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


##########
fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/window/Ntile.java:
##########
@@ -80,12 +81,22 @@ public void checkLegalityBeforeTypeCoercion() {
             throw new AnalysisException(
                 "The bucket of NTILE must be a constant value: " + 
this.toSql());
         }
-        if (buckets instanceof Literal) {
-            if (((Literal) buckets).getDouble() <= 0) {
-                throw new AnalysisException(
-                    "The bucket parameter of NTILE must be a constant positive 
integer: " + this.toSql());
-            }
-        } else {
+        // The bucket may be a constant expression such as `1 + 1`, which is 
folded to a literal only by the
+        // rewrite phase after this check runs. Evaluate it here so that any 
constant expression yielding a
+        // positive integer is accepted, while a non-positive or unevaluable 
bucket is still rejected.
+        
checkPositiveBucket(FoldConstantRuleOnFE.evaluateWithoutContext(buckets));

Review Comment:
   [P2] Honor the configured constant-fold path when validating the bucket
   
   This binding-time check uses the FE-only context-free evaluator, so it 
rejects constants that the configured rewrite can fold on BE. For example, with 
`enable_fold_constant_by_be=true`, `ntile(3 % 2)` reaches this line with an 
integral deterministic constant, but FE has no `mod` executor and 
`evaluateWithoutContext` returns the non-literal `Mod`; the query fails here 
even though the normal `FoldConstantRule` would ask BE to produce literal `1`. 
The same happens for `crc32('a')`. Please validate through the configured 
folding strategy (or another unavoidable post-fold boundary) while preserving 
an unconditional positive-literal guard even when window-expression rewrite 
rules are disabled, and add a BE-fold-mode regression.



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