2010YOUY01 commented on code in PR #737: URL: https://github.com/apache/sedona-db/pull/737#discussion_r3004675216
########## 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? A more common approach is to maintain end-to-end behavioral tests that can be reused across different specialized join implementations. (I might be mistaken for this part, as I’ve only skimmed the code.) The existing spatial join does not seem to rely directly on this primitive. Instead, it uses `OperandEvaluator` to build `EvaluatedGeometryArray`. For predicates like spatial distance, one side’s geometries are expanded when creating `EvaluatedGeometryArray` so that the R-tree probe logic remains consistent across different spatial predicates. As a result, this proposed API does not appear to be used directly in the implementation. Is it still useful for testing? -- 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]
