james-willis commented on code in PR #1073: URL: https://github.com/apache/sedona-db/pull/1073#discussion_r3642827986
########## rust/sedona-spatial-join-raster/src/physical_planner.rs: ########## @@ -0,0 +1,322 @@ +// 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::sync::Arc; + +use arrow_schema::Schema; +use datafusion::physical_plan::ExecutionPlan; +use datafusion_common::Result; +use datafusion_physical_expr::PhysicalExpr; +use sedona_query_planner::{ + spatial_join_physical_planner::{PlanSpatialJoinArgs, SpatialJoinPhysicalPlanner}, + spatial_predicate::{RelationPredicate, SpatialPredicate, SpatialRelationType}, +}; +use sedona_schema::{ + crs::{lnglat, Crs}, + datatypes::SedonaType, + matchers::ArgMatcher, +}; +use sedona_spatial_join::{ + physical_planner::{repartition_probe_side, should_swap_join_order}, + SpatialJoinExec, +}; + +use crate::join_provider::RasterJoinProvider; + +/// [`SpatialJoinPhysicalPlanner`] implementation for raster/geometry spatial joins. +/// +/// Handles `RS_Intersects`/`RS_Contains`/`RS_Within` predicates where exactly one +/// operand is a raster and the other is a planar geometry, producing an optimized +/// [`SpatialJoinExec`] backed by a [`RasterJoinProvider`]. All other predicates +/// (including raster/raster, for which there is no fixed common CRS to compare in) +/// are declined with `None` so they fall back to the nested-loop join. +#[derive(Debug)] +pub struct RasterSpatialJoinPhysicalPlanner; + +impl RasterSpatialJoinPhysicalPlanner { + /// Create a new raster join planner. + pub fn new() -> Self { + Self + } +} + +impl Default for RasterSpatialJoinPhysicalPlanner { + fn default() -> Self { + Self::new() + } +} + +impl SpatialJoinPhysicalPlanner for RasterSpatialJoinPhysicalPlanner { + fn plan_spatial_join( + &self, + args: &PlanSpatialJoinArgs<'_>, + ) -> Result<Option<Arc<dyn ExecutionPlan>>> { + let Some(target_crs) = raster_geometry_target_crs( + args.spatial_predicate, + &args.physical_left.schema(), + &args.physical_right.schema(), + )? + else { + return Ok(None); + }; + + let should_swap = args.join_type.supports_swap() + && should_swap_join_order( + args.join_options, + args.physical_left.as_ref(), + args.physical_right.as_ref(), + )?; + + // Repartition the probe side when enabled, mirroring the default planner. + let (physical_left, physical_right) = if args.join_options.repartition_probe_side { + repartition_probe_side( + args.physical_left.clone(), + args.physical_right.clone(), + args.spatial_predicate, + should_swap, + )? + } else { + (args.physical_left.clone(), args.physical_right.clone()) + }; Review Comment: There's a PR stacked on this one that has some idea here. #1074 Would be great to get your input. -- 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]
