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");
> I recently learned about exprs-test, and this seems like a good fit there.
exprs-test is a good place for it. One catch: the allowCast change does not 
seem to take effect, and that one is on me - I suggested it without checking. 
On PS5 with planner=calcite, fallback_planner=none:

    trunc(2.1, cast(1 as int))                                trunc() must be 
called with a constant second argument   (original: 2.1)
    truncate(cast('3.1615' as decimal(6,4)), cast(1 as int))  same shape        
                                       (original: 3.1)
    trunc(2.1, cast(null as int))                             must be called 
with a constant                           (original: cannot be called with a 
NULL)
    round(2.1, cast(1 as int))                                same

SqlUtil.isLiteral unwraps SqlKind.CAST, but an explicit cast here is 
ImpalaCastFunction ("EXPLICIT_CAST"), and ImpalaOperator registers with 
SqlKind.OTHER, so the allowCast branch is never taken. Which means the two new 
expr-test rows pass on the original planner and would start failing once 
exprs-test runs with Calcite.

Unwrapping EXPLICIT_CAST here, or putting allowCast back to false and leaving 
the cast forms for later, would both be consistent. Whichever you prefer - the 
NPE this patch removes is the important part.



--
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: Tue, 25 Aug 2026 16:13:33 +0000
Gerrit-HasComments: Yes

Reply via email to