viirya commented on code in PR #8459:
URL: https://github.com/apache/arrow-datafusion/pull/8459#discussion_r1419514312


##########
datafusion/optimizer/src/optimize_projections.rs:
##########
@@ -213,6 +213,16 @@ fn optimize_projections(
             let (aggregate_input, _is_added) =
                 add_projection_on_top_if_helpful(aggregate_input, 
necessary_exprs, true)?;
 
+            // Aggregate always needs at least one aggregate expression.
+            // With a nested count we don't require any column as input, but 
still need to create a correct aggregate
+            // The aggregate may be optimized out later (select count(*) from 
(select count(*) from [...]) always returns 1
+            if new_aggr_expr.is_empty()
+                && new_group_bys.is_empty()
+                && !aggregate.aggr_expr.is_empty()
+            {
+                new_aggr_expr = vec![aggregate.aggr_expr[0].clone()];

Review Comment:
   Hmm, why only taking the agg expr at index 0? If there are multiple agg 
expr? Is because they are not necessary by the parent query?



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