jacktengg opened a new pull request, #68030:
URL: https://github.com/apache/doris/pull/68030

   Problem Summary:
   Frontend declared `NTILE(LARGEINT) -> LARGEINT`, but `WindowFunctionNTile` 
in backend always returns BIGINT, since the bucket index is computed with an 
int64 value. As a result, a legal-looking window query
   
       select ntile(170141183460469231731687303715884105727) over (order by k) 
from t;
   
   failed in the prepare phase with an internal error instead of a clear user 
error:
   
       [INTERNAL_ERROR]Result type of ntile is not matched, planner expect 
LARGEINT, but get BIGINT
   
   Fix:
   1. remove the LARGEINT signature of NTILE, so that every declared signature 
returns BIGINT and keeps consistent with backend;
   2. reject a LARGEINT bucket in `checkLegalityBeforeTypeCoercion` with an 
explicit AnalysisException, because backend computes the bucket index with an 
int64 value and can not handle a LARGEINT bucket;
   3. drop the redundant `buckets` field, which duplicated the first child and 
was not initialized when the expression is rebuilt by `withChildren`, and read 
the first argument through `getArgument(0)`.
   
   After the fix, the query above is rejected during analysis with `The bucket 
of NTILE must be an integer within the range of BIGINT, but got LARGEINT`, 
while an integer bucket (TINYINT/SMALLINT/INT/BIGINT) keeps working as before.
   
   None
   
   - Test: Regression test / Unit Test
       - `./run-regression-test.sh --run -f 
regression-test/suites/query_p0/sql_functions/window_functions/test_ntile_function.groovy`
       - `./run-fe-ut.sh --run 
org.apache.doris.nereids.trees.expressions.functions.window.NtileBucketTest`
   - Behavior changed: Yes. A LARGEINT bucket of NTILE is rejected during 
analysis with an explicit error message, instead of failing in the prepare 
phase with an internal type mismatch error.
   - Does this need documentation: No
   
   ### What problem does this PR solve?
   
   Issue Number: close #xxx
   
   Related PR: #xxx
   
   Problem Summary:
   
   ### Release note
   
   None
   
   ### Check List (For Author)
   
   - Test <!-- At least one of them must be included. -->
       - [ ] Regression test
       - [ ] Unit Test
       - [ ] Manual test (add detailed scripts or steps below)
       - [ ] No need to test or manual test. Explain why:
           - [ ] This is a refactor/code format and no logic has been changed.
           - [ ] Previous test can cover this change.
           - [ ] No code files have been changed.
           - [ ] Other reason <!-- Add your reason?  -->
   
   - Behavior changed:
       - [ ] No.
       - [ ] Yes. <!-- Explain the behavior change -->
   
   - Does this need documentation?
       - [ ] No.
       - [ ] Yes. <!-- Add document PR link here. eg: 
https://github.com/apache/doris-website/pull/1214 -->
   
   ### Check List (For Reviewer who merge this PR)
   
   - [ ] Confirm the release note
   - [ ] Confirm test cases
   - [ ] Confirm document
   - [ ] Add branch pick label <!-- Add branch pick label that this PR should 
merge into -->
   
   


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