jiangzhx commented on code in PR #6504: URL: https://github.com/apache/arrow-datafusion/pull/6504#discussion_r1218278880
########## datafusion/optimizer/src/analyzer/count_wildcard_rule.rs: ########## @@ -97,19 +98,47 @@ fn analyze_internal(plan: LogicalPlan) -> Result<Transformed<LogicalPlan>> { fetch, }))) } - LogicalPlan::Projection(projection) => { - let projection_expr = projection - .expr - .iter() - .map(|expr| expr.clone().rewrite(&mut rewriter)) - .collect::<Result<Vec<_>>>()?; + LogicalPlan::Projection(projection) + if matches!( + projection.input.as_ref(), + LogicalPlan::Aggregate(..) | LogicalPlan::Window(..) + ) => + { + let (new_exprs, new_fields): (Vec<_>, Vec<_>) = + izip!(projection.expr.iter(), projection.schema.fields().iter()) + .map(|(expr, field)| { + let new_field = match expr { + Expr::Alias(_, _) => field.clone(), + _ => { + let mut name = field.field().name().clone(); + if name.contains(COUNT_STAR) { + name = name.replace( + COUNT_STAR, + count(lit(COUNT_STAR_EXPANSION)) + .to_string() + .as_str(), + ); + } + DFField::new( + field.qualifier().cloned(), + &name, + field.data_type().clone(), + field.is_nullable(), + ) + } + }; Review Comment: Yes, this piece of code is indeed difficult to understand and seems strange. However, I haven't found a good solution for it yet. thanks for your help. -- 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: github-unsubscr...@arrow.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org