paleolimbot commented on code in PR #1778:
URL: https://github.com/apache/sedona/pull/1778#discussion_r1936132086


##########
python/tests/test_base.py:
##########


Review Comment:
   I'm happy to move this to another PR...it's basically what it takes to get 
VSCode's Python testing integration to enable run/debug/discover.



##########
spark/common/src/test/resources/.gitignore:
##########
@@ -1,2 +1,3 @@
 *.DS_Store
 real-*
+wkb/testSaveAs*

Review Comment:
   Again, I can move this to another PR (running the Python tests creates quite 
a lot of files here!)



##########
spark/common/src/main/java/org/apache/sedona/core/spatialPartitioning/GenericUniquePartitioner.java:
##########
@@ -0,0 +1,77 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.sedona.core.spatialPartitioning;
+
+import java.util.HashSet;
+import java.util.Iterator;
+import java.util.List;
+import javax.annotation.Nullable;
+import org.apache.sedona.core.enums.GridType;
+import org.apache.sedona.core.joinJudgement.DedupParams;
+import org.locationtech.jts.geom.Envelope;
+import org.locationtech.jts.geom.Geometry;
+import scala.Tuple2;
+
+public class GenericUniquePartitioner extends SpatialPartitioner {
+  private SpatialPartitioner parent;
+
+  public GenericUniquePartitioner(SpatialPartitioner parent) {
+    this.parent = parent;
+  }
+
+  public GridType getGridType() {
+    return parent.gridType;
+  }
+
+  public List<Envelope> getGrids() {
+    return parent.grids;
+  }
+
+  @Override
+  public Iterator<Tuple2<Integer, Geometry>> placeObject(Geometry 
spatialObject) throws Exception {
+    Iterator<Tuple2<Integer, Geometry>> it = parent.placeObject(spatialObject);
+    int minParitionId = Integer.MAX_VALUE;
+    Geometry minGeometry = null;
+    while (it.hasNext()) {
+      Tuple2<Integer, Geometry> value = it.next();
+      if (value._1() < minParitionId) {
+        minParitionId = value._1();
+        minGeometry = value._2();
+      }
+    }
+
+    HashSet<Tuple2<Integer, Geometry>> out = new HashSet<Tuple2<Integer, 
Geometry>>();
+    if (minGeometry != null) {
+      out.add(new Tuple2<Integer, Geometry>(minParitionId, minGeometry));
+    }
+
+    return out.iterator();

Review Comment:
   I could also just take `it.Next()` here (i.e., always return the first one) 
and modify the `placeObject` implementations to not return an iterator off of a 
`HashSet` (i.e., write our own implementation of `Iterator`, which might be 
better anyway).
   
   The motivation here is to ensure that the output is deterministic (i.e., if 
you set grids and ask Sedona to partition, you'll get the same result if you 
run your pipeline today or tomorrow).



##########
spark/common/src/main/java/org/apache/sedona/core/spatialPartitioning/SpatialPartitioner.java:
##########
@@ -35,6 +35,11 @@ public abstract class SpatialPartitioner extends Partitioner 
implements Serializ
   protected final GridType gridType;
   protected final List<Envelope> grids;
 
+  protected SpatialPartitioner() {
+    gridType = null;
+    grids = null;
+  }

Review Comment:
   A cleaner way to do this would probably be to remove the `gridType` and 
`grids` field and make `getGridType()` and `getGrids()` abstract? I could also 
remove this constructror and just pass the `GenericUniquePartitioner`'s parent 
grids/grid type through here.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to