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 2021/07/16 17:25:26 UTC
[incubator-sedona] branch master updated: [SEDONA-53]fix
SpatialKnnQuery NullPointerException (#532)
This is an automated email from the ASF dual-hosted git repository.
jiayu pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-sedona.git
The following commit(s) were added to refs/heads/master by this push:
new e6513be [SEDONA-53]fix SpatialKnnQuery NullPointerException (#532)
e6513be is described below
commit e6513bedd41f8f71d75dcdf9f7db9efaef880518
Author: chenpengchuan <pc...@foxmail.com>
AuthorDate: Sat Jul 17 01:25:18 2021 +0800
[SEDONA-53]fix SpatialKnnQuery NullPointerException (#532)
---
.../apache/sedona/core/knnJudgement/KnnJudgement.java | 10 ++++++++--
.../sedona/core/spatialOperator/PointKnnTest.java | 19 +++++++++++++++++++
core/src/test/resources/small/onepoint.csv | 1 +
3 files changed, 28 insertions(+), 2 deletions(-)
diff --git a/core/src/main/java/org/apache/sedona/core/knnJudgement/KnnJudgement.java b/core/src/main/java/org/apache/sedona/core/knnJudgement/KnnJudgement.java
index df2d006..f8999e2 100644
--- a/core/src/main/java/org/apache/sedona/core/knnJudgement/KnnJudgement.java
+++ b/core/src/main/java/org/apache/sedona/core/knnJudgement/KnnJudgement.java
@@ -81,8 +81,14 @@ public class KnnJudgement<U extends Geometry, T extends Geometry>
}
}
ArrayList<T> res = new ArrayList<T>();
- for (int i = 0; i < k; i++) {
- res.add(pq.poll());
+ if (pq.size() >= k) {
+ for (int i = 0; i < k; i++) {
+ res.add(pq.poll());
+ }
+ } else {
+ for (int i = 0; i < pq.size(); i++) {
+ res.add(pq.poll());
+ }
}
return res.iterator();
}
diff --git a/core/src/test/java/org/apache/sedona/core/spatialOperator/PointKnnTest.java b/core/src/test/java/org/apache/sedona/core/spatialOperator/PointKnnTest.java
index aebe610..1f15c54 100644
--- a/core/src/test/java/org/apache/sedona/core/spatialOperator/PointKnnTest.java
+++ b/core/src/test/java/org/apache/sedona/core/spatialOperator/PointKnnTest.java
@@ -224,4 +224,23 @@ public class PointKnnTest
}
assert difference == 0;
}
+
+ /**
+ * Test spatial knn query without useIndex and k is larger than spatialRDD's approximateTotalCount
+ *
+ * @throws Exception the exception
+ */
+ @Test
+ public void testSpatialKnnQueryTopKlargerThanRowNumber()
+ throws Exception
+ {
+ String inputPath = "file://" + PointKnnTest.class.getClassLoader().getResource("small/onepoint.csv").getPath();
+ PointRDD pointRDD = new PointRDD(sc, inputPath, 0, splitter, false);
+ //this pointRDD only one row of data
+// System.out.println(pointRDD.getRawSpatialRDD().count());
+ for (int i = 0; i < loopTimes; i++) {
+ List<Point> result = KNNQuery.SpatialKnnQuery(pointRDD, queryPoint, 5, false);
+ assert result.size() == 1;
+ }
+ }
}
\ No newline at end of file
diff --git a/core/src/test/resources/small/onepoint.csv b/core/src/test/resources/small/onepoint.csv
new file mode 100644
index 0000000..6410d58
--- /dev/null
+++ b/core/src/test/resources/small/onepoint.csv
@@ -0,0 +1 @@
+-112.506968,45.98186
\ No newline at end of file