alamb commented on code in PR #27207:
URL: https://github.com/apache/datafusion/pull/27207#discussion_r4761298957
##########
datafusion/physical-plan/src/windows/proto.rs:
##########
@@ -22,66 +23,87 @@ use datafusion_proto_models::protobuf::{self,
physical_window_expr_node};
use super::{
PlainAggregateWindowExpr, StandardWindowExpr, WindowExpr, WindowUDFExpr,
- create_window_expr, schema_add_window_field,
+ new_udwf_window_expr, schema_add_window_field,
window_expr_from_aggregate_expr,
};
-pub(super) fn encode_physical_window_expr(
+/// Serialize a [`WindowExpr`] to protobuf.
+pub 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();
+ let (
+ window_function,
+ fun_definition,
+ ignore_nulls,
+ distinct,
+ is_reversed,
+ ordering_req,
+ filter,
+ ) = 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(),
+ aggregate_expr.is_reversed(),
+ aggregate_expr.order_bys(),
+ plain.filter_expr(),
+ )
+ } 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(),
+ aggregate_expr.is_reversed(),
+ aggregate_expr.order_bys(),
+ sliding.filter_expr(),
+ )
+ } 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::UserDefinedAggrFunction(
- aggregate_expr.fun().name().to_string(),
+
physical_window_expr_node::WindowFunction::UserDefinedWindowFunction(
+ window_udf.fun().name().to_string(),
),
- ctx.encode_udaf(aggregate_expr.fun())?,
- aggregate_expr.ignore_nulls(),
- aggregate_expr.is_distinct(),
+ ctx.encode_udwf(window_udf.fun().as_ref())?,
+ window_udf.ignore_nulls(),
+ false,
+ window_udf.is_reversed(),
+ &[][..],
+ None,
)
- } 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:?}");
- };
+ 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 = sort_exprs_try_to_proto(window_expr.order_by(),
&ctx.expr_ctx())?;
+ let ordering_req = sort_exprs_try_to_proto(ordering_req, &ctx.expr_ctx())?;
+ let filter = filter
+ .map(|expr| ctx.encode_expr(expr).map(Box::new))
Review Comment:
in theory the need for this Box is a breaking API change, so when we
backport to branch-56 we should potentially find some way to avoid it
--
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]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]