pwrliang commented on code in PR #465:
URL: https://github.com/apache/sedona-db/pull/465#discussion_r2696449267


##########
rust/sedona-spatial-join-gpu/src/exec.rs:
##########
@@ -0,0 +1,294 @@
+// 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::any::Any;
+use std::fmt::{Debug, Formatter};
+use std::sync::Arc;
+
+use arrow::datatypes::SchemaRef;
+use datafusion::error::{DataFusionError, Result};
+use datafusion::execution::context::TaskContext;
+use datafusion::physical_expr::EquivalenceProperties;
+use datafusion::physical_plan::execution_plan::{Boundedness, EmissionType};
+use datafusion::physical_plan::{
+    joins::utils::build_join_schema, DisplayAs, DisplayFormatType, 
ExecutionPlan, PlanProperties,
+    SendableRecordBatchStream,
+};
+use datafusion_physical_plan::metrics::ExecutionPlanMetricsSet;
+use datafusion_physical_plan::ExecutionPlanProperties;
+use futures::stream::StreamExt;
+use parking_lot::Mutex;
+
+use crate::config::GpuSpatialJoinConfig;
+use crate::once_fut::OnceAsync;
+
+/// GPU-accelerated spatial join execution plan
+///
+/// This execution plan accepts two child inputs (e.g., ParquetExec) and 
performs:
+/// 1. Reading data from child streams
+/// 2. Data transfer to GPU memory
+/// 3. GPU spatial join execution
+/// 4. Result materialization
+pub struct GpuSpatialJoinExec {
+    /// Left child execution plan (build side)
+    left: Arc<dyn ExecutionPlan>,
+
+    /// Right child execution plan (probe side)
+    right: Arc<dyn ExecutionPlan>,
+
+    /// Join configuration
+    config: GpuSpatialJoinConfig,
+
+    /// Combined output schema
+    schema: SchemaRef,
+
+    /// Execution properties
+    properties: PlanProperties,
+
+    /// Metrics for this join operation
+    metrics: datafusion_physical_plan::metrics::ExecutionPlanMetricsSet,
+
+    /// Shared build data computed once and reused across all output partitions
+    once_async_build_data: 
Arc<Mutex<Option<OnceAsync<crate::build_data::GpuBuildData>>>>,
+}
+
+impl GpuSpatialJoinExec {
+    pub fn new(
+        left: Arc<dyn ExecutionPlan>,
+        right: Arc<dyn ExecutionPlan>,
+        config: GpuSpatialJoinConfig,
+    ) -> Result<Self> {
+        // Build join schema using DataFusion's utility to handle duplicate 
column names
+        let left_schema = left.schema();
+        let right_schema = right.schema();
+        let (join_schema, _column_indices) =
+            build_join_schema(&left_schema, &right_schema, &config.join_type);
+        let schema = Arc::new(join_schema);
+
+        // Create execution properties
+        // Output partitioning matches right side to enable parallelism
+        let eq_props = EquivalenceProperties::new(schema.clone());
+        let partitioning = right.output_partitioning().clone();
+        let properties = PlanProperties::new(
+            eq_props,
+            partitioning,
+            EmissionType::Final, // GPU join produces all results at once

Review Comment:
   This file has been completely rewritten.



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