You are viewing a plain text version of this content. The canonical link for it is here.
Posted to github@arrow.apache.org by "jiangzhx (via GitHub)" <gi...@apache.org> on 2023/06/05 15:49:56 UTC

[GitHub] [arrow-datafusion] jiangzhx commented on a diff in pull request #6504: fix count_wildcard_rule when alias in subquery

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


##########
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(),
+                                )
+                            }
+                        };
+                        (expr.clone().rewrite(&mut rewriter).unwrap(), new_field)

Review Comment:
   thanks,fixed.



-- 
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-unsubscribe@arrow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org