paleolimbot commented on code in PR #737:
URL: https://github.com/apache/sedona-db/pull/737#discussion_r2997007717


##########
rust/sedona-spatial-join/src/evaluated_batch/spill.rs:
##########
@@ -70,7 +73,12 @@ impl EvaluatedBatchSpillWriter {
             Field::new("data", DataType::Struct(data_inner_fields.clone()), 
false);
         let geom_field = sedona_type.to_storage_field("geom", true)?;
         let dist_field = Field::new("dist", DataType::Float64, true);
-        let spill_schema = Schema::new(vec![data_struct_field, geom_field, 
dist_field]);
+        let rect_field = Field::new(
+            "rect",
+            DataType::new_fixed_size_list(DataType::Float32, 4, true),
+            true,
+        );
+        let spill_schema = Schema::new(vec![data_struct_field, geom_field, 
dist_field, rect_field]);

Review Comment:
   Spilling the rectangles here was primarily to avoid having to pipe the 
SpatialIndexProvider through the machinery that reads the batches, which is a 
verbose change. This is potentially faster because it avoid recomputing bounds 
and potentially slower because it increases the size of the spilled batch.



##########
rust/sedona-spatial-join/src/index/spatial_index_builder.rs:
##########
@@ -41,8 +42,10 @@ pub(crate) trait SpatialIndexBuilder {
         options: &SpatialJoinOptions,
     ) -> usize;
 
+    fn operand_evaluator(&self) -> Arc<dyn OperandEvaluator>;

Review Comment:
   I needed this because the OperandEvaluator is one of the places where 
EvaluatedGeometryArrays are created and this eliminated one more place where I 
had to pipe through the SpatialJoinProvider



##########
rust/sedona-spatial-join/src/partitioning/stream_repartitioner.rs:
##########
@@ -645,115 +643,14 @@ pub(crate) fn interleave_evaluated_batch(
         return sedona_internal_err!("interleave_evaluated_batch requires at 
least one batch");
     }
     let batch = interleave_record_batch(record_batches, indices)?;
-    let geom_array = interleave_geometry_array(geom_arrays, indices)?;
+    let geom_array = EvaluatedGeometryArray::interleave(geom_arrays, indices)?;

Review Comment:
   I did this to avoid having to pipe through the `SpatialJoinEvaluator` here; 
however, I think it is also positive (the rectangles from the input 
EvaluatedGeometryArray are used instead of being recomputed).



##########
rust/sedona-spatial-join/src/partitioning/stream_repartitioner.rs:
##########
@@ -645,115 +643,14 @@ pub(crate) fn interleave_evaluated_batch(
         return sedona_internal_err!("interleave_evaluated_batch requires at 
least one batch");
     }
     let batch = interleave_record_batch(record_batches, indices)?;
-    let geom_array = interleave_geometry_array(geom_arrays, indices)?;
+    let geom_array = EvaluatedGeometryArray::interleave(geom_arrays, indices)?;
     Ok(EvaluatedBatch { batch, geom_array })
 }
 
-fn interleave_geometry_array(
-    geom_arrays: &[&EvaluatedGeometryArray],
-    indices: &[(usize, usize)],
-) -> Result<EvaluatedGeometryArray> {
-    if geom_arrays.is_empty() {
-        return sedona_internal_err!("interleave_geometry_array requires at 
least one batch");
-    }

Review Comment:
   This was just moved to EvaluatedGeometryArray (with its tests)



##########
rust/sedona-spatial-join/src/join_provider.rs:
##########
@@ -0,0 +1,95 @@
+// 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.
+
+use arrow_array::ArrayRef;
+use arrow_schema::SchemaRef;
+use datafusion_common::Result;
+use datafusion_expr::JoinType;
+use sedona_common::SpatialJoinOptions;
+use sedona_schema::datatypes::SedonaType;
+
+use crate::{
+    index::{
+        spatial_index_builder::{SpatialIndexBuilder, SpatialJoinBuildMetrics},
+        DefaultSpatialIndexBuilder,
+    },
+    operand_evaluator::EvaluatedGeometryArray,
+    SpatialPredicate,
+};
+
+/// Provider for join internals
+///
+/// This trait provides an extension point for overriding the evaluation
+/// details of a spatial join. In particular it allows plugging in a custom
+/// index for accellerated joins on specific hardware (e.g., GPU) and a custom
+/// bounder for specific data types (e.g., geography).
+pub(crate) trait SpatialJoinProvider: std::fmt::Debug + Send + Sync {
+    /// Create a new [SpatialIndexBuilder]
+    fn try_new_spatial_index_builder(
+        &self,
+        schema: SchemaRef,
+        spatial_predicate: SpatialPredicate,
+        options: SpatialJoinOptions,
+        join_type: JoinType,
+        probe_threads_count: usize,
+        metrics: SpatialJoinBuildMetrics,
+    ) -> Result<Box<dyn SpatialIndexBuilder>>;
+
+    /// Create a new [EvaluatedGeometryArray]
+    ///
+    /// Use [EvaluatedGeometryArray::try_new_with_rects] for custom 
computation of
+    /// bounding rectangles for specific items.
+    fn try_new_evaluated_array(
+        &self,
+        geometry_array: ArrayRef,
+        sedona_type: &SedonaType,
+    ) -> Result<EvaluatedGeometryArray>;
+}

Review Comment:
   This is the extension point that is the primary motivation for this PR. 
Implementing it in this way allows all of the existing join pathways to run 
through this trait to reduce the test responsibility for custom joins.



-- 
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