From 14ad0e9bc805b3dba857accaf1183f3a6618c0b1 Mon Sep 17 00:00:00 2001 From: Andy Grove Date: Sat, 14 Nov 2026 03:30:56 -0700 Subject: [PATCH 1/3] fix: carry input requirements across FFI_ExecutionPlan ForeignExecutionPlan fell back to the ExecutionPlan defaults for input_distribution_requirements, required_input_ordering, maintains_input_order and benefits_from_input_partitioning. Physical optimizer rules running on the other side of the boundary, such as a foreign QueryPlanner's session rules, could not see what the plan required: EnsureRequirements added only a round-robin repartition under a FinalPartitioned aggregate. Add FFI callbacks and stable representations for Distribution, InputDistributionRequirements, PhysicalSortRequirement and OrderingRequirements, and forward them from ForeignExecutionPlan. Closes #27427 Co-Authored-By: Claude Opus 5.5 --- datafusion/ffi/src/execution_plan.rs | 317 +++++++++++++++++- .../ffi/src/physical_expr/partitioning.rs | 130 ++++++- datafusion/ffi/src/physical_expr/sort.rs | 129 +++++++ .../library-user-guide/upgrading/57.0.0.md | 13 + 4 files changed, 586 insertions(+), 3 deletions(-) diff --git a/datafusion/ffi/src/execution_plan.rs b/datafusion/ffi/src/execution_plan.rs index c7f3662c4f5a9..130041de2411f 100644 --- a/datafusion/ffi/src/execution_plan.rs +++ b/datafusion/ffi/src/execution_plan.rs @@ -11,10 +11,13 @@ use datafusion_common::config::ConfigOptions; use datafusion_common::tree_node::TreeNodeRecursion; use datafusion_common::{DataFusionError, Result, Statistics}; use datafusion_execution::{SendableRecordBatchStream, TaskContext}; +use datafusion_physical_expr::Distribution; use datafusion_physical_expr_common::metrics::MetricsSet; +use datafusion_physical_expr_common::sort_expr::OrderingRequirements; use datafusion_physical_plan::{ - ChildrenPropertiesMode, DisplayAs, DisplayFormatType, ExecutionPlan, PlanProperties, - ReplaceChildrenOptions, StatisticsArgs, StatisticsContext, + ChildrenPropertiesMode, DisplayAs, DisplayFormatType, ExecutionPlan, + InputDistributionRequirements, PlanProperties, ReplaceChildrenOptions, + StatisticsArgs, StatisticsContext, }; use stabby::string::String as SString; use stabby::vec::Vec as SVec; @@ -24,6 +27,8 @@ use crate::config::FFI_ConfigOptions; use crate::execution::FFI_TaskContext; use crate::physical_expr::FFI_PhysicalExpr; use crate::physical_expr::metrics::FFI_MetricsSet; +use crate::physical_expr::partitioning::FFI_InputDistributionRequirements; +use crate::physical_expr::sort::FFI_OrderingRequirements; use crate::plan_properties::FFI_PlanProperties; use crate::record_batch_stream::FFI_RecordBatchStream; use crate::statistics::{deserialize_statistics, serialize_statistics}; @@ -82,6 +87,24 @@ pub struct FFI_ExecutionPlan { partition: FFI_Option, ) -> FFI_Result>, + /// Return the input distribution requirements. See + /// [`ExecutionPlan::input_distribution_requirements`]. + pub input_distribution_requirements: + unsafe extern "C" fn(plan: &Self) -> FFI_InputDistributionRequirements, + + /// Return the required ordering of each child. See + /// [`ExecutionPlan::required_input_ordering`]. + pub required_input_ordering: + unsafe extern "C" fn(plan: &Self) -> SVec>, + + /// Return whether the plan maintains the order of each child. See + /// [`ExecutionPlan::maintains_input_order`]. + pub maintains_input_order: unsafe extern "C" fn(plan: &Self) -> SVec, + + /// Return whether the plan benefits from partitioning each child. See + /// [`ExecutionPlan::benefits_from_input_partitioning`]. + pub benefits_from_input_partitioning: unsafe extern "C" fn(plan: &Self) -> SVec, + /// Used to create a clone on the provider of the execution plan. This should /// only need to be called by the receiver of the plan. pub clone: unsafe extern "C" fn(plan: &Self) -> Self, @@ -244,6 +267,37 @@ unsafe extern "C" fn partition_statistics_fn_wrapper( .into() } +unsafe extern "C" fn input_distribution_requirements_fn_wrapper( + plan: &FFI_ExecutionPlan, +) -> FFI_InputDistributionRequirements { + (&plan.inner().input_distribution_requirements()).into() +} + +unsafe extern "C" fn required_input_ordering_fn_wrapper( + plan: &FFI_ExecutionPlan, +) -> SVec> { + plan.inner() + .required_input_ordering() + .iter() + .map(|ordering| ordering.as_ref().map(FFI_OrderingRequirements::from).into()) + .collect() +} + +unsafe extern "C" fn maintains_input_order_fn_wrapper( + plan: &FFI_ExecutionPlan, +) -> SVec { + plan.inner().maintains_input_order().into_iter().collect() +} + +unsafe extern "C" fn benefits_from_input_partitioning_fn_wrapper( + plan: &FFI_ExecutionPlan, +) -> SVec { + plan.inner() + .benefits_from_input_partitioning() + .into_iter() + .collect() +} + unsafe extern "C" fn release_fn_wrapper(plan: &mut FFI_ExecutionPlan) { unsafe { debug_assert!(!plan.private_data.is_null()); @@ -357,6 +411,10 @@ impl FFI_ExecutionPlan { repartitioned: repartitioned_fn_wrapper, metrics: metrics_fn_wrapper, partition_statistics: partition_statistics_fn_wrapper, + input_distribution_requirements: input_distribution_requirements_fn_wrapper, + required_input_ordering: required_input_ordering_fn_wrapper, + maintains_input_order: maintains_input_order_fn_wrapper, + benefits_from_input_partitioning: benefits_from_input_partitioning_fn_wrapper, clone: clone_fn_wrapper, release: release_fn_wrapper, version: crate::version, @@ -462,6 +520,46 @@ impl ExecutionPlan for ForeignExecutionPlan { self.children.iter().collect() } + fn required_input_distribution(&self) -> Vec { + self.input_distribution_requirements().into_per_child() + } + + fn input_distribution_requirements(&self) -> InputDistributionRequirements { + let ffi = unsafe { (self.plan.input_distribution_requirements)(&self.plan) }; + (&ffi).into() + } + + fn required_input_ordering(&self) -> Vec> { + unsafe { (self.plan.required_input_ordering)(&self.plan) } + .iter() + .map(|ordering| match ordering { + FFI_Option::Some(ordering) => OrderingRequirements::try_from(ordering) + .inspect_err(|e| { + log::error!( + "Invalid required input ordering from foreign plan {}: {e}", + self.name + ) + }) + .ok(), + FFI_Option::None => None, + }) + .collect() + } + + fn maintains_input_order(&self) -> Vec { + unsafe { (self.plan.maintains_input_order)(&self.plan) } + .iter() + .copied() + .collect() + } + + fn benefits_from_input_partitioning(&self) -> Vec { + unsafe { (self.plan.benefits_from_input_partitioning)(&self.plan) } + .iter() + .copied() + .collect() + } + fn replace_children( self: Arc, children: Vec>, @@ -573,6 +671,16 @@ pub mod tests { metrics: Option, statistics: Option, downcast_delegate: bool, + input_requirements: Option, + } + + /// Non-default input requirements for an [`EmptyExec`], one entry per child. + #[derive(Debug, Clone)] + pub struct TestInputRequirements { + pub distribution: InputDistributionRequirements, + pub ordering: Vec>, + pub maintains_input_order: Vec, + pub benefits_from_input_partitioning: Vec, } impl EmptyExec { @@ -590,9 +698,23 @@ pub mod tests { metrics: None, statistics: None, downcast_delegate: false, + input_requirements: None, } } + pub fn with_children(mut self, children: Vec>) -> Self { + self.children = children; + self + } + + pub fn with_input_requirements( + mut self, + input_requirements: TestInputRequirements, + ) -> Self { + self.input_requirements = Some(input_requirements); + self + } + pub fn with_metrics(mut self, metrics: MetricsSet) -> Self { self.metrics = Some(metrics); self @@ -669,6 +791,7 @@ pub mod tests { metrics: self.metrics.clone(), statistics: self.statistics.clone(), downcast_delegate: self.downcast_delegate, + input_requirements: self.input_requirements.clone(), })) } @@ -690,6 +813,41 @@ pub mod tests { unimplemented!() } + fn required_input_distribution(&self) -> Vec { + self.input_distribution_requirements().into_per_child() + } + + fn input_distribution_requirements(&self) -> InputDistributionRequirements { + match &self.input_requirements { + Some(reqs) => reqs.distribution.clone(), + None => InputDistributionRequirements::new(vec![ + Distribution::UnspecifiedDistribution; + self.children.len() + ]), + } + } + + fn required_input_ordering(&self) -> Vec> { + match &self.input_requirements { + Some(reqs) => reqs.ordering.clone(), + None => vec![None; self.children.len()], + } + } + + fn maintains_input_order(&self) -> Vec { + match &self.input_requirements { + Some(reqs) => reqs.maintains_input_order.clone(), + None => vec![false; self.children.len()], + } + } + + fn benefits_from_input_partitioning(&self) -> Vec { + match &self.input_requirements { + Some(reqs) => reqs.benefits_from_input_partitioning.clone(), + None => vec![true; self.children.len()], + } + } + fn downcast_delegate(&self) -> Option<&dyn ExecutionPlan> { self.downcast_delegate .then(|| self.children.first().map(|c| c.as_ref())) @@ -1005,6 +1163,161 @@ pub mod tests { Ok(()) } + /// A foreign plan reports the same input requirements as the plan it wraps, + /// so optimizer rules on the other side of the boundary see them. + #[test] + fn test_ffi_execution_plan_input_requirements_round_trip() -> Result<()> { + use arrow::compute::SortOptions; + use datafusion_physical_expr::expressions::Column; + use datafusion_physical_expr_common::sort_expr::{ + LexRequirement, PhysicalSortRequirement, + }; + + let schema = Arc::new(arrow::datatypes::Schema::new(vec![ + arrow::datatypes::Field::new("a", arrow::datatypes::DataType::Int32, false), + ])); + let a = Arc::new(Column::new("a", 0)) as Arc; + let child = + || Arc::new(EmptyExec::new(Arc::clone(&schema))) as Arc; + let foreign = |plan: EmptyExec| -> Result> { + let mut ffi = FFI_ExecutionPlan::new(Arc::new(plan), None); + ffi.library_marker_id = crate::mock_foreign_marker_id; + (&ffi).try_into() + }; + + // Defaults survive unchanged. + let default_plan = foreign( + EmptyExec::new(Arc::clone(&schema)).with_children(vec![child(), child()]), + )?; + assert_eq!( + format!("{:?}", default_plan.input_distribution_requirements()), + format!( + "{:?}", + InputDistributionRequirements::new(vec![ + Distribution::UnspecifiedDistribution; + 2 + ]) + ) + ); + assert_eq!(default_plan.required_input_ordering(), vec![None, None]); + assert_eq!(default_plan.maintains_input_order(), vec![false, false]); + assert_eq!( + default_plan.benefits_from_input_partitioning(), + vec![true, true] + ); + + // Non-default requirements, including co-partitioning and soft + // ordering, survive unchanged. + let ordering = OrderingRequirements::new_soft( + LexRequirement::new([PhysicalSortRequirement::new( + Arc::clone(&a), + Some(SortOptions::new(true, false)), + )]) + .expect("non-empty"), + ); + let reqs = TestInputRequirements { + distribution: InputDistributionRequirements::co_partitioned(vec![ + Distribution::KeyPartitioned(vec![Arc::clone(&a)]), + Distribution::KeyPartitioned(vec![Arc::clone(&a)]), + ]), + ordering: vec![Some(ordering.clone()), None], + maintains_input_order: vec![true, false], + benefits_from_input_partitioning: vec![false, true], + }; + let plan = foreign( + EmptyExec::new(Arc::clone(&schema)) + .with_children(vec![child(), child()]) + .with_input_requirements(reqs.clone()), + )?; + assert!(plan.is::()); + assert_eq!( + format!("{:?}", plan.input_distribution_requirements()), + format!("{:?}", reqs.distribution) + ); + #[expect(deprecated, reason = "the deprecated method must agree too")] + let per_child = plan.required_input_distribution(); + assert_eq!( + format!("{per_child:?}"), + format!("{:?}", reqs.distribution.clone().into_per_child()) + ); + assert_eq!(plan.required_input_ordering(), vec![Some(ordering), None]); + assert_eq!(plan.maintains_input_order(), vec![true, false]); + assert_eq!(plan.benefits_from_input_partitioning(), vec![false, true]); + + Ok(()) + } + + /// `EnsureRequirements` running on the consumer side of the boundary sees + /// that a foreign `FinalPartitioned` aggregate needs its input + /// hash-partitioned, and inserts the repartition. Without the requirement + /// crossing FFI it adds only a round-robin repartition, producing a plan + /// that groups the same key in several partitions. + #[cfg(test)] + #[tokio::test] + async fn test_ensure_requirements_sees_foreign_plan_requirements() -> Result<()> { + use datafusion::arrow::array::Int32Array; + use datafusion::arrow::datatypes::{DataType, Field, Schema}; + use datafusion::arrow::record_batch::RecordBatch; + use datafusion::common::tree_node::{Transformed, TreeNode}; + use datafusion::datasource::MemTable; + use datafusion::physical_plan::aggregates::{AggregateExec, AggregateMode}; + use datafusion::physical_plan::displayable; + use datafusion::physical_plan::repartition::RepartitionExec; + use datafusion::prelude::{SessionConfig, SessionContext}; + use datafusion_physical_optimizer::PhysicalOptimizerRule; + use datafusion_physical_optimizer::ensure_requirements::EnsureRequirements; + use datafusion_physical_optimizer::sanity_checker::check_plan_tree_sanity; + + let schema = Arc::new(Schema::new(vec![Field::new("a", DataType::Int32, false)])); + let batch = RecordBatch::try_new( + Arc::clone(&schema), + vec![Arc::new(Int32Array::from(vec![1, 2, 3, 4, 5, 6]))], + )?; + let config = SessionConfig::new().with_target_partitions(4); + let ctx = SessionContext::new_with_config(config.clone()); + ctx.register_table("t", Arc::new(MemTable::try_new(schema, vec![vec![batch]])?))?; + let plan = ctx + .sql("SELECT a % 2 AS parity, count(*) AS n FROM t GROUP BY 1") + .await? + .create_physical_plan() + .await?; + + // Remove the hash repartition under the final aggregate and send that + // aggregate across the (mock) FFI boundary. + let plan = plan + .transform_up(|node| { + let Some(agg) = node.downcast_ref::() else { + return Ok(Transformed::no(node)); + }; + if *agg.mode() != AggregateMode::FinalPartitioned { + return Ok(Transformed::no(node)); + } + let repartition = agg + .input() + .downcast_ref::() + .expect("hash repartition under the final aggregate"); + let stripped = Arc::clone(&node).replace_children( + vec![Arc::clone(repartition.input())], + ReplaceChildrenOptions::new(ChildrenPropertiesMode::Recompute), + )?; + let mut ffi = FFI_ExecutionPlan::new(stripped, None); + ffi.library_marker_id = crate::mock_foreign_marker_id; + let foreign: Arc = (&ffi).try_into()?; + Ok(Transformed::yes(foreign)) + })? + .data; + + let optimized = EnsureRequirements::new().optimize(plan, config.options())?; + let display = displayable(optimized.as_ref()).indent(false).to_string(); + assert!( + display.contains("RepartitionExec: partitioning=Hash("), + "expected a hash repartition under the foreign aggregate:\n{display}" + ); + check_plan_tree_sanity(&optimized, &config.options().optimizer)?; + + Ok(()) + } + #[test] fn test_ffi_execution_plan_local_bypass() { let schema = Arc::new(arrow::datatypes::Schema::new(vec![ diff --git a/datafusion/ffi/src/physical_expr/partitioning.rs b/datafusion/ffi/src/physical_expr/partitioning.rs index d9bfa0aaa6949..0ccbcfa6f1c85 100644 --- a/datafusion/ffi/src/physical_expr/partitioning.rs +++ b/datafusion/ffi/src/physical_expr/partitioning.rs @@ -6,9 +6,10 @@ use std::sync::Arc; use datafusion_common::{DataFusionError, ScalarValue, SplitPoint}; use datafusion_physical_expr::{ - LexOrdering, Partitioning, PhysicalSortExpr, RangePartitioning, + Distribution, LexOrdering, Partitioning, PhysicalSortExpr, RangePartitioning, }; use datafusion_physical_expr_common::physical_expr::PhysicalExpr; +use datafusion_physical_plan::InputDistributionRequirements; use stabby::vec::Vec as SVec; use crate::arrow_wrappers::WrappedArray; @@ -128,6 +129,85 @@ impl TryFrom for Partitioning { } } +/// A stable enum for sharing a [`Distribution`] across FFI boundaries. +/// +/// The deprecated [`Distribution::HashPartitioned`] is sent as +/// `KeyPartitioned`, which the optimizer treats identically. +#[repr(C)] +#[derive(Debug)] +pub enum FFI_Distribution { + UnspecifiedDistribution, + SinglePartition, + KeyPartitioned(SVec), +} + +impl From<&Distribution> for FFI_Distribution { + #[expect( + deprecated, + reason = "HashPartitioned is accepted during the KeyPartitioned migration" + )] + fn from(value: &Distribution) -> Self { + match value { + Distribution::UnspecifiedDistribution => Self::UnspecifiedDistribution, + Distribution::SinglePartition => Self::SinglePartition, + Distribution::HashPartitioned(exprs) + | Distribution::KeyPartitioned(exprs) => Self::KeyPartitioned( + exprs + .iter() + .map(Arc::clone) + .map(FFI_PhysicalExpr::from) + .collect(), + ), + } + } +} + +impl From<&FFI_Distribution> for Distribution { + fn from(value: &FFI_Distribution) -> Self { + match value { + FFI_Distribution::UnspecifiedDistribution => Self::UnspecifiedDistribution, + FFI_Distribution::SinglePartition => Self::SinglePartition, + FFI_Distribution::KeyPartitioned(exprs) => Self::KeyPartitioned( + exprs.iter().map(>::from).collect(), + ), + } + } +} + +/// A stable struct for sharing [`InputDistributionRequirements`] across FFI +/// boundaries. +#[repr(C)] +#[derive(Debug)] +pub struct FFI_InputDistributionRequirements { + /// One distribution per child. + distributions: SVec, + /// Whether all children must be co-partitioned. + co_partitioned: bool, +} + +impl From<&InputDistributionRequirements> for FFI_InputDistributionRequirements { + fn from(value: &InputDistributionRequirements) -> Self { + Self { + distributions: value + .per_child_distributions() + .map(FFI_Distribution::from) + .collect(), + co_partitioned: value.is_co_partitioned(), + } + } +} + +impl From<&FFI_InputDistributionRequirements> for InputDistributionRequirements { + fn from(value: &FFI_InputDistributionRequirements) -> Self { + let distributions = value.distributions.iter().map(Distribution::from).collect(); + if value.co_partitioned { + Self::co_partitioned(distributions) + } else { + Self::new(distributions) + } + } +} + #[cfg(test)] mod tests { use std::sync::Arc; @@ -248,4 +328,52 @@ mod tests { "{err}" ); } + + #[test] + #[expect( + deprecated, + reason = "test covers deprecated HashPartitioned being sent as KeyPartitioned" + )] + fn round_trip_ffi_input_distribution_requirements() { + use datafusion_physical_expr::Distribution; + use datafusion_physical_plan::InputDistributionRequirements; + + use crate::physical_expr::partitioning::FFI_InputDistributionRequirements; + + let a = Arc::new(Column::new("a", 0)) as Arc; + let b = Arc::new(Column::new("b", 1)) as Arc; + + let round_trip = |reqs: &InputDistributionRequirements| { + let ffi = FFI_InputDistributionRequirements::from(reqs); + InputDistributionRequirements::from(&ffi) + }; + + let single = InputDistributionRequirements::new(vec![ + Distribution::UnspecifiedDistribution, + Distribution::SinglePartition, + Distribution::KeyPartitioned(vec![Arc::clone(&a), Arc::clone(&b)]), + ]); + let returned = round_trip(&single); + assert!(!returned.is_co_partitioned()); + assert_eq!(format!("{single:?}"), format!("{returned:?}")); + + let co_partitioned = InputDistributionRequirements::co_partitioned(vec![ + Distribution::KeyPartitioned(vec![Arc::clone(&a)]), + Distribution::KeyPartitioned(vec![Arc::clone(&b)]), + ]); + let returned = round_trip(&co_partitioned); + assert!(returned.is_co_partitioned()); + assert_eq!(format!("{co_partitioned:?}"), format!("{returned:?}")); + + // The deprecated HashPartitioned is sent as the equivalent KeyPartitioned. + let hash = + InputDistributionRequirements::new(vec![Distribution::HashPartitioned( + vec![Arc::clone(&a)], + )]); + let returned = round_trip(&hash); + assert!(matches!( + returned.child_distribution(0), + Some(Distribution::KeyPartitioned(exprs)) if exprs.len() == 1 + )); + } } diff --git a/datafusion/ffi/src/physical_expr/sort.rs b/datafusion/ffi/src/physical_expr/sort.rs index 2901e856bd4d4..d332949a4abf1 100644 --- a/datafusion/ffi/src/physical_expr/sort.rs +++ b/datafusion/ffi/src/physical_expr/sort.rs @@ -5,11 +5,17 @@ use std::sync::Arc; use arrow_schema::SortOptions; +use datafusion_common::{DataFusionError, Result}; use datafusion_physical_expr::PhysicalSortExpr; use datafusion_physical_expr_common::physical_expr::PhysicalExpr; +use datafusion_physical_expr_common::sort_expr::{ + LexRequirement, OrderingRequirements, PhysicalSortRequirement, +}; +use stabby::vec::Vec as SVec; use crate::expr::expr_properties::FFI_SortOptions; use crate::physical_expr::FFI_PhysicalExpr; +use crate::util::FFI_Option; /// A stable struct for sharing [`PhysicalSortExpr`] across FFI boundaries. /// See [`PhysicalSortExpr`] for the meaning of each field. @@ -38,6 +44,95 @@ impl From<&FFI_PhysicalSortExpr> for PhysicalSortExpr { } } +/// FFI representation of a [`PhysicalSortRequirement`]. +#[repr(C)] +#[derive(Debug)] +pub struct FFI_PhysicalSortRequirement { + expr: FFI_PhysicalExpr, + options: FFI_Option, +} + +impl From<&PhysicalSortRequirement> for FFI_PhysicalSortRequirement { + fn from(value: &PhysicalSortRequirement) -> Self { + Self { + expr: FFI_PhysicalExpr::from(Arc::clone(&value.expr)), + options: value.options.as_ref().map(FFI_SortOptions::from).into(), + } + } +} + +impl From<&FFI_PhysicalSortRequirement> for PhysicalSortRequirement { + fn from(value: &FFI_PhysicalSortRequirement) -> Self { + let expr: Arc = (&value.expr).into(); + let options = match &value.options { + FFI_Option::Some(options) => Some(SortOptions::from(options)), + FFI_Option::None => None, + }; + Self { expr, options } + } +} + +/// FFI representation of [`OrderingRequirements`]. Each inner vector is one +/// alternative [`LexRequirement`]. +#[repr(C)] +#[derive(Debug)] +pub enum FFI_OrderingRequirements { + Hard(SVec>), + Soft(SVec>), +} + +fn alternatives_to_ffi( + alternatives: &[LexRequirement], +) -> SVec> { + alternatives + .iter() + .map(|lex| lex.iter().map(FFI_PhysicalSortRequirement::from).collect()) + .collect() +} + +fn alternatives_from_ffi( + alternatives: &SVec>, +) -> Result> { + alternatives + .iter() + .map(|lex| { + LexRequirement::new(lex.iter().map(PhysicalSortRequirement::from)).ok_or_else( + || { + DataFusionError::Internal( + "FFI ordering requirement must be non-empty".to_string(), + ) + }, + ) + }) + .collect() +} + +impl From<&OrderingRequirements> for FFI_OrderingRequirements { + fn from(value: &OrderingRequirements) -> Self { + match value { + OrderingRequirements::Hard(alts) => Self::Hard(alternatives_to_ffi(alts)), + OrderingRequirements::Soft(alts) => Self::Soft(alternatives_to_ffi(alts)), + } + } +} + +impl TryFrom<&FFI_OrderingRequirements> for OrderingRequirements { + type Error = DataFusionError; + + fn try_from(value: &FFI_OrderingRequirements) -> Result { + let (alternatives, soft) = match value { + FFI_OrderingRequirements::Hard(alts) => (alternatives_from_ffi(alts)?, false), + FFI_OrderingRequirements::Soft(alts) => (alternatives_from_ffi(alts)?, true), + }; + OrderingRequirements::new_alternatives(alternatives, soft).ok_or_else(|| { + DataFusionError::Internal( + "FFI ordering requirements must have at least one alternative" + .to_string(), + ) + }) + } +} + #[cfg(test)] mod tests { use std::sync::Arc; @@ -59,4 +154,38 @@ mod tests { assert_eq!(expr, foreign_expr); } + + #[test] + fn ffi_ordering_requirements_round_trip() -> datafusion_common::Result<()> { + use datafusion_physical_expr_common::sort_expr::{ + LexRequirement, OrderingRequirements, PhysicalSortRequirement, + }; + + use crate::physical_expr::sort::FFI_OrderingRequirements; + + let a = Arc::new(Column::new("a", 0)) as Arc; + let b = Arc::new(Column::new("b", 1)) as Arc; + let first = LexRequirement::new([ + PhysicalSortRequirement::new( + Arc::clone(&a), + Some(SortOptions::new(true, false)), + ), + PhysicalSortRequirement::new(Arc::clone(&b), None), + ]) + .expect("non-empty"); + let second = LexRequirement::new([PhysicalSortRequirement::new(b, None)]) + .expect("non-empty"); + + for soft in [false, true] { + let original = OrderingRequirements::new_alternatives( + [first.clone(), second.clone()], + soft, + ) + .expect("non-empty"); + let ffi = FFI_OrderingRequirements::from(&original); + let returned = OrderingRequirements::try_from(&ffi)?; + assert_eq!(original, returned); + } + Ok(()) + } } diff --git a/docs/source/library-user-guide/upgrading/57.0.0.md b/docs/source/library-user-guide/upgrading/57.0.0.md index 6404b5e0a7134..8c92c2403fd7d 100644 --- a/docs/source/library-user-guide/upgrading/57.0.0.md +++ b/docs/source/library-user-guide/upgrading/57.0.0.md @@ -97,3 +97,16 @@ that aligns with the SQL specification. ```txt COPY (SELECT * FROM t ORDER BY c1) TO 'ordered.parquet'; ``` + +### `FFI_ExecutionPlan` carries input requirements + +`FFI_ExecutionPlan` has new callbacks for `input_distribution_requirements`, +`required_input_ordering`, `maintains_input_order` and +`benefits_from_input_partitioning`, so a `ForeignExecutionPlan` now reports the +same input requirements as the plan it wraps. Previously these fell back to the +`ExecutionPlan` defaults, so physical optimizer rules running across the FFI +boundary (for example with a foreign `QueryPlanner`) could produce plans that +did not satisfy them. + +The struct has a new layout; rebuild FFI providers and consumers against the +same release. From f7f5a5137a4ce6a0b028a956264c816e90956e95 Mon Sep 17 00:00:00 2001 From: Andy Grove Date: Sun, 15 Nov 2026 18:29:34 -0700 Subject: [PATCH 2/3] fix: compare foreign physical exprs structurally and cache plan requirements Address review feedback: - Add an `eq` callback to `FFI_PhysicalExpr` so `ForeignPhysicalExpr`s wrapping equal expressions from the same library compare equal. Identity equality meant a foreign plan's input requirements never matched its foreign children's partitioning or ordering, so host planning failed the sanity check (or added redundant repartitions/sorts). - Fetch input requirements once when building `ForeignExecutionPlan` instead of crossing FFI on every optimizer call, and reject a plan with a malformed ordering requirement rather than silently dropping it. - Document that the co-partitioned flag relies on all-or-none construction. - Remove an unused `required_input_distribution` override in the test plan. - Add a cross-library integration test and mention the `FFI_PhysicalExpr` layout change in the 57 upgrade guide. Co-Authored-By: Claude Opus 5.5 --- Cargo.lock | 1 + datafusion/ffi/integration-tests/Cargo.toml | 1 + .../tests/cases/execution_plan.rs | 59 ++++++++++++++++ datafusion/ffi/src/execution_plan.rs | 67 +++++++++++-------- datafusion/ffi/src/physical_expr/mod.rs | 20 +++++- .../ffi/src/physical_expr/partitioning.rs | 5 +- datafusion/ffi/src/tests/mod.rs | 65 ++++++++++++++++++ datafusion/ffi/src/tests/utils.rs | 25 +++++++ .../library-user-guide/upgrading/57.0.0.md | 7 +- 9 files changed, 217 insertions(+), 33 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 9142bae174cf0..5fc45975735e2 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2267,6 +2267,7 @@ version = "0.1.0" dependencies = [ "arrow", "arrow-schema", + "async-trait", "datafusion", "datafusion-catalog", "datafusion-common", diff --git a/datafusion/ffi/integration-tests/Cargo.toml b/datafusion/ffi/integration-tests/Cargo.toml index 5c94315210497..3bcb5c869cb42 100644 --- a/datafusion/ffi/integration-tests/Cargo.toml +++ b/datafusion/ffi/integration-tests/Cargo.toml @@ -25,6 +25,7 @@ datafusion-ffi = { workspace = true } [dev-dependencies] arrow = { workspace = true } arrow-schema = { workspace = true } +async-trait = { workspace = true } datafusion = { workspace = true, default-features = false, features = ["sql"] } datafusion-catalog = { workspace = true } datafusion-common = { workspace = true } diff --git a/datafusion/ffi/integration-tests/tests/cases/execution_plan.rs b/datafusion/ffi/integration-tests/tests/cases/execution_plan.rs index b4c6cc5fb4a25..f74c035a528d2 100644 --- a/datafusion/ffi/integration-tests/tests/cases/execution_plan.rs +++ b/datafusion/ffi/integration-tests/tests/cases/execution_plan.rs @@ -283,3 +283,62 @@ mod tests { Ok(()) } } + +mod foreign_requirements { + use std::sync::Arc; + + use async_trait::async_trait; + use datafusion::catalog::{Session, TableProvider}; + use datafusion::logical_expr::{Expr, TableType}; + use datafusion::prelude::SessionContext; + use datafusion_common::Result; + use datafusion_ffi::tests::utils::get_requirements_exec; + use datafusion_physical_plan::{ExecutionPlan, displayable}; + + /// A host-side table whose scan returns a plan built by another library. + #[derive(Debug)] + struct ForeignScanTable(Arc); + + #[async_trait] + impl TableProvider for ForeignScanTable { + fn schema(&self) -> arrow_schema::SchemaRef { + self.0.schema() + } + fn table_type(&self) -> TableType { + TableType::Base + } + async fn scan( + &self, + _: &dyn Session, + _: Option<&[usize]>, + _: &[Expr], + _: Option, + ) -> Result> { + Ok(Arc::clone(&self.0)) + } + } + + /// A correct foreign subtree (its top node's requirement is met by its own + /// child) must plan on the host without errors or extra repartitions/sorts. + #[tokio::test] + async fn foreign_requirements_met_by_foreign_child() -> Result<()> { + for hard_ordering in [false, true] { + let ffi = get_requirements_exec(hard_ordering)?; + let foreign: Arc = (&ffi).try_into()?; + let ctx = SessionContext::new(); + ctx.register_table("t", Arc::new(ForeignScanTable(foreign)))?; + let plan = ctx + .sql("SELECT * FROM t") + .await? + .create_physical_plan() + .await?; + let display = displayable(plan.as_ref()).indent(false).to_string(); + assert!( + !display.contains("\n RepartitionExec: partitioning=Hash") + && !display.contains("\n SortExec"), + "redundant repartition or sort added:\n{display}" + ); + } + Ok(()) + } +} diff --git a/datafusion/ffi/src/execution_plan.rs b/datafusion/ffi/src/execution_plan.rs index 130041de2411f..58641b20ac87d 100644 --- a/datafusion/ffi/src/execution_plan.rs +++ b/datafusion/ffi/src/execution_plan.rs @@ -442,6 +442,12 @@ pub struct ForeignExecutionPlan { plan: FFI_ExecutionPlan, properties: Arc, children: Vec>, + /// Input requirements are fixed for a plan instance, so they are fetched + /// once on construction rather than across FFI on every optimizer call. + input_distribution_requirements: InputDistributionRequirements, + required_input_ordering: Vec>, + maintains_input_order: Vec, + benefits_from_input_partitioning: Vec, } unsafe impl Send for ForeignExecutionPlan {} @@ -497,11 +503,40 @@ impl TryFrom for ForeignExecutionPlan { .map(>::try_from) .collect::>>()?; + let input_distribution_requirements = + (&(plan.input_distribution_requirements)(&plan)).into(); + // `LexRequirement` and `OrderingRequirements` are non-empty by + // construction, so a well-formed provider never sends one that fails + // to convert. Reject the plan rather than silently dropping a + // (possibly hard) ordering requirement. + let required_input_ordering = (plan.required_input_ordering)(&plan) + .iter() + .map(|ordering| match ordering { + FFI_Option::Some(ordering) => { + OrderingRequirements::try_from(ordering).map(Some) + } + FFI_Option::None => Ok(None), + }) + .collect::>>()?; + let maintains_input_order = (plan.maintains_input_order)(&plan) + .iter() + .copied() + .collect(); + let benefits_from_input_partitioning = + (plan.benefits_from_input_partitioning)(&plan) + .iter() + .copied() + .collect(); + Ok(ForeignExecutionPlan { name, plan, properties: Arc::new(properties), children, + input_distribution_requirements, + required_input_ordering, + maintains_input_order, + benefits_from_input_partitioning, }) } } @@ -525,39 +560,19 @@ impl ExecutionPlan for ForeignExecutionPlan { } fn input_distribution_requirements(&self) -> InputDistributionRequirements { - let ffi = unsafe { (self.plan.input_distribution_requirements)(&self.plan) }; - (&ffi).into() + self.input_distribution_requirements.clone() } fn required_input_ordering(&self) -> Vec> { - unsafe { (self.plan.required_input_ordering)(&self.plan) } - .iter() - .map(|ordering| match ordering { - FFI_Option::Some(ordering) => OrderingRequirements::try_from(ordering) - .inspect_err(|e| { - log::error!( - "Invalid required input ordering from foreign plan {}: {e}", - self.name - ) - }) - .ok(), - FFI_Option::None => None, - }) - .collect() + self.required_input_ordering.clone() } fn maintains_input_order(&self) -> Vec { - unsafe { (self.plan.maintains_input_order)(&self.plan) } - .iter() - .copied() - .collect() + self.maintains_input_order.clone() } fn benefits_from_input_partitioning(&self) -> Vec { - unsafe { (self.plan.benefits_from_input_partitioning)(&self.plan) } - .iter() - .copied() - .collect() + self.benefits_from_input_partitioning.clone() } fn replace_children( @@ -813,10 +828,6 @@ pub mod tests { unimplemented!() } - fn required_input_distribution(&self) -> Vec { - self.input_distribution_requirements().into_per_child() - } - fn input_distribution_requirements(&self) -> InputDistributionRequirements { match &self.input_requirements { Some(reqs) => reqs.distribution.clone(), diff --git a/datafusion/ffi/src/physical_expr/mod.rs b/datafusion/ffi/src/physical_expr/mod.rs index 6ff3dbc90a77b..8106478b8e75b 100644 --- a/datafusion/ffi/src/physical_expr/mod.rs +++ b/datafusion/ffi/src/physical_expr/mod.rs @@ -115,6 +115,10 @@ pub struct FFI_PhysicalExpr { // Hash trait pub hash: unsafe extern "C" fn(&Self) -> u64, + /// Structural equality with `other`. Returns `false` when `other` was + /// created by a different library. + pub eq: unsafe extern "C" fn(&Self, other: &Self) -> bool, + /// Used to create a clone on the provider of the execution plan. This should /// only need to be called by the receiver of the plan. pub clone: unsafe extern "C" fn(plan: &Self) -> Self, @@ -395,6 +399,15 @@ unsafe extern "C" fn hash_fn_wrapper(expr: &FFI_PhysicalExpr) -> u64 { hasher.finish() } +unsafe extern "C" fn eq_fn_wrapper( + expr: &FFI_PhysicalExpr, + other: &FFI_PhysicalExpr, +) -> bool { + // `other.inner()` is only valid when this library created `other`. + (other.library_marker_id)() == crate::get_library_marker_id() + && expr.inner() == other.inner() +} + unsafe extern "C" fn release_fn_wrapper(expr: &mut FFI_PhysicalExpr) { unsafe { debug_assert!(!expr.private_data.is_null()); @@ -434,6 +447,7 @@ unsafe extern "C" fn clone_fn_wrapper(expr: &FFI_PhysicalExpr) -> FFI_PhysicalEx expression_id: expression_id_fn_wrapper, display: display_fn_wrapper, hash: hash_fn_wrapper, + eq: eq_fn_wrapper, clone: clone_fn_wrapper, release: release_fn_wrapper, version: super::version, @@ -478,6 +492,7 @@ impl From> for FFI_PhysicalExpr { expression_id: expression_id_fn_wrapper, display: display_fn_wrapper, hash: hash_fn_wrapper, + eq: eq_fn_wrapper, clone: clone_fn_wrapper, release: release_fn_wrapper, version: super::version, @@ -721,8 +736,7 @@ impl PhysicalExpr for ForeignPhysicalExpr { impl Eq for ForeignPhysicalExpr {} impl PartialEq for ForeignPhysicalExpr { fn eq(&self, other: &Self) -> bool { - // FFI_PhysicalExpr cannot be compared, so identity equality is the best we can do. - std::ptr::eq(self, other) + std::ptr::eq(self, other) || unsafe { (self.expr.eq)(&self.expr, &other.expr) } } } impl Hash for ForeignPhysicalExpr { @@ -994,7 +1008,7 @@ mod tests { let (_, foreign_1) = create_test_expr(); let (_, foreign_2) = create_test_expr(); - assert_ne!(&foreign_1, &foreign_2); + assert_eq!(&foreign_1, &foreign_2); let mut hasher = DefaultHasher::new(); foreign_1.as_ref().hash(&mut hasher); diff --git a/datafusion/ffi/src/physical_expr/partitioning.rs b/datafusion/ffi/src/physical_expr/partitioning.rs index 0ccbcfa6f1c85..b84d30f6452d7 100644 --- a/datafusion/ffi/src/physical_expr/partitioning.rs +++ b/datafusion/ffi/src/physical_expr/partitioning.rs @@ -181,7 +181,10 @@ impl From<&FFI_Distribution> for Distribution { pub struct FFI_InputDistributionRequirements { /// One distribution per child. distributions: SVec, - /// Whether all children must be co-partitioned. + /// Whether all children must be co-partitioned. This relies on + /// [`InputDistributionRequirements`] only being constructible with all or + /// none of its children co-partitioned; if subsets become possible, this + /// must carry the co-partitioned child indexes instead. co_partitioned: bool, } diff --git a/datafusion/ffi/src/tests/mod.rs b/datafusion/ffi/src/tests/mod.rs index 32ac7aceefb21..023d45ce6b7e5 100644 --- a/datafusion/ffi/src/tests/mod.rs +++ b/datafusion/ffi/src/tests/mod.rs @@ -281,6 +281,71 @@ pub extern "C" fn datafusion_ffi_test_create_exec_with_byte_metrics() -> FFI_Exe FFI_ExecutionPlan::new(plan, None) } +/// A plan whose top node requires its input hash-partitioned (or, with +/// `hard_ordering`, sorted) on `a`, and whose child already provides it. +/// +/// Exported as its own symbol, like +/// `datafusion_ffi_test_create_exec_with_byte_metrics`, so it does not change +/// the layout of [`ForeignLibraryModule`]. +#[unsafe(no_mangle)] +pub extern "C" fn datafusion_ffi_test_create_exec_with_requirements( + hard_ordering: bool, +) -> FFI_ExecutionPlan { + use crate::execution_plan::tests::TestInputRequirements; + use datafusion_physical_expr::Distribution; + use datafusion_physical_expr_common::sort_expr::{ + LexRequirement, OrderingRequirements, PhysicalSortRequirement, + }; + use datafusion_physical_plan::InputDistributionRequirements; + use datafusion_physical_plan::repartition::RepartitionExec; + use datafusion_physical_plan::sorts::sort::SortExec; + + let schema = Arc::new(Schema::new(vec![Field::new("a", DataType::Int32, false)])); + let a = Arc::new(Column::new("a", 0)) as Arc; + let leaf = Arc::new(EmptyExec::new(Arc::clone(&schema))) as Arc; + let (child, reqs): (Arc, _) = if hard_ordering { + let ord = + LexOrdering::new([PhysicalSortExpr::new_default(Arc::clone(&a))]).unwrap(); + let req = OrderingRequirements::new( + LexRequirement::new([PhysicalSortRequirement::new(Arc::clone(&a), None)]) + .unwrap(), + ); + ( + Arc::new(SortExec::new(ord, leaf).with_preserve_partitioning(true)), + TestInputRequirements { + distribution: InputDistributionRequirements::new(vec![ + Distribution::UnspecifiedDistribution, + ]), + ordering: vec![Some(req)], + maintains_input_order: vec![true], + benefits_from_input_partitioning: vec![false], + }, + ) + } else { + ( + Arc::new( + RepartitionExec::try_new( + leaf, + Partitioning::Hash(vec![Arc::clone(&a)], 4), + ) + .unwrap(), + ), + TestInputRequirements { + distribution: InputDistributionRequirements::new(vec![ + Distribution::KeyPartitioned(vec![Arc::clone(&a)]), + ]), + ordering: vec![None], + maintains_input_order: vec![false], + benefits_from_input_partitioning: vec![true], + }, + ) + }; + let plan = EmptyExec::new(schema) + .with_children(vec![child]) + .with_input_requirements(reqs); + FFI_ExecutionPlan::new(Arc::new(plan), None) +} + /// Thin wrapper that attaches a fixed [`Statistics`] snapshot to any inner /// [`TableProvider`] without changing its scan behaviour. #[derive(Debug)] diff --git a/datafusion/ffi/src/tests/utils.rs b/datafusion/ffi/src/tests/utils.rs index 0efca296183e9..fbdc8cb9af078 100644 --- a/datafusion/ffi/src/tests/utils.rs +++ b/datafusion/ffi/src/tests/utils.rs @@ -107,6 +107,31 @@ pub fn get_byte_metrics_exec() -> Result Result { + let lib_path = find_library()?; + let lib = unsafe { + libloading::Library::new(&lib_path) + .map_err(|e| DataFusionError::External(Box::new(e)))? + }; + let create_exec: libloading::Symbol< + extern "C" fn(bool) -> crate::execution_plan::FFI_ExecutionPlan, + > = unsafe { + lib.get(b"datafusion_ffi_test_create_exec_with_requirements") + .map_err(|e| DataFusionError::External(Box::new(e)))? + }; + let plan = create_exec(hard_ordering); + + // Leak the library to keep it loaded for the duration of the test + #[expect(clippy::mem_forget)] + std::mem::forget(lib); + + Ok(plan) +} + /// Load an independent copy of the integration-test cdylib. /// /// Copying to a unique path makes the dynamic loader create a separate image diff --git a/docs/source/library-user-guide/upgrading/57.0.0.md b/docs/source/library-user-guide/upgrading/57.0.0.md index 8c92c2403fd7d..218b422c2818a 100644 --- a/docs/source/library-user-guide/upgrading/57.0.0.md +++ b/docs/source/library-user-guide/upgrading/57.0.0.md @@ -108,5 +108,10 @@ same input requirements as the plan it wraps. Previously these fell back to the boundary (for example with a foreign `QueryPlanner`) could produce plans that did not satisfy them. -The struct has a new layout; rebuild FFI providers and consumers against the +`FFI_PhysicalExpr` also has a new `eq` callback, so two `ForeignPhysicalExpr`s +wrapping equal expressions from the same library now compare equal. Previously +they compared by identity, so a foreign plan's requirements never matched its +children's partitioning or ordering on the host. + +Both structs have a new layout; rebuild FFI providers and consumers against the same release. From 0150c0f8250a2a159685cd2aa722310a14ff8cd5 Mon Sep 17 00:00:00 2001 From: Andy Grove Date: Tue, 17 Nov 2026 06:26:02 -0700 Subject: [PATCH 3/3] test: cover cross-library ForeignPhysicalExpr eq and move FFI upgrade note to 56 Co-Authored-By: Claude Opus 5.5 --- .../tests/cases/execution_plan.rs | 42 ++++++++++++++++++- .../library-user-guide/upgrading/56.0.0.md | 18 ++++++++ .../library-user-guide/upgrading/57.0.0.md | 18 -------- 3 files changed, 59 insertions(+), 19 deletions(-) diff --git a/datafusion/ffi/integration-tests/tests/cases/execution_plan.rs b/datafusion/ffi/integration-tests/tests/cases/execution_plan.rs index f74c035a528d2..043dc79df141c 100644 --- a/datafusion/ffi/integration-tests/tests/cases/execution_plan.rs +++ b/datafusion/ffi/integration-tests/tests/cases/execution_plan.rs @@ -12,8 +12,13 @@ mod tests { ExecutionPlanPrivateData, FFI_ExecutionPlan, ForeignExecutionPlan, tests::EmptyExec, }; - use datafusion_ffi::tests::utils::{get_byte_metrics_exec, get_module}; + use datafusion_ffi::physical_expr::ForeignPhysicalExpr; + use datafusion_ffi::tests::ForeignLibraryModule; + use datafusion_ffi::tests::utils::{ + get_byte_metrics_exec, get_module, get_module_copy, + }; use datafusion_physical_expr_common::metrics::{MetricCategory, MetricValue}; + use datafusion_physical_expr_common::physical_expr::PhysicalExpr; use datafusion_physical_plan::execution_plan::InvariantLevel; use datafusion_physical_plan::{ ChildrenPropertiesMode, ExecutionPlan, Partitioning, ReplaceChildrenOptions, @@ -163,6 +168,41 @@ mod tests { Ok(()) } + /// `ForeignPhysicalExpr` equality may only look inside an expression + /// created by the same library image. Expressions from two separately + /// loaded copies of the cdylib must compare unequal even when they are + /// structurally identical, while two from the same copy compare equal. + #[test] + fn test_ffi_physical_expr_eq_across_library_images() -> Result<(), DataFusionError> { + fn range_sort_expr( + module: &ForeignLibraryModule, + ) -> Result, DataFusionError> { + let plan = (module.create_exec_with_statistics)(); + let plan: Arc = (&plan).try_into()?; + let Partitioning::Range(range) = plan.properties().output_partitioning() + else { + panic!("expected range partitioning"); + }; + Ok(Arc::clone(&range.ordering().first().expr)) + } + + let library_b = get_module_copy("physical_expr_eq_library_b")?; + let library_c = get_module_copy("physical_expr_eq_library_c")?; + + let b_1 = range_sort_expr(&library_b)?; + let b_2 = range_sort_expr(&library_b)?; + let c = range_sort_expr(&library_c)?; + assert!(b_1.downcast_ref::().is_some()); + assert!(c.downcast_ref::().is_some()); + assert_eq!(b_1.to_string(), c.to_string()); + + assert_eq!(&b_1, &b_2); + assert_ne!(&b_1, &c); + assert_ne!(&c, &b_1); + + Ok(()) + } + #[test] fn test_ffi_execution_plan_expressions_cross_library() -> Result<(), DataFusionError> { diff --git a/docs/source/library-user-guide/upgrading/56.0.0.md b/docs/source/library-user-guide/upgrading/56.0.0.md index 57e701acef6a5..4276acffcc3d0 100644 --- a/docs/source/library-user-guide/upgrading/56.0.0.md +++ b/docs/source/library-user-guide/upgrading/56.0.0.md @@ -308,6 +308,24 @@ serialized physical plan reconstructed with local type identities. See the pattern. `ForeignSession::query_planner`, `optimize`, and `physical_optimizers` continue to forward to the owning session across the FFI boundary. +### `FFI_ExecutionPlan` carries input requirements + +`FFI_ExecutionPlan` has new callbacks for `input_distribution_requirements`, +`required_input_ordering`, `maintains_input_order` and +`benefits_from_input_partitioning`, so a `ForeignExecutionPlan` now reports the +same input requirements as the plan it wraps. Previously these fell back to the +`ExecutionPlan` defaults, so physical optimizer rules running across the FFI +boundary (for example with a foreign `QueryPlanner`) could produce plans that +did not satisfy them. + +`FFI_PhysicalExpr` also has a new `eq` callback, so two `ForeignPhysicalExpr`s +wrapping equal expressions from the same library now compare equal. Previously +they compared by identity, so a foreign plan's requirements never matched its +children's partitioning or ordering on the host. + +Both structs have a new layout; rebuild FFI providers and consumers against the +same release. + ### Range partitioning supports retained samples and scaling `RangePartitioning::new` is deprecated. Prefer the validated diff --git a/docs/source/library-user-guide/upgrading/57.0.0.md b/docs/source/library-user-guide/upgrading/57.0.0.md index 218b422c2818a..6404b5e0a7134 100644 --- a/docs/source/library-user-guide/upgrading/57.0.0.md +++ b/docs/source/library-user-guide/upgrading/57.0.0.md @@ -97,21 +97,3 @@ that aligns with the SQL specification. ```txt COPY (SELECT * FROM t ORDER BY c1) TO 'ordered.parquet'; ``` - -### `FFI_ExecutionPlan` carries input requirements - -`FFI_ExecutionPlan` has new callbacks for `input_distribution_requirements`, -`required_input_ordering`, `maintains_input_order` and -`benefits_from_input_partitioning`, so a `ForeignExecutionPlan` now reports the -same input requirements as the plan it wraps. Previously these fell back to the -`ExecutionPlan` defaults, so physical optimizer rules running across the FFI -boundary (for example with a foreign `QueryPlanner`) could produce plans that -did not satisfy them. - -`FFI_PhysicalExpr` also has a new `eq` callback, so two `ForeignPhysicalExpr`s -wrapping equal expressions from the same library now compare equal. Previously -they compared by identity, so a foreign plan's requirements never matched its -children's partitioning or ordering on the host. - -Both structs have a new layout; rebuild FFI providers and consumers against the -same release.