github-actions[bot] commented on code in PR #64293:
URL: https://github.com/apache/doris/pull/64293#discussion_r3379312883
##########
fe/fe-core/src/main/java/org/apache/doris/nereids/rules/rewrite/CountLiteralRewrite.java:
##########
@@ -107,10 +114,29 @@ 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()
+ && arg.getInputSlots().isEmpty()
+ && !arg.containsType(AggregateFunction.class,
SubqueryExpr.class,
+ TableGeneratingFunction.class, WindowExpression.class);
+ }
+
private Expression rewrite(Count count) {
if (count.child(0).isNullLiteral()) {
return new BigIntLiteral(0);
Review Comment:
This rewrite changes empty-input aggregate semantics because it moves the
original count argument into an upper project. For example, on an empty table
`SELECT count(json_extract('{"id":123}', '$.')) FROM t` should not evaluate the
aggregate argument for any input row and should return `0`, but after this
rewrite the plan evaluates `json_extract(..., '$.') IS NULL` once above
`count(*)`, and JSON path validation raises `Invalid Json Path for value: $.`
even though the aggregate input is empty. The same applies to any deterministic
row-independent expression that can fail when evaluated. Please avoid
evaluating the original argument above the aggregate for the zero-row case, or
otherwise restrict the rewrite to expressions that are proven safe to evaluate
independently, and add an empty-table negative/positive regression case.
--
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]