Apache DataFusion SQL Query Engine
refactor(proto): migrate window serde (#23780)
Phoenix9808e83a9c3d
diff --git a/datafusion/physical-plan/src/windows/bounded_window_agg_exec.rs b/datafusion/physical-plan/src/windows/bounded_window_agg_exec.rsindex 3ca612bbdb..d586308089 100644--- a/datafusion/physical-plan/src/windows/bounded_window_agg_exec.rs+++ b/datafusion/physical-plan/src/windows/bounded_window_agg_exec.rs@@ -401,6 +401,55 @@ impl ExecutionPlan for BoundedWindowAggExec {fn cardinality_effect(&self) -> CardinalityEffect {CardinalityEffect::Equal}++ #[cfg(feature = "proto")]+ fn try_to_proto(+ &self,+ ctx: &crate::proto::ExecutionPlanEncodeCtx<'_>,+ ) -> Result<Option<datafusion_proto_models::protobuf::PhysicalPlanNode>> {+ use super::proto::encode_physical_window_expr;+ use datafusion_proto_common::protobuf_common::EmptyMessage;+ use datafusion_proto_models::protobuf;+ use protobuf::window_agg_exec_node::InputOrderMode as ProtoInputOrderMode;++ let input = ctx.encode_child(self.input())?;+ let window_expr = self+ .window_expr()+ .iter()+ .map(|expr| encode_physical_window_expr(expr, ctx))+ .collect::<Result<Vec<_>>>()?;+ let partition_keys = self+ .partition_keys()+ .iter()+ .map(|expr| ctx.encode_expr(expr))+ .collect::<Result<Vec<_>>>()?;+ // A `Some(input_order_mode)` is what tells the shared `Window` decode+ // arm to rebuild a `BoundedWindowAggExec` rather than a `WindowAggExec`.+ let input_order_mode = match &self.input_order_mode {+ InputOrderMode::Linear => ProtoInputOrderMode::Linear(EmptyMessage {}),+ InputOrderMode::PartiallySorted(columns) => {+ ProtoInputOrderMode::PartiallySorted(+ protobuf::PartiallySortedInputOrderMode {+ columns: columns.iter().map(|column| *column as u64).collect(),+ },+ )+ }+ InputOrderMode::Sorted => ProtoInputOrderMode::Sorted(EmptyMessage {}),+ };++ Ok(Some(protobuf::PhysicalPlanNode {+ physical_plan_type: Some(+ protobuf::physical_plan_node::PhysicalPlanType::Window(Box::new(+ protobuf::WindowAggExecNode {+ input: Some(Box::new(input)),+ window_expr,+ partition_keys,+ input_order_mode: Some(input_order_mode),+ },+ )),+ ),+ }))+ }}/// Trait that specifies how we search for (or calculate) partitions. It has twodiff --git a/datafusion/physical-plan/src/windows/mod.rs b/datafusion/physical-plan/src/windows/mod.rsindex b72a65cf99..baa6abd839 100644--- a/datafusion/physical-plan/src/windows/mod.rs+++ b/datafusion/physical-plan/src/windows/mod.rs@@ -18,6 +18,8 @@//! Physical expressions for window functionsmod bounded_window_agg_exec;+#[cfg(feature = "proto")]+mod proto;mod utils;mod window_agg_exec;diff --git a/datafusion/physical-plan/src/windows/proto.rs b/datafusion/physical-plan/src/windows/proto.rsnew file mode 100644index 0000000000..aa62158d18--- /dev/null+++ b/datafusion/physical-plan/src/windows/proto.rs@@ -0,0 +1,288 @@+// 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.++//! Protobuf conversions shared by window execution plans.++use std::sync::Arc;++use arrow::compute::SortOptions;+use arrow::datatypes::Schema;+use datafusion_common::{+ Result, ScalarValue, internal_datafusion_err, internal_err, not_impl_err,+};+use datafusion_expr::{+ WindowFrame, WindowFrameBound, WindowFrameUnits, WindowFunctionDefinition,+};+use datafusion_physical_expr::window::SlidingAggregateWindowExpr;+use datafusion_physical_expr_common::sort_expr::PhysicalSortExpr;+use datafusion_proto_common::protobuf_common;+use datafusion_proto_models::protobuf::{self, physical_window_expr_node};++use super::{+ PlainAggregateWindowExpr, StandardWindowExpr, WindowExpr, WindowUDFExpr,+ create_window_expr, schema_add_window_field,+};++pub(super) fn encode_physical_window_expr(+ window_expr: &Arc<dyn WindowExpr>,+ ctx: &crate::proto::ExecutionPlanEncodeCtx<'_>,+) -> Result<protobuf::PhysicalWindowExprNode> {+ let expr = window_expr.as_any();+ let mut args = window_expr.expressions().to_vec();+ let window_frame = window_expr.get_window_frame();+ let (window_function, fun_definition, ignore_nulls, distinct) =+ if let Some(plain) = expr.downcast_ref::<PlainAggregateWindowExpr>() {+ let aggregate_expr = plain.get_aggregate_expr();+ (+ physical_window_expr_node::WindowFunction::UserDefinedAggrFunction(+ aggregate_expr.fun().name().to_string(),+ ),+ ctx.encode_udaf(aggregate_expr.fun())?,+ aggregate_expr.ignore_nulls(),+ aggregate_expr.is_distinct(),+ )+ } else if let Some(sliding) = expr.downcast_ref::<SlidingAggregateWindowExpr>() {+ let aggregate_expr = sliding.get_aggregate_expr();+ (+ physical_window_expr_node::WindowFunction::UserDefinedAggrFunction(+ aggregate_expr.fun().name().to_string(),+ ),+ ctx.encode_udaf(aggregate_expr.fun())?,+ aggregate_expr.ignore_nulls(),+ aggregate_expr.is_distinct(),+ )+ } else if let Some(standard) = expr.downcast_ref::<StandardWindowExpr>() {+ if let Some(window_udf) = standard+ .get_standard_func_expr()+ .as_any()+ .downcast_ref::<WindowUDFExpr>()+ {+ // `WindowUDFExpr::args` returns the full, unfiltered argument list so+ // every argument survives the round-trip.+ args = window_udf.args().to_vec();+ (+ physical_window_expr_node::WindowFunction::UserDefinedWindowFunction(+ window_udf.fun().name().to_string(),+ ),+ ctx.encode_udwf(window_udf.fun().as_ref())?,+ false,+ false,+ )+ } else {+ return not_impl_err!(+ "User-defined window function not supported: {window_expr:?}"+ );+ }+ } else {+ return not_impl_err!("WindowExpr not supported: {window_expr:?}");+ };++ let args = ctx.encode_expressions(&args)?;+ let partition_by = ctx.encode_expressions(window_expr.partition_by())?;+ let order_by = window_expr+ .order_by()+ .iter()+ .map(|sort_expr| {+ Ok(protobuf::PhysicalSortExprNode {+ expr: Some(Box::new(ctx.encode_expr(&sort_expr.expr)?)),+ asc: !sort_expr.options.descending,+ nulls_first: sort_expr.options.nulls_first,+ })+ })+ .collect::<Result<Vec<_>>>()?;++ Ok(protobuf::PhysicalWindowExprNode {+ args,+ partition_by,+ order_by,+ window_frame: Some(encode_window_frame(window_frame.as_ref())?),+ window_function: Some(window_function),+ name: window_expr.name().to_string(),+ fun_definition,+ ignore_nulls,+ distinct,+ })+}++pub(super) fn decode_physical_window_expr(+ proto: &protobuf::PhysicalWindowExprNode,+ ctx: &crate::proto::ExecutionPlanDecodeCtx<'_>,+ input_schema: &Schema,+) -> Result<Arc<dyn WindowExpr>> {+ let args = proto+ .args+ .iter()+ .map(|expr| ctx.decode_expr(expr, input_schema))+ .collect::<Result<Vec<_>>>()?;+ let partition_by = proto+ .partition_by+ .iter()+ .map(|expr| ctx.decode_expr(expr, input_schema))+ .collect::<Result<Vec<_>>>()?;+ let order_by = proto+ .order_by+ .iter()+ .map(|sort_expr| {+ let expr = sort_expr.expr.as_ref().ok_or_else(|| {+ internal_datafusion_err!(+ "Missing expr in window order_by sort expression"+ )+ })?;+ Ok(PhysicalSortExpr {+ expr: ctx.decode_expr(expr, input_schema)?,+ options: SortOptions {+ descending: !sort_expr.asc,+ nulls_first: sort_expr.nulls_first,+ },+ })+ })+ .collect::<Result<Vec<_>>>()?;+ let window_frame = proto+ .window_frame+ .as_ref()+ .map(decode_window_frame)+ .transpose()?+ .ok_or_else(|| {+ internal_datafusion_err!("Missing required field 'window_frame' in protobuf")+ })?;+ let function = match proto.window_function.as_ref() {+ Some(physical_window_expr_node::WindowFunction::UserDefinedAggrFunction(+ name,+ )) => WindowFunctionDefinition::AggregateUDF(+ ctx.decode_udaf(name, proto.fun_definition.as_deref())?,+ ),+ Some(physical_window_expr_node::WindowFunction::UserDefinedWindowFunction(+ name,+ )) => WindowFunctionDefinition::WindowUDF(+ ctx.decode_udwf(name, proto.fun_definition.as_deref())?,+ ),+ None => {+ return internal_err!("Missing required field 'window_function' in protobuf");+ }+ };++ let name = proto.name.clone();+ // TODO: Remove extended_schema if functions are all UDAF+ let extended_schema = schema_add_window_field(&args, input_schema, &function, &name)?;+ create_window_expr(+ &function,+ name,+ &args,+ &partition_by,+ &order_by,+ Arc::new(window_frame),+ extended_schema,+ proto.ignore_nulls,+ proto.distinct,+ None,+ )+}++fn encode_window_frame(window_frame: &WindowFrame) -> Result<protobuf::WindowFrame> {+ let units = match window_frame.units {+ WindowFrameUnits::Rows => protobuf::WindowFrameUnits::Rows,+ WindowFrameUnits::Range => protobuf::WindowFrameUnits::Range,+ WindowFrameUnits::Groups => protobuf::WindowFrameUnits::Groups,+ };+ Ok(protobuf::WindowFrame {+ window_frame_units: units.into(),+ start_bound: Some(encode_window_frame_bound(&window_frame.start_bound)?),+ end_bound: Some(protobuf::window_frame::EndBound::Bound(+ encode_window_frame_bound(&window_frame.end_bound)?,+ )),+ })+}++fn encode_window_frame_bound(+ bound: &WindowFrameBound,+) -> Result<protobuf::WindowFrameBound> {+ let encode_value = |value: &ScalarValue| -> Result<protobuf_common::ScalarValue> {+ Ok(value.try_into()?)+ };+ Ok(match bound {+ WindowFrameBound::CurrentRow => protobuf::WindowFrameBound {+ window_frame_bound_type: protobuf::WindowFrameBoundType::CurrentRow.into(),+ bound_value: None,+ },+ WindowFrameBound::Preceding(value) => protobuf::WindowFrameBound {+ window_frame_bound_type: protobuf::WindowFrameBoundType::Preceding.into(),+ bound_value: Some(encode_value(value)?),+ },+ WindowFrameBound::Following(value) => protobuf::WindowFrameBound {+ window_frame_bound_type: protobuf::WindowFrameBoundType::Following.into(),+ bound_value: Some(encode_value(value)?),+ },+ })+}++fn decode_window_frame(window_frame: &protobuf::WindowFrame) -> Result<WindowFrame> {+ let units = protobuf::WindowFrameUnits::try_from(window_frame.window_frame_units)+ .map_err(|_| {+ internal_datafusion_err!(+ "Received a WindowFrame message with unknown WindowFrameUnits {}",+ window_frame.window_frame_units+ )+ })?;+ let units = match units {+ protobuf::WindowFrameUnits::Rows => WindowFrameUnits::Rows,+ protobuf::WindowFrameUnits::Range => WindowFrameUnits::Range,+ protobuf::WindowFrameUnits::Groups => WindowFrameUnits::Groups,+ };+ let start_bound =+ decode_window_frame_bound(window_frame.start_bound.as_ref().ok_or_else(+ || internal_datafusion_err!("Missing start_bound in WindowFrame"),+ )?)?;+ let end_bound = window_frame+ .end_bound+ .as_ref()+ .map(|end_bound| match end_bound {+ protobuf::window_frame::EndBound::Bound(bound) => {+ decode_window_frame_bound(bound)+ }+ })+ .transpose()?+ .unwrap_or(WindowFrameBound::CurrentRow);+ Ok(WindowFrame::new_bounds(units, start_bound, end_bound))+}++fn decode_window_frame_bound(+ bound: &protobuf::WindowFrameBound,+) -> Result<WindowFrameBound> {+ let decode_value = |value: &protobuf_common::ScalarValue| -> Result<ScalarValue> {+ Ok(ScalarValue::try_from(value)?)+ };+ let bound_type = protobuf::WindowFrameBoundType::try_from(+ bound.window_frame_bound_type,+ )+ .map_err(|_| {+ internal_datafusion_err!(+ "Received a WindowFrameBound message with unknown WindowFrameBoundType {}",+ bound.window_frame_bound_type+ )+ })?;+ match bound_type {+ protobuf::WindowFrameBoundType::CurrentRow => Ok(WindowFrameBound::CurrentRow),+ protobuf::WindowFrameBoundType::Preceding => match &bound.bound_value {+ Some(value) => Ok(WindowFrameBound::Preceding(decode_value(value)?)),+ None => Ok(WindowFrameBound::Preceding(ScalarValue::UInt64(None))),+ },+ protobuf::WindowFrameBoundType::Following => match &bound.bound_value {+ Some(value) => Ok(WindowFrameBound::Following(decode_value(value)?)),+ None => Ok(WindowFrameBound::Following(ScalarValue::UInt64(None))),+ },+ }+}diff --git a/datafusion/physical-plan/src/windows/window_agg_exec.rs b/datafusion/physical-plan/src/windows/window_agg_exec.rsindex 3eb8edd298..81838300cf 100644--- a/datafusion/physical-plan/src/windows/window_agg_exec.rs+++ b/datafusion/physical-plan/src/windows/window_agg_exec.rs@@ -21,6 +21,8 @@ use std::pin::Pin;use std::sync::Arc;use std::task::{Context, Poll};+#[cfg(feature = "proto")]+use super::proto::{decode_physical_window_expr, encode_physical_window_expr};use super::utils::create_schema;use crate::execution_plan::{CardinalityEffect, EmissionType};use crate::metrics::{BaselineMetrics, ExecutionPlanMetricsSet, MetricsSet};@@ -317,6 +319,106 @@ impl ExecutionPlan for WindowAggExec {fn cardinality_effect(&self) -> CardinalityEffect {CardinalityEffect::Equal}++ #[cfg(feature = "proto")]+ fn try_to_proto(+ &self,+ ctx: &crate::proto::ExecutionPlanEncodeCtx<'_>,+ ) -> Result<Option<datafusion_proto_models::protobuf::PhysicalPlanNode>> {+ use datafusion_proto_models::protobuf;++ let input = ctx.encode_child(self.input())?;+ let window_expr = self+ .window_expr()+ .iter()+ .map(|expr| encode_physical_window_expr(expr, ctx))+ .collect::<Result<Vec<_>>>()?;+ let partition_keys = self+ .partition_keys()+ .iter()+ .map(|expr| ctx.encode_expr(expr))+ .collect::<Result<Vec<_>>>()?;++ Ok(Some(protobuf::PhysicalPlanNode {+ physical_plan_type: Some(+ protobuf::physical_plan_node::PhysicalPlanType::Window(Box::new(+ protobuf::WindowAggExecNode {+ input: Some(Box::new(input)),+ window_expr,+ partition_keys,+ // `None` distinguishes a `WindowAggExec` from a+ // `BoundedWindowAggExec` on the shared `Window` variant.+ input_order_mode: None,+ },+ )),+ ),+ }))+ }+}++#[cfg(feature = "proto")]+impl WindowAggExec {+ /// Reconstruct a window plan from its protobuf representation.+ ///+ /// This returns a [`WindowAggExec`] when `input_order_mode` is absent and a+ /// [`BoundedWindowAggExec`] when it is present.+ ///+ /// [`BoundedWindowAggExec`]: crate::windows::BoundedWindowAggExec+ pub fn try_from_proto(+ node: &datafusion_proto_models::protobuf::PhysicalPlanNode,+ ctx: &crate::proto::ExecutionPlanDecodeCtx<'_>,+ ) -> Result<Arc<dyn ExecutionPlan>> {+ use super::BoundedWindowAggExec;+ use crate::InputOrderMode;+ use datafusion_proto_models::protobuf;+ use protobuf::window_agg_exec_node::InputOrderMode as ProtoInputOrderMode;++ let window_agg = crate::expect_plan_variant!(+ node,+ protobuf::physical_plan_node::PhysicalPlanType::Window,+ "WindowAggExec",+ );+ let input = ctx.decode_required_child(+ window_agg.input.as_deref(),+ "WindowAggExec",+ "input",+ )?;+ let input_schema = input.schema();+ let window_expr = window_agg+ .window_expr+ .iter()+ .map(|expr| decode_physical_window_expr(expr, ctx, input_schema.as_ref()))+ .collect::<Result<Vec<_>>>()?;+ let partition_keys = window_agg+ .partition_keys+ .iter()+ .map(|expr| ctx.decode_expr(expr, input_schema.as_ref()))+ .collect::<Result<Vec<_>>>()?;++ if let Some(input_order_mode) = window_agg.input_order_mode.as_ref() {+ let input_order_mode = match input_order_mode {+ ProtoInputOrderMode::Linear(_) => InputOrderMode::Linear,+ ProtoInputOrderMode::PartiallySorted(+ protobuf::PartiallySortedInputOrderMode { columns },+ ) => InputOrderMode::PartiallySorted(+ columns.iter().map(|column| *column as usize).collect(),+ ),+ ProtoInputOrderMode::Sorted(_) => InputOrderMode::Sorted,+ };+ Ok(Arc::new(BoundedWindowAggExec::try_new(+ window_expr,+ input,+ input_order_mode,+ !partition_keys.is_empty(),+ )?))+ } else {+ Ok(Arc::new(WindowAggExec::try_new(+ window_expr,+ input,+ !partition_keys.is_empty(),+ )?))+ }+ }}/// Compute the window aggregate columnsdiff --git a/datafusion/proto/src/physical_plan/mod.rs b/datafusion/proto/src/physical_plan/mod.rsindex 5cb9a922a8..e1801f66ef 100644--- a/datafusion/proto/src/physical_plan/mod.rs+++ b/datafusion/proto/src/physical_plan/mod.rs@@ -98,7 +98,7 @@ use datafusion_physical_plan::sorts::sort_preserving_merge::SortPreservingMergeEuse datafusion_physical_plan::union::{InterleaveExec, UnionExec};use datafusion_physical_plan::unnest::UnnestExec;use datafusion_physical_plan::windows::{BoundedWindowAggExec, WindowAggExec};-use datafusion_physical_plan::{ExecutionPlan, InputOrderMode, PhysicalExpr, WindowExpr};+use datafusion_physical_plan::{ExecutionPlan, PhysicalExpr};use prost::Message;use prost::bytes::BufMut;@@ -107,18 +107,18 @@ use crate::convert::{FromProto, TryFromProto};use crate::convert_required;use crate::physical_plan::from_proto::{parse_physical_expr_with_converter, parse_physical_sort_expr,- parse_physical_sort_exprs, parse_physical_window_expr,- parse_protobuf_file_scan_config, parse_record_batches, parse_table_schema_from_proto,+ parse_physical_sort_exprs, parse_protobuf_file_scan_config, parse_record_batches,+ parse_table_schema_from_proto,};use crate::physical_plan::to_proto::{serialize_file_scan_config, serialize_maybe_filter, serialize_physical_aggr_expr,serialize_physical_expr_with_converter, serialize_physical_sort_exprs,- serialize_physical_window_expr, serialize_record_batches,+ serialize_record_batches,};use crate::protobuf::physical_aggregate_expr_node::AggregateFunction;use crate::protobuf::physical_expr_node::ExprType;use crate::protobuf::physical_plan_node::PhysicalPlanType;-use crate::protobuf::{self, SortMergeJoinExecNode, proto_error, window_agg_exec_node};+use crate::protobuf::{self, SortMergeJoinExecNode, proto_error};pub mod from_proto;pub mod to_proto;@@ -790,8 +790,8 @@ pub trait PhysicalPlanNodeExt: Sized {PhysicalPlanType::LocalLimit(_) => {LocalLimitExec::try_from_proto(self.node(), &decode_ctx)}- PhysicalPlanType::Window(window_agg) => {- self.try_into_window_physical_plan(window_agg, ctx, proto_converter)+ PhysicalPlanType::Window(_) => {+ WindowAggExec::try_from_proto(self.node(), &decode_ctx)}PhysicalPlanType::Aggregate(hash_agg) => {self.try_into_aggregate_physical_plan(hash_agg, ctx, proto_converter)@@ -924,22 +924,6 @@ pub trait PhysicalPlanNodeExt: Sized {return Ok(node);}- if let Some(exec) = plan.downcast_ref::<WindowAggExec>() {- return protobuf::PhysicalPlanNode::try_from_window_agg_exec(- exec,- codec,- proto_converter,- );- }-- if let Some(exec) = plan.downcast_ref::<BoundedWindowAggExec>() {- return protobuf::PhysicalPlanNode::try_from_bounded_window_agg_exec(- exec,- codec,- proto_converter,- );- }-if let Some(exec) = plan.downcast_ref::<DataSinkExec>()&& let Some(node) = protobuf::PhysicalPlanNode::try_from_data_sink_exec(exec,@@ -1419,61 +1403,27 @@ pub trait PhysicalPlanNodeExt: Sized {LocalLimitExec::try_from_proto(&node, &decode_ctx)}+ #[deprecated(+ since = "55.0.0",+ note = "unused by DataFusion; window plans deserialize via `WindowAggExec::try_from_proto`"+ )]fn try_into_window_physical_plan(&self,window_agg: &protobuf::WindowAggExecNode,ctx: &PhysicalPlanDecodeContext<'_>,proto_converter: &dyn PhysicalProtoConverterExtension,) -> Result<Arc<dyn ExecutionPlan>> {- let input: Arc<dyn ExecutionPlan> =- into_physical_plan(&window_agg.input, ctx, proto_converter)?;- let input_schema = input.schema();-- let physical_window_expr: Vec<Arc<dyn WindowExpr>> = window_agg- .window_expr- .iter()- .map(|window_expr| {- parse_physical_window_expr(- window_expr,- ctx,- input_schema.as_ref(),- proto_converter,- )- })- .collect::<Result<Vec<_>, _>>()?;-- let partition_keys = window_agg- .partition_keys- .iter()- .map(|expr| {- proto_converter.proto_to_physical_expr(expr, input.schema().as_ref(), ctx)- })- .collect::<Result<Vec<Arc<dyn PhysicalExpr>>>>()?;-- if let Some(input_order_mode) = window_agg.input_order_mode.as_ref() {- let input_order_mode = match input_order_mode {- window_agg_exec_node::InputOrderMode::Linear(_) => InputOrderMode::Linear,- window_agg_exec_node::InputOrderMode::PartiallySorted(- protobuf::PartiallySortedInputOrderMode { columns },- ) => InputOrderMode::PartiallySorted(- columns.iter().map(|c| *c as usize).collect(),- ),- window_agg_exec_node::InputOrderMode::Sorted(_) => InputOrderMode::Sorted,- };-- Ok(Arc::new(BoundedWindowAggExec::try_new(- physical_window_expr,- input,- input_order_mode,- !partition_keys.is_empty(),- )?))- } else {- Ok(Arc::new(WindowAggExec::try_new(- physical_window_expr,- input,- !partition_keys.is_empty(),- )?))- }+ let node = protobuf::PhysicalPlanNode {+ physical_plan_type: Some(PhysicalPlanType::Window(Box::new(+ window_agg.clone(),+ ))),+ };+ let decoder = ConverterPlanDecoder {+ ctx,+ proto_converter,+ };+ let decode_ctx = ExecutionPlanDecodeCtx::new(&decoder);+ WindowAggExec::try_from_proto(&node, &decode_ctx)}fn try_into_aggregate_physical_plan(@@ -2985,89 +2935,40 @@ pub trait PhysicalPlanNodeExt: Sized {})}+ #[deprecated(+ since = "55.0.0",+ note = "unused by DataFusion; `WindowAggExec` serializes itself via `ExecutionPlan::try_to_proto`"+ )]fn try_from_window_agg_exec(exec: &WindowAggExec,codec: &dyn PhysicalExtensionCodec,proto_converter: &dyn PhysicalProtoConverterExtension,) -> Result<protobuf::PhysicalPlanNode> {- let input = protobuf::PhysicalPlanNode::try_from_physical_plan_with_converter(- exec.input().to_owned(),+ let encoder = ConverterPlanEncoder {codec,proto_converter,- )?;-- let window_expr = exec- .window_expr()- .iter()- .map(|e| serialize_physical_window_expr(e, codec, proto_converter))- .collect::<Result<Vec<protobuf::PhysicalWindowExprNode>>>()?;-- let partition_keys = exec- .partition_keys()- .iter()- .map(|e| proto_converter.physical_expr_to_proto(e, codec))- .collect::<Result<Vec<protobuf::PhysicalExprNode>>>()?;-- Ok(protobuf::PhysicalPlanNode {- physical_plan_type: Some(PhysicalPlanType::Window(Box::new(- protobuf::WindowAggExecNode {- input: Some(Box::new(input)),- window_expr,- partition_keys,- input_order_mode: None,- },- ))),- })+ };+ let encode_ctx = ExecutionPlanEncodeCtx::new(&encoder);+ exec.try_to_proto(&encode_ctx)?+ .ok_or_else(|| internal_datafusion_err!("WindowAggExec is not serializable"))}+ #[deprecated(+ since = "55.0.0",+ note = "unused by DataFusion; `BoundedWindowAggExec` serializes itself via `ExecutionPlan::try_to_proto`"+ )]fn try_from_bounded_window_agg_exec(exec: &BoundedWindowAggExec,codec: &dyn PhysicalExtensionCodec,proto_converter: &dyn PhysicalProtoConverterExtension,) -> Result<protobuf::PhysicalPlanNode> {- let input = protobuf::PhysicalPlanNode::try_from_physical_plan_with_converter(- exec.input().to_owned(),+ let encoder = ConverterPlanEncoder {codec,proto_converter,- )?;-- let window_expr = exec- .window_expr()- .iter()- .map(|e| serialize_physical_window_expr(e, codec, proto_converter))- .collect::<Result<Vec<protobuf::PhysicalWindowExprNode>>>()?;-- let partition_keys = exec- .partition_keys()- .iter()- .map(|e| proto_converter.physical_expr_to_proto(e, codec))- .collect::<Result<Vec<protobuf::PhysicalExprNode>>>()?;-- let input_order_mode = match &exec.input_order_mode {- InputOrderMode::Linear => {- window_agg_exec_node::InputOrderMode::Linear(protobuf::EmptyMessage {})- }- InputOrderMode::PartiallySorted(columns) => {- window_agg_exec_node::InputOrderMode::PartiallySorted(- protobuf::PartiallySortedInputOrderMode {- columns: columns.iter().map(|c| *c as u64).collect(),- },- )- }- InputOrderMode::Sorted => {- window_agg_exec_node::InputOrderMode::Sorted(protobuf::EmptyMessage {})- }};-- Ok(protobuf::PhysicalPlanNode {- physical_plan_type: Some(PhysicalPlanType::Window(Box::new(- protobuf::WindowAggExecNode {- input: Some(Box::new(input)),- window_expr,- partition_keys,- input_order_mode: Some(input_order_mode),- },- ))),+ let encode_ctx = ExecutionPlanEncodeCtx::new(&encoder);+ exec.try_to_proto(&encode_ctx)?.ok_or_else(|| {+ internal_datafusion_err!("BoundedWindowAggExec is not serializable")})}