Aleksandr Efimov has posted comments on this change. ( 
http://gerrit.cloudera.org:8080/24260 )

Change subject: IMPALA-14946: Catch "trunc" error within Calcite planner
......................................................................


Patch Set 2:

(1 comment)

http://gerrit.cloudera.org:8080/#/c/24260/2/java/calcite-planner/src/main/java/org/apache/impala/calcite/operators/ImpalaAdjustScaleFunction.java
File 
java/calcite-planner/src/main/java/org/apache/impala/calcite/operators/ImpalaAdjustScaleFunction.java:

http://gerrit.cloudera.org:8080/#/c/24260/2/java/calcite-planner/src/main/java/org/apache/impala/calcite/operators/ImpalaAdjustScaleFunction.java@63
PS2, Line 63:         throw new RuntimeException("Invalid Truncate Unit for 
scale");
> Made the cleaner exception handling, added tests
On master every one of these forms ends in NullPointerException: Cannot invoke 
"java.lang.Integer.intValue()" because "scale" is null; with PS3 the two cases 
the original planner also rejects come out word for word the same.

Measured the rest on PS3 through both planners, frontend only:

    trunc(2.1, int_col)            orig: must be called with a constant   
calcite: same
    trunc(2.1, null)               orig: cannot be called with a NULL     
calcite: same
    trunc(2.1, cast(1 as int))     orig: plans fine                       
calcite: must be called with a constant
    trunc(2.1, 1 + 1)              orig: plans fine                       
calcite: must be called with a constant
    trunc(2.1, cast(null as int))  orig: cannot be called with a NULL     
calcite: must be called with a constant
    round(2.1, cast(1 as int))     orig: plans fine                       
calcite: must be called with a constant

isOperandLiteral(1, false) and isOperandNull(1, false) count a cast of a 
literal as non-constant, while the original planner checks 
children_.get(1).isConstant(). Passing true for allowCast lines up both cast 
rows, and nothing else has to change for it - getOperandLiteralValue already 
unwraps a CAST in SqlCallBinding.valueAs. The "1 + 1" row needs the operand 
reduced first, which is probably beyond this patch. None of these are 
regressions; they were all NPEs before.

Also worth knowing: for the query in the commit message, 
dayofyear(trunc('2014-11-11', string_col)), the frontend now says "trunc() must 
be called with a constant second argument" - the original planner gets through 
analysis there, and the second argument is a time unit rather than a scale.

One question: this reaches the caller as java.lang.IllegalArgumentException 
rather than an AnalysisException - CalciteAnalysisDriver catches 
ImpalaException and CalciteContextException only. I went through 
parseAndAnalyze, so it may be converted higher up. Is it?



--
To view, visit http://gerrit.cloudera.org:8080/24260
To unsubscribe, visit http://gerrit.cloudera.org:8080/settings

Gerrit-Project: Impala-ASF
Gerrit-Branch: master
Gerrit-MessageType: comment
Gerrit-Change-Id: I766c138fae027ba0d919daa5cce38dc93d7144d1
Gerrit-Change-Number: 24260
Gerrit-PatchSet: 2
Gerrit-Owner: Steve Carlin <[email protected]>
Gerrit-Reviewer: Aleksandr Efimov <[email protected]>
Gerrit-Reviewer: Aman Sinha <[email protected]>
Gerrit-Reviewer: Impala Public Jenkins <[email protected]>
Gerrit-Reviewer: Joe McDonnell <[email protected]>
Gerrit-Reviewer: Michael Smith <[email protected]>
Gerrit-Reviewer: Quanlong Huang <[email protected]>
Gerrit-Reviewer: Steve Carlin <[email protected]>
Gerrit-Comment-Date: Sun, 23 Aug 2026 21:16:44 +0000
Gerrit-HasComments: Yes

Reply via email to