From ce4ee92df908d3e663c6ede7b040ded08c769b38 Mon Sep 17 00:00:00 2001 From: lutengda <18346072982@163.com> Date: Thu, 24 Oct 2024 10:23:51 +0800 Subject: [PATCH] add sum(count) case in PushDownProjection --- datafusion/optimizer/src/push_down_projection.rs | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/datafusion/optimizer/src/push_down_projection.rs b/datafusion/optimizer/src/push_down_projection.rs index 4dc888545e22..c2e65840ad5f 100644 --- a/datafusion/optimizer/src/push_down_projection.rs +++ b/datafusion/optimizer/src/push_down_projection.rs @@ -264,7 +264,13 @@ impl OptimizerRule for PushDownProjection { fun, args, .. }) = &agg.aggr_expr[0] { - if matches!(fun, datafusion_expr::AggregateFunction::Count) + if matches!(fun, datafusion_expr::AggregateFunction::Sum) && args.len() == 1 { + if let Expr::Column(Column { relation, name }) = &args[0] { + if relation.is_none() && name == "COUNT(UInt8(1))" { + new_aggr_expr.push(agg.aggr_expr[0].clone()); + } + } + } else if matches!(fun, datafusion_expr::AggregateFunction::Count) && args.len() == 1 && args[0] == Expr::Literal(UInt8(Some(1))) {