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


##########
rust/sedona-spatial-join/src/planner/physical_planner.rs:
##########
@@ -0,0 +1,263 @@
+// 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::collections::HashMap;
+use std::fmt;
+use std::sync::Arc;
+
+use async_trait::async_trait;
+
+use arrow_schema::Schema;
+
+use datafusion::execution::context::QueryPlanner;
+use datafusion::execution::session_state::{SessionState, SessionStateBuilder};
+use datafusion::physical_plan::ExecutionPlan;
+use datafusion::physical_planner::{DefaultPhysicalPlanner, ExtensionPlanner, 
PhysicalPlanner};
+use datafusion_common::{plan_err, DFSchema, Result};
+use datafusion_expr::logical_plan::UserDefinedLogicalNode;
+use datafusion_expr::LogicalPlan;
+use datafusion_physical_expr::create_physical_expr;
+use datafusion_physical_plan::joins::utils::JoinFilter;
+use datafusion_physical_plan::joins::NestedLoopJoinExec;
+use sedona_common::sedona_internal_err;
+
+use crate::exec::SpatialJoinExec;
+use crate::planner::logical_plan_node::SpatialJoinPlanNode;
+use crate::planner::spatial_expr_utils::{is_spatial_predicate_supported, 
transform_join_filter};
+use crate::spatial_predicate::SpatialPredicate;
+use sedona_common::option::SedonaOptions;
+
+/// Registers a query planner that can produce [`SpatialJoinExec`] from a 
logical extension node.
+pub fn register_spatial_join_planner(builder: SessionStateBuilder) -> 
SessionStateBuilder {
+    builder.with_query_planner(Arc::new(SedonaSpatialQueryPlanner))
+}
+
+/// Query planner that enables Sedona's spatial join planning.
+///
+/// Installs an [`ExtensionPlanner`] that recognizes `SpatialJoinPlanNode` and 
produces
+/// `SpatialJoinExec` when supported and enabled.
+pub struct SedonaSpatialQueryPlanner;
+
+impl fmt::Debug for SedonaSpatialQueryPlanner {
+    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
+        f.debug_struct("SedonaSpatialQueryPlanner").finish()
+    }
+}
+
+#[async_trait]
+impl QueryPlanner for SedonaSpatialQueryPlanner {
+    async fn create_physical_plan(
+        &self,
+        logical_plan: &LogicalPlan,
+        session_state: &SessionState,
+    ) -> Result<Arc<dyn ExecutionPlan>> {
+        let physical_planner = 
DefaultPhysicalPlanner::with_extension_planners(vec![Arc::new(
+            SpatialJoinExtensionPlanner {},
+        )]);
+        physical_planner
+            .create_physical_plan(logical_plan, session_state)
+            .await
+    }
+}
+
+/// Physical planner hook for `SpatialJoinPlanNode`.
+struct SpatialJoinExtensionPlanner;
+
+#[async_trait]
+impl ExtensionPlanner for SpatialJoinExtensionPlanner {
+    async fn plan_extension(
+        &self,
+        _planner: &dyn PhysicalPlanner,
+        node: &dyn UserDefinedLogicalNode,
+        logical_inputs: &[&LogicalPlan],
+        physical_inputs: &[Arc<dyn ExecutionPlan>],
+        session_state: &SessionState,
+    ) -> Result<Option<Arc<dyn ExecutionPlan>>> {
+        let Some(spatial_node) = 
node.as_any().downcast_ref::<SpatialJoinPlanNode>() else {
+            return Ok(None);
+        };
+
+        let Some(ext) = session_state
+            .config_options()
+            .extensions
+            .get::<SedonaOptions>()
+        else {
+            return sedona_internal_err!("SedonaOptions not found in session 
state extensions");
+        };
+
+        if !ext.spatial_join.enable {
+            return sedona_internal_err!("Spatial join is disabled in 
SedonaOptions");

Review Comment:
   This is intentional. There must be some programming error somewhere when we 
get a SpatialJoinPlanNode with spatial join feature disabled.



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