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


##########
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:
   > I have a question: why does promoting a low-level API help testing?
   
   If we have to maintain a "default join" and "custom join" pathway, we have 
add tests for the "custom join" pathway. Here they're essentially both running 
through a "custom join" pathway, which doesn't remove the need for integration 
tests for the GPU and Geography joins, but does in theory limit their low-level 
testing responsibility to building and querying the index. It's not a perfect 
system but in the previous PR implementing the join there was `#[cfg(feat = 
"gpu")]` sprinkled throughout various pieces of sedona-spatial join and it 
wasn't clear which ones of those were tested.
   
   >  A more common approach is to maintain end-to-end behavioral tests that 
can be reused across different specialized join implementations.
   
   We can/will do this too. We have to move some of the tests here into 
`rust/sedona/tests` anyway because we have a circular dependency problem at the 
moment (https://github.com/apache/sedona-db/issues/702). We also have some in 
Python that can be parameterized.
   
   > The try_new_evaluated_array() API seems more like a spatial-index-related 
utility
   
   That's a great point...I think this can be moved to the SpatialIndexBuilder 
for this PR. I am not 100% on exactly what we need to do to make the 
evaluatedgeometryarray work with Geography yet...it may be this can be isolated 
to the DefaultSpatialIndex with some more (possibly disruptive) effort.



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