jackwener commented on code in PR #6504:
URL: https://github.com/apache/arrow-datafusion/pull/6504#discussion_r1218267325


##########
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:
   IMO, it looks like a `hack` patch to fix issue. maybe It isn't a good method 
to resolve this issue.
   I need to think carefully



-- 
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]

Reply via email to