Skip to content

[GH-3046] Flink ST_DWithin: propagate NULL arguments instead of NPE#3047

Merged
jiayuasu merged 1 commit into
apache:masterfrom
jiayuasu:fix/flink-dwithin-null-args
Jun 12, 2026
Merged

[GH-3046] Flink ST_DWithin: propagate NULL arguments instead of NPE#3047
jiayuasu merged 1 commit into
apache:masterfrom
jiayuasu:fix/flink-dwithin-null-args

Conversation

@jiayuasu

Copy link
Copy Markdown
Member

Did you read the Contributor Guide?

  • Yes

Is this PR related to a ticket?

What changes were proposed in this PR?

The Flink ST_DWithin overloads passed their arguments straight to the common-layer dWithin, which takes primitive double / boolean. A SQL NULL distance (or useSphere) autounboxed to a NullPointerException, and a NULL geometry NPE'd inside the predicate — instead of propagating to a NULL result as SQL semantics require.

  • 3-arg overload: guard o1 / o2 / distance.
  • 4-arg overload: additionally guard useSphere.

This brings ST_DWithin up to the NULL-safe contract that ST_3DDWithin already has (added in #3043).

Audit of the rest of the Flink predicate surface: ST_DWithin and ST_3DDWithin are the only predicates with boxed-primitive arguments (distance / useSphere); every other predicate takes geometry RAW arguments only, so there is no further autounbox hazard. ST_3DDWithin was already guarded.

How was this patch tested?

  • PredicateTest.testDWithinNullArguments asserts NULL propagation for a NULL distance, a NULL geometry, and a NULL useSphere.
  • Full PredicateTest: 22 pass.

Did this PR include necessary documentation updates?

  • No — behavior fix; no API surface change.

… NPE

The Flink ST_DWithin overloads passed their arguments straight to the
common-layer dWithin, which takes primitive double / boolean. A SQL
NULL distance (or useSphere) autounboxed to a NullPointerException, and
a NULL geometry NPE'd inside the predicate — instead of propagating to
a NULL result as SQL semantics require. Surfaced reviewing apache#3043, where
ST_3DDWithin was given the guards but ST_DWithin was left as-is to keep
that PR scoped to Box3D.

- 3-arg overload: guard o1 / o2 / distance.
- 4-arg overload: additionally guard useSphere.

Audit of the rest of the Flink predicate surface: ST_DWithin and
ST_3DDWithin are the only predicates with boxed-primitive arguments
(distance / useSphere); every other predicate takes geometry RAW
arguments only, so there is no further autounbox hazard. ST_3DDWithin
was already guarded in apache#3043.

Tests: PredicateTest.testDWithinNullArguments asserts NULL propagation
for a NULL distance, a NULL geometry, and a NULL useSphere.
@jiayuasu jiayuasu requested a review from Copilot June 12, 2026 04:05
@jiayuasu jiayuasu added this to the sedona-1.9.1 milestone Jun 12, 2026
@jiayuasu jiayuasu linked an issue Jun 12, 2026 that may be closed by this pull request

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Note

Copilot was unable to run its full agentic suite in this review.

Fixes Flink ST_DWithin overloads to propagate SQL NULL inputs to a NULL result (instead of throwing NullPointerException due to autounboxing / null geometries), and adds regression coverage for these cases.

Changes:

  • Add NULL-guarding in Flink ST_DWithin 3-arg overload for o1, o2, and distance.
  • Add NULL-guarding in Flink ST_DWithin 4-arg overload for o1, o2, distance, and useSphere.
  • Add a Flink PredicateTest covering NULL propagation for NULL distance, NULL geometry, and NULL useSphere.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.

File Description
flink/src/main/java/org/apache/sedona/flink/expressions/Predicates.java Adds explicit NULL checks to prevent NPEs from autounboxing / null geometry inputs and to follow SQL NULL semantics.
flink/src/test/java/org/apache/sedona/flink/PredicateTest.java Adds regression test asserting ST_DWithin returns NULL when any argument is NULL.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@jiayuasu jiayuasu merged commit 7e54fa1 into apache:master Jun 12, 2026
19 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Flink ST_DWithin: NULL argument propagation (geometry + distance)

2 participants