You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@sedona.apache.org by ji...@apache.org on 2026/06/12 05:27:06 UTC
(sedona) branch master updated: [GH-3046] Flink ST_DWithin: propagate NULL arguments instead of NPE (#3047)
This is an automated email from the ASF dual-hosted git repository.
jiayuasu pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/sedona.git
The following commit(s) were added to refs/heads/master by this push:
new 7e54fa1569 [GH-3046] Flink ST_DWithin: propagate NULL arguments instead of NPE (#3047)
7e54fa1569 is described below
commit 7e54fa1569d0c1f9114ada0d6282c22159714506
Author: Jia Yu <ji...@apache.org>
AuthorDate: Thu Jun 11 22:27:00 2026 -0700
[GH-3046] Flink ST_DWithin: propagate NULL arguments instead of NPE (#3047)
---
.../org/apache/sedona/flink/expressions/Predicates.java | 5 +++++
.../java/org/apache/sedona/flink/PredicateTest.java | 17 +++++++++++++++++
2 files changed, 22 insertions(+)
diff --git a/flink/src/main/java/org/apache/sedona/flink/expressions/Predicates.java b/flink/src/main/java/org/apache/sedona/flink/expressions/Predicates.java
index 127bd90d70..032dea00f6 100644
--- a/flink/src/main/java/org/apache/sedona/flink/expressions/Predicates.java
+++ b/flink/src/main/java/org/apache/sedona/flink/expressions/Predicates.java
@@ -417,6 +417,9 @@ public class Predicates {
bridgedTo = Geometry.class)
Object o2,
@DataTypeHint("Double") Double distance) {
+ // The common-layer dWithin takes a primitive double, so a SQL NULL distance would
+ // autounbox to an NPE; any NULL argument propagates to a NULL result instead.
+ if (o1 == null || o2 == null || distance == null) return null;
Geometry geom1 = (Geometry) o1;
Geometry geom2 = (Geometry) o2;
return org.apache.sedona.common.Predicates.dWithin(geom1, geom2, distance);
@@ -436,6 +439,8 @@ public class Predicates {
Object o2,
@DataTypeHint("Double") Double distance,
@DataTypeHint("Boolean") Boolean useSphere) {
+ // distance and useSphere both autounbox to primitives in the common layer; guard all four.
+ if (o1 == null || o2 == null || distance == null || useSphere == null) return null;
Geometry geom1 = (Geometry) o1;
Geometry geom2 = (Geometry) o2;
return org.apache.sedona.common.Predicates.dWithin(geom1, geom2, distance, useSphere);
diff --git a/flink/src/test/java/org/apache/sedona/flink/PredicateTest.java b/flink/src/test/java/org/apache/sedona/flink/PredicateTest.java
index b914ab6099..d76a77f7da 100644
--- a/flink/src/test/java/org/apache/sedona/flink/PredicateTest.java
+++ b/flink/src/test/java/org/apache/sedona/flink/PredicateTest.java
@@ -283,6 +283,23 @@ public class PredicateTest extends TestBase {
assertEquals(true, actual);
}
+ @Test
+ public void testDWithinNullArguments() {
+ // Any NULL argument propagates to NULL rather than NPE-ing on autounbox / null geometry.
+ Table t =
+ tableEnv.sqlQuery(
+ "SELECT ST_DWithin(ST_GeomFromWKT('POINT (0 0)'), ST_GeomFromWKT('POINT (1 0)'),"
+ + " CAST(NULL AS DOUBLE)) AS null_dist,"
+ + " ST_DWithin(ST_GeomFromWKT(CAST(NULL AS STRING)),"
+ + " ST_GeomFromWKT('POINT (1 0)'), 1.0) AS null_geom,"
+ + " ST_DWithin(ST_GeomFromWKT('POINT (0 0)'), ST_GeomFromWKT('POINT (1 0)'), 1.0,"
+ + " CAST(NULL AS BOOLEAN)) AS null_sphere");
+ org.apache.flink.types.Row row = first(t);
+ assertNull(row.getField(0));
+ assertNull(row.getField(1));
+ assertNull(row.getField(2));
+ }
+
@Test
public void testDWithinFailure() {
Table table =