Kontinuation commented on code in PR #573:
URL: https://github.com/apache/sedona-db/pull/573#discussion_r2780493637


##########
rust/sedona-spatial-join/src/probe/knn_results_merger.rs:
##########
@@ -0,0 +1,2226 @@
+// 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 core::f64;
+use std::ops::Range;
+use std::sync::Arc;
+
+use arrow::array::{
+    Array, ArrayBuilder, AsArray, Float64Array, ListArray, 
OffsetBufferBuilder, PrimitiveBuilder,
+    RecordBatch, StructArray, UInt64Array,
+};
+use arrow::buffer::OffsetBuffer;
+use arrow::compute::{concat, concat_batches, interleave};
+use arrow::datatypes::{DataType, Field, Float64Type, Schema, SchemaRef, 
UInt64Type};
+use arrow_array::ArrayRef;
+use arrow_schema::Fields;
+use datafusion::config::SpillCompression;
+use datafusion_common::{arrow_datafusion_err, DataFusionError, Result};
+use datafusion_execution::disk_manager::RefCountedTempFile;
+use datafusion_execution::runtime_env::RuntimeEnv;
+use datafusion_physical_plan::metrics::SpillMetrics;
+use sedona_common::sedona_internal_err;
+
+use crate::index::spatial_index::DISTANCE_TOLERANCE;
+use crate::utils::spill::{RecordBatchSpillReader, RecordBatchSpillWriter};
+
+/// [UnprocessedKNNResultBatch] represents the KNN results produced by probing 
the spatial index.
+/// An [UnprocessedKNNResultBatch] may include KNN results for multiple probe 
rows.
+///
+/// The KNN results are stored in a StructArray, where each row corresponds to 
a KNN result.
+/// The results for the same probe row are stored in contiguous rows, and the 
offsets to
+/// split the results into groups per probe row are stored in the `offsets` 
field.
+///
+/// Each probe row has a unique index. The index must be strictly increasing
+/// across probe rows. The sequence of index across the entire sequence of 
ingested
+/// [UnprocessedKNNResultBatch] must also be strictly increasing. The index is 
computed based on
+/// the 0-based index of the probe row in this probe partition.
+///
+/// The KNN results are filtered, meaning that the original KNN results 
obtained by probing
+/// the spatial index may be further filtered based on some predicates. It is 
also possible that
+/// all the KNN results for a probe row are filtered out. However, we still 
need to keep track of the
+/// distances of unfiltered results to correctly compute the top-K distances 
before filtering. This
+/// is critical for correctly merging KNN results from multiple partitions.

Review Comment:
   It can be any condition, not necessarily related to the distance.
   
   The writing can be a bit confusing. I have extended the comment to explain 
it.



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