[ 
https://issues.apache.org/jira/browse/CALCITE-5713?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17724452#comment-17724452
 ] 

Guoliang Sun commented on CALCITE-5713:
---------------------------------------

Yes, you didn't misunderstand, the main change in this PR fix is to adjust 
immutability.
Or maybe there are other modifications that could be made, like making sure the 
final result of the modification is equivalent when modifying either operands 
or operators twice, do you think that would work, I'm still thinking about it.

> SqlBasicCall's Deep Copy Logic Raises Rule Optimization Exception
> -----------------------------------------------------------------
>
>                 Key: CALCITE-5713
>                 URL: https://issues.apache.org/jira/browse/CALCITE-5713
>             Project: Calcite
>          Issue Type: Bug
>          Components: core
>            Reporter: Guoliang Sun
>            Priority: Major
>
> h3. Background
> In the fix for 
> [CALCITE-4795,|https://issues.apache.org/jira/browse/CALCITE-4795] the 
> operands in the SqlBasicCall class were changed from SqlNode[] to 
> ImmutableNullableList. Also change the variable name to operandList, and add 
> a new set method to modify the elements in the collection.
> h3. Exception
> Take the following SQL as an example
> {code:sql}
> SELECT { fn TRUNCATE(
>         { fn QUARTER(
>                 { fn TIMESTAMPADD(
>                         SQL_TSI_HOUR,
>                         1,
>                         { ts '1900-01-01 00:00:00' }
>                     ) }
>             ) },
>         0
>     ) }
> FROM "TDVT"."CALCS" "CALCS"
> GROUP BY 1.1000000000000001
> {code}
> An exception is thrown when the optimization execution reaches the 
> CoreRules.PROJECT_REDUCE_EXPRESSIONS rule: {color:#DE350B}cannot translate 
> call QUARTER($t4){color}
> h3. RootCause
> The SqlBasicCall#set method uses a deep copy in order to modify immutable 
> collections and returns a new operandList object when modified.
> If the SQL contains an operation that requires a rewrite call, such as 
> QUARTER in the above SQL, the deep copy logic will cause the operator and 
> operandList to be different and eventually raise an exception.



--
This message was sent by Atlassian Jira
(v8.20.10#820010)

Reply via email to