Skip to content

[GH-3042] Flink Box3D predicates: ST_Intersects / ST_Contains + ST_3DDWithin#3043

Merged
jiayuasu merged 1 commit into
apache:masterfrom
jiayuasu:feature/flink-box3d-predicates
Jun 12, 2026
Merged

[GH-3042] Flink Box3D predicates: ST_Intersects / ST_Contains + ST_3DDWithin#3043
jiayuasu merged 1 commit into
apache:masterfrom
jiayuasu:feature/flink-box3d-predicates

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?

Final Flink Box3D slice. Brings the Flink predicate surface to parity with Spark's Box3D predicates (consolidated into ST_Intersects / ST_Contains plus the standalone ST_3DDWithin).

  • ST_Intersects / ST_Contains: Box3D eval overloads wrapping Predicates.box3dIntersects / box3dContains. Mirrors the Box2D overloads already on these classes.
  • ST_3DDWithin: new scalar function with two overloads — (Geometry, Geometry, Double)dWithin3D (missing Z folds to 0), and (Box3D, Box3D, Double)dWithin3D. NULL-guarded like the Box overloads. Registered in Catalog.

How was this patch tested?

  • PredicateTest.testIntersectsOnBox3D / testContainsOnBox3D — XY-overlapping-but-Z-disjoint rows confirm the Z axis is enforced (not just an XY-footprint check).
  • PredicateTest.test3DDWithin — Geometry POINT Z within / just-outside the threshold, plus Box3D-on-Box3D faces-apart-in-Z within / just-outside.
  • Full PredicateTest: 21 pass.

Did this PR include necessary documentation updates?

  • No — Box3D documentation is tracked separately under the Box3D EPIC.

Completion

This completes Flink Box3D parity with the shipped Spark surface: type + serializer, constructors, accessors, ST_AsText, ST_3DExtent, and predicates.

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

This PR completes the Flink “Box3D predicates” slice by adding Box3D overloads for existing ST_Intersects/ST_Contains and introducing a new ST_3DDWithin predicate, aligning Flink’s Box3D predicate surface with Sedona’s common-layer Box3D predicate implementations.

Changes:

  • Added Box3D overloads to Flink ST_Intersects and ST_Contains delegating to org.apache.sedona.common.Predicates.box3dIntersects/box3dContains.
  • Added new Flink scalar function ST_3DDWithin with Geometry and Box3D overloads delegating to org.apache.sedona.common.Predicates.dWithin3D.
  • Registered ST_3DDWithin in the Flink Catalog and added corresponding Flink SQL tests.

Reviewed changes

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

File Description
flink/src/test/java/org/apache/sedona/flink/PredicateTest.java Adds Flink SQL tests covering Box3D intersects/contains semantics and ST_3DDWithin threshold behavior.
flink/src/main/java/org/apache/sedona/flink/expressions/Predicates.java Implements Box3D overloads for ST_Intersects/ST_Contains and adds the new ST_3DDWithin scalar function.
flink/src/main/java/org/apache/sedona/flink/Catalog.java Registers ST_3DDWithin among Flink predicate UDFs.

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

bridgedTo = Geometry.class)
Object o2,
@DataTypeHint("Double") Double distance) {
if (o1 == null || o2 == null) return null;

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Fixed in latest push: the geometry overload now guards distance == null (alongside the existing o1/o2 null guards) and returns NULL. Added a NULL-distance assertion to PredicateTest.test3DDWithin. The pre-existing ST_DWithin has the same gap (NULL distance and NULL geometry both NPE); tracked separately in #3046 to keep this PR scoped to Box3D.

bridgedTo = Box3D.class)
Box3D b,
@DataTypeHint("Double") Double distance) {
if (a == null || b == null) return null;

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Fixed in latest push: the Box3D overload now guards distance == null and returns NULL, with a NULL-distance assertion added to the test. See #3046 for the parallel ST_DWithin cleanup.

@jiayuasu

Copy link
Copy Markdown
Member Author

One thing to fix before merge: ST_3DDWithin guards the spatial arguments, but not the nullable distance argument. Both overloads accept Double and then pass it to org.apache.sedona.common.Predicates.dWithin3D(..., double), so ST_3DDWithin(..., CAST(NULL AS DOUBLE)) will autounbox and throw instead of returning SQL NULL.

Please add distance == null to both null guards and cover the null-distance case in PredicateTest. I verified the current focused test suite passes with:

mvn -pl flink -Dtest=PredicateTest test

… ST_3DDWithin

Final Flink Box3D slice, bringing the Flink predicate surface to parity
with Spark's Box3D predicates.

- ST_Intersects / ST_Contains: Box3D eval overloads wrapping
  Predicates.box3dIntersects / box3dContains, mirroring the Box2D
  overloads already on these classes.
- New ST_3DDWithin scalar function: (Geometry, Geometry, Double) →
  dWithin3D (missing Z folds to 0) and (Box3D, Box3D, Double) →
  dWithin3D. NULL-guarded.
- Registered ST_3DDWithin in Catalog.

Tests:
- PredicateTest.testIntersectsOnBox3D / testContainsOnBox3D: the
  XY-overlapping-but-Z-disjoint rows confirm the Z axis is enforced.
- PredicateTest.test3DDWithin: Geometry POINT Z within / just-outside,
  plus Box3D-on-Box3D faces-apart-in-Z within / just-outside.

This completes Flink Box3D parity with the Spark surface.
@jiayuasu jiayuasu force-pushed the feature/flink-box3d-predicates branch from 0b880da to 8ea92c8 Compare June 12, 2026 02:40
@jiayuasu jiayuasu added this to the sedona-1.9.1 milestone Jun 12, 2026
@jiayuasu jiayuasu merged commit 026d2c0 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 Box3D predicates: ST_Intersects / ST_Contains overloads + ST_3DDWithin

2 participants