Skip to content

Commit 76b1311

Browse files
committed
refactor(proto): migrate window serde
Window plans still relied on centralized protobuf dispatch, keeping serialization separate from the execution plans that own their state. Both window executors share one protobuf variant. Decoding must inspect `input_order_mode` before selecting the concrete plan. Add plan-local encoders for both executors and a decoder for the shared node. Keep the legacy helpers as deprecated delegates while preserving window frames and UDF payloads on the existing wire format. CLOSES apache#23513 Signed-off-by: Jiawei Zhao <[email protected]>
1 parent 16471ee commit 76b1311

3 files changed

Lines changed: 469 additions & 138 deletions

File tree

‎datafusion/physical-plan/src/windows/bounded_window_agg_exec.rs‎

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -401,6 +401,53 @@ impl ExecutionPlan for BoundedWindowAggExec {
401401
fn cardinality_effect(&self) -> CardinalityEffect {
402402
CardinalityEffect::Equal
403403
}
404+
405+
#[cfg(feature = "proto")]
406+
fn try_to_proto(
407+
&self,
408+
ctx: &crate::proto::ExecutionPlanEncodeCtx<'_>,
409+
) -> Result<Option<datafusion_proto_models::protobuf::PhysicalPlanNode>> {
410+
use super::window_agg_exec::encode_physical_window_expr;
411+
use datafusion_proto_common::protobuf_common::EmptyMessage;
412+
use datafusion_proto_models::protobuf;
413+
use protobuf::window_agg_exec_node::InputOrderMode as ProtoInputOrderMode;
414+
415+
let input = ctx.encode_child(self.input())?;
416+
let window_expr = self
417+
.window_expr()
418+
.iter()
419+
.map(|expr| encode_physical_window_expr(expr, ctx))
420+
.collect::<Result<Vec<_>>>()?;
421+
let partition_keys = self
422+
.partition_keys()
423+
.iter()
424+
.map(|expr| ctx.encode_expr(expr))
425+
.collect::<Result<Vec<_>>>()?;
426+
let input_order_mode = match &self.input_order_mode {
427+
InputOrderMode::Linear => ProtoInputOrderMode::Linear(EmptyMessage {}),
428+
InputOrderMode::PartiallySorted(columns) => {
429+
ProtoInputOrderMode::PartiallySorted(
430+
protobuf::PartiallySortedInputOrderMode {
431+
columns: columns.iter().map(|column| *column as u64).collect(),
432+
},
433+
)
434+
}
435+
InputOrderMode::Sorted => ProtoInputOrderMode::Sorted(EmptyMessage {}),
436+
};
437+
438+
Ok(Some(protobuf::PhysicalPlanNode {
439+
physical_plan_type: Some(
440+
protobuf::physical_plan_node::PhysicalPlanType::Window(Box::new(
441+
protobuf::WindowAggExecNode {
442+
input: Some(Box::new(input)),
443+
window_expr,
444+
partition_keys,
445+
input_order_mode: Some(input_order_mode),
446+
},
447+
)),
448+
),
449+
}))
450+
}
404451
}
405452

406453
/// Trait that specifies how we search for (or calculate) partitions. It has two

0 commit comments

Comments
 (0)