Copilot commented on code in PR #737:
URL: https://github.com/apache/sedona-db/pull/737#discussion_r2997055179
##########
rust/sedona-spatial-join/src/operand_evaluator.rs:
##########
@@ -107,10 +108,10 @@ pub struct EvaluatedGeometryArray {
}
impl EvaluatedGeometryArray {
+ /// Create a new EvaluatedGeometryArray and compute item bounds
pub fn try_new(geometry_array: ArrayRef, sedona_type: &SedonaType) ->
Result<Self> {
let num_rows = geometry_array.len();
let mut rect_vec = Vec::with_capacity(num_rows);
- let mut wkbs = Vec::with_capacity(num_rows);
geometry_array.iter_as_wkb(sedona_type, num_rows, |wkb_opt| {
Review Comment:
`EvaluatedGeometryArray::try_new()` now does one `iter_as_wkb` pass to
compute `rect_vec` and then (via `try_new_with_rects`) does a second
`iter_as_wkb` pass to populate `wkbs`. This adds avoidable CPU overhead in a
hot path; consider keeping a single-pass constructor for the default case that
collects both rects and WKB refs together.
##########
rust/sedona-spatial-join/src/evaluated_batch/spill.rs:
##########
@@ -141,11 +149,31 @@ impl EvaluatedBatchSpillWriter {
}
let dist_array = dist_builder.finish();
+ // Store rect into a FixedSizeList array
+ let mut rect_builder =
+
arrow::array::FixedSizeListBuilder::new(arrow::array::Float32Builder::new(), 4);
+ for rect_opt in &geom_array.rects {
+ if let Some(rect) = rect_opt {
+ rect_builder.values().append_slice(&[
+ rect.min().x(),
+ rect.min().y(),
+ rect.max().x(),
+ rect.max().y,
Review Comment:
In the rect spill encoding, `rect.max().y` is inconsistent with the other
coordinate accesses (`x()`/`y()` from `CoordTrait`) and likely won’t compile or
will access the wrong thing depending on the `geo` version. Use the same
accessor style as the other coordinates when writing `max_y`.
```suggestion
rect.max().y(),
```
##########
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 accelerated 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,
Review Comment:
`SpatialJoinProvider` is `pub(crate)`, which prevents other crates from
implementing/customizing join internals (GPU/Geography) as described in the PR.
If cross-crate configurability is intended, make the trait public (and likewise
expose/re-export any types needed to implement it).
##########
rust/sedona-spatial-join/src/lib.rs:
##########
@@ -18,6 +18,7 @@
pub mod evaluated_batch;
pub mod exec;
mod index;
+mod join_provider;
Review Comment:
`join_provider` is declared as a private module (`mod join_provider;`). If
the goal is to allow Geography/GPU join implementations in separate crates,
they won’t be able to reference or implement the provider trait. Consider
making this module public (or re-exporting the trait/types) so external crates
can plug in a custom provider.
```suggestion
pub mod join_provider;
```
##########
rust/sedona-spatial-join/src/prepare.rs:
##########
@@ -407,6 +410,7 @@ impl SpatialJoinComponentsBuilder {
self.join_type,
self.probe_threads_count,
SpatialJoinBuildMetrics::new(0, &self.metrics),
+ Arc::new(DefaultSpatialJoinProvider {}),
);
Review Comment:
`PartitionedIndexProvider` now accepts a `join_provider`, but this call site
hard-codes `DefaultSpatialJoinProvider`. That prevents a custom provider from
being propagated into index building/spill-reading. To make the provider
configurable, thread an `Arc<dyn SpatialJoinProvider>` through
`SpatialJoinComponentsBuilder` and pass it here instead of always constructing
the default.
##########
rust/sedona-spatial-join/src/exec.rs:
##########
@@ -172,6 +175,7 @@ impl SpatialJoinExec {
cache,
once_async_spatial_join_components: Arc::new(Mutex::new(None)),
seed,
+ join_provider: Arc::new(DefaultSpatialJoinProvider {}),
})
}
Review Comment:
`SpatialJoinExec` initializes `join_provider` to
`DefaultSpatialJoinProvider`, but there’s no constructor parameter or `with_*`
method to override it. If GPU/Geography implementations are expected to plug in
from other crates, consider exposing an API to set `join_provider` and then
thread that same instance through preparation/index-building as well as the
probe-side evaluator.
```suggestion
/// Override the default spatial join provider used by this execution
plan.
///
/// This allows alternative implementations (e.g. GPU-accelerated or
/// geography-aware providers) to be plugged in from other crates while
/// reusing the same prepared/indexed state and probe-side evaluation.
pub fn with_join_provider(
mut self,
join_provider: Arc<dyn SpatialJoinProvider>,
) -> Self {
self.join_provider = join_provider;
self
}
```
--
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]