Copilot commented on code in PR #443: URL: https://github.com/apache/sedona-db/pull/443#discussion_r2613615227
########## rust/sedona-spatial-join/bench/partitioning/flat.rs: ########## @@ -0,0 +1,56 @@ +// 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. + +mod common; + +use std::hint::black_box; + +use common::{default_extent, grid_partitions, sample_queries, GRID_DIM, QUERY_BATCH_SIZE}; +use criterion::{criterion_group, criterion_main, Criterion, Throughput}; +use sedona_spatial_join::partitioning::{flat::FlatPartitioner, SpatialPartitioner}; + +fn bench_flat_partition_queries(c: &mut Criterion) { + let extent = default_extent(); + let partitions = grid_partitions(&extent, GRID_DIM); + let queries = sample_queries(&extent, QUERY_BATCH_SIZE); + let partitioner = + FlatPartitioner::new(partitions).expect("failed to build Flat partitioner for benchmark"); + + let mut group = c.benchmark_group("flat_partition_queries"); + group.throughput(Throughput::Elements(QUERY_BATCH_SIZE as u64)); + + for (label, no_dup) in [("partition", false), ("partition_no_dup", true)] { + group.bench_function(format!("linear_scan_{label}"), |b| { + b.iter(|| { + for query in &queries { + let partition = if no_dup { Review Comment: The variable name 'no_dup' is ambiguous. Based on usage, it appears to control whether 'partition_no_multi' is called. Consider renaming to 'use_no_multi' or 'single_partition_mode' to better reflect its purpose. ```suggestion for (label, use_no_multi) in [("partition", false), ("partition_no_dup", true)] { group.bench_function(format!("linear_scan_{label}"), |b| { b.iter(|| { for query in &queries { let partition = if use_no_multi { ``` ########## rust/sedona-spatial-join/bench/partitioning/rtree.rs: ########## @@ -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. + +mod common; + +use std::hint::black_box; + +use common::{default_extent, grid_partitions, sample_queries, GRID_DIM, QUERY_BATCH_SIZE}; +use criterion::{criterion_group, criterion_main, BenchmarkId, Criterion, Throughput}; +use sedona_geometry::bounding_box::BoundingBox; +use sedona_spatial_join::partitioning::{rtree::RTreePartitioner, SpatialPartitioner}; +const NODE_SIZES: [u16; 5] = [4, 8, 16, 32, 64]; // smaller node size => deeper tree + +fn bench_rtree_partition_queries(c: &mut Criterion) { + let extent = default_extent(); + let partitions = grid_partitions(&extent, GRID_DIM); + let queries = sample_queries(&extent, QUERY_BATCH_SIZE); + let partitioners = build_partitioners(&partitions); + + let mut group = c.benchmark_group("rtree_partition_queries"); + group.throughput(Throughput::Elements(QUERY_BATCH_SIZE as u64)); + + for (node_size, depth, partitioner) in &partitioners { + for (method, no_dup) in [("partition", false), ("partition_no_dup", true)] { Review Comment: The variable name 'no_dup' is ambiguous. Based on usage, it appears to control whether 'partition_no_multi' is called. Consider renaming to 'use_no_multi' or 'single_partition_mode' to better reflect its purpose. ########## rust/sedona-spatial-join/bench/partitioning/kdb.rs: ########## @@ -0,0 +1,129 @@ +// 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 std::hint::black_box; + +use criterion::{criterion_group, criterion_main, BenchmarkId, Criterion, Throughput}; +use rand::{rngs::StdRng, Rng, SeedableRng}; +use sedona_geometry::{bounding_box::BoundingBox, interval::IntervalTrait}; +use sedona_spatial_join::partitioning::{kdb::KDBPartitioner, SpatialPartitioner}; + +const SAMPLE_COUNT: usize = 20_000; +const QUERY_BATCH_SIZE: usize = 1_024; +const MAX_ITEMS_PER_NODE: usize = 64; +const DEPTHS: [usize; 5] = [2, 4, 6, 8, 10]; +const RNG_SEED: u64 = 0x005E_D04A; // stable dataset across runs + +fn bench_partition_queries(c: &mut Criterion) { + let extent = default_extent(); + let mut rng = StdRng::seed_from_u64(RNG_SEED); + let samples = synthetic_bboxes(SAMPLE_COUNT, &extent, &mut rng, span_for_extent(&extent)); + let queries = synthetic_bboxes( + QUERY_BATCH_SIZE, + &extent, + &mut rng, + span_for_extent(&extent) / 2.0, + ); + + let partitioners = build_partitioners(&samples, &extent); + + let mut group = c.benchmark_group("kdb_partition_queries"); + group.throughput(Throughput::Elements(QUERY_BATCH_SIZE as u64)); + + for (depth, partitioner) in &partitioners { + for (method, no_dup) in [("partition", false), ("partition_no_dup", true)] { + group.bench_with_input( + BenchmarkId::from_parameter(format!("depth-{depth}_{method}")), + partitioner, + |b, part: &KDBPartitioner| { + b.iter(|| { + for query in &queries { + let partition = if no_dup { Review Comment: The variable name 'no_dup' is ambiguous. Based on usage, it appears to control whether 'partition_no_multi' is called. Consider renaming to 'use_no_multi' or 'single_partition_mode' to better reflect its purpose. ```suggestion for (method, use_no_multi) in [("partition", false), ("partition_no_dup", true)] { group.bench_with_input( BenchmarkId::from_parameter(format!("depth-{depth}_{method}")), partitioner, |b, part: &KDBPartitioner| { b.iter(|| { for query in &queries { let partition = if use_no_multi { ``` ########## rust/sedona-spatial-join/src/partitioning/util.rs: ########## @@ -0,0 +1,186 @@ +// 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. + +//! Utility functions for spatial partitioning. + +use datafusion_common::{DataFusionError, Result}; +use float_next_after::NextAfter; +use geo::{Coord, CoordNum, Rect}; +use sedona_geometry::bounding_box::BoundingBox; +use sedona_geometry::interval::IntervalTrait; + +/// Convert a BoundingBox to f32 coordinates +/// +/// # Arguments +/// * `bbox` - The BoundingBox to convert +/// +/// # Returns +/// A tuple of (min_x, min_y, max_x, max_y) as f32 values +/// +/// # Errors +/// Returns an error if the bounding box has wraparound coordinates (e.g., crossing the anti-meridian) +pub(crate) fn bbox_to_f32_rect(bbox: &BoundingBox) -> Result<(f32, f32, f32, f32)> { + // Check for wraparound coordinates + if bbox.x().is_wraparound() { + return Err(DataFusionError::Execution( + "BoundingBox has wraparound coordinates, which is not supported yet".to_string(), + )); + } + + // Convert lo bounds - these are inclusive, so we want to round down + // to ensure we don't exclude any points + let min_x = bbox.x().lo() as f32; + let min_y = bbox.y().lo() as f32; Review Comment: The comment on line 44-45 states 'we want to round down to ensure we don't exclude any points,' but the `as f32` cast does not guarantee rounding down. For f64 values that cannot be exactly represented as f32, the cast may round to the nearest representable value, which could round up. Consider documenting this behavior more accurately or using explicit rounding functions if guarantees are required. ```suggestion let min_x = { let v = bbox.x().lo(); let f = v as f32; if (f as f64) > v { f.next_after(f32::NEG_INFINITY) } else { f } }; let min_y = { let v = bbox.y().lo(); let f = v as f32; if (f as f64) > v { f.next_after(f32::NEG_INFINITY) } else { f } }; ``` -- 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]
