github-actions[bot] commented on code in PR #64293:
URL: https://github.com/apache/doris/pull/64293#discussion_r3385747839


##########
fe/fe-core/src/main/java/org/apache/doris/nereids/rules/rewrite/CountLiteralRewrite.java:
##########
@@ -107,10 +114,40 @@ private boolean isCountLiteral(AggregateFunction aggFunc) 
{
                 && aggFunc.child(0).isLiteral();
     }
 
+    private boolean isCountConstantExpression(AggregateFunction aggFunc) {
+        if (aggFunc.isDistinct()
+                || !(aggFunc instanceof Count)
+                || aggFunc.children().size() != 1) {
+            return false;
+        }
+        Expression arg = aggFunc.child(0);
+        return !arg.isLiteral()
+                && arg.foldable()
+                && !arg.containsNondeterministic()
+                && !arg.containsVolatileExpression()

Review Comment:
   This still allows rewriting a `Count` that is itself the function child of a 
`WindowExpression`, because the `WindowExpression` is the parent, not inside 
`arg`. A grouped window query such as `SELECT id, count(json_extract('{"a":1}', 
'$.a')) OVER () FROM count_constant_rewrite_test GROUP BY id` can reach this 
rule while the `LogicalAggregate` output still contains the window expression. 
The new branch rewrites `WindowExpression(Count(arg))` into 
`WindowExpression(IF(arg IS NULL, 0, Count()))`; then `NormalizeAggregate` can 
collect that nested `Count()` from 
`WindowExpression.getExpressionsInWindowSpec()`, leaving a window expression 
whose function is no longer an aggregate/window function. Please skip 
`WindowExpression` function bodies for this rewrite, or use a non-windowed 
aggregate collector for the constant-expression path, and add coverage for 
windowed `count(const_expr)`.



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


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to