[
https://issues.apache.org/jira/browse/CALCITE-5713?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17758799#comment-17758799
]
Guoliang Sun commented on CALCITE-5713:
---------------------------------------
Thanks for the reply, the test case is included in my PR, and using the SQL in
the description as an example.
After my PR change, the SQL executes normally without errors.
The more detailed stack error message before the fix is as follows:
{code:java}
java.lang.RuntimeException: cannot translate call QUARTER($t4)
at
org.apache.calcite.adapter.enumerable.RexToLixTranslator.visitCall(RexToLixTranslator.java:1173)
at
org.apache.calcite.adapter.enumerable.RexToLixTranslator.visitCall(RexToLixTranslator.java:101)
at org.apache.calcite.rex.RexCall.accept(RexCall.java:189)
at
org.apache.calcite.adapter.enumerable.RexToLixTranslator.visitLocalRef(RexToLixTranslator.java:1060)
at
org.apache.calcite.adapter.enumerable.RexToLixTranslator.visitLocalRef(RexToLixTranslator.java:101)
at org.apache.calcite.rex.RexLocalRef.accept(RexLocalRef.java:77)
at
org.apache.calcite.adapter.enumerable.RexToLixTranslator.implementCallOperand(RexToLixTranslator.java:1193)
at
org.apache.calcite.adapter.enumerable.RexToLixTranslator.visitCall(RexToLixTranslator.java:1180)
at
org.apache.calcite.adapter.enumerable.RexToLixTranslator.visitCall(RexToLixTranslator.java:101)
at org.apache.calcite.rex.RexCall.accept(RexCall.java:189)
at
org.apache.calcite.adapter.enumerable.RexToLixTranslator.visitLocalRef(RexToLixTranslator.java:1060)
at
org.apache.calcite.adapter.enumerable.RexToLixTranslator.visitLocalRef(RexToLixTranslator.java:101)
at org.apache.calcite.rex.RexLocalRef.accept(RexLocalRef.java:77)
at
org.apache.calcite.adapter.enumerable.RexToLixTranslator.translate(RexToLixTranslator.java:253)
at
org.apache.calcite.adapter.enumerable.RexToLixTranslator.translate(RexToLixTranslator.java:247)
at
org.apache.calcite.adapter.enumerable.RexToLixTranslator.translateList(RexToLixTranslator.java:899)
at
org.apache.calcite.adapter.enumerable.RexToLixTranslator.translateProjects(RexToLixTranslator.java:201)
at org.apache.calcite.rex.RexExecutorImpl.compile(RexExecutorImpl.java:94)
at org.apache.calcite.rex.RexExecutorImpl.compile(RexExecutorImpl.java:68)
at org.apache.calcite.rex.RexExecutorImpl.reduce(RexExecutorImpl.java:133)
at
org.apache.calcite.rel.rules.ReduceExpressionsRule.reduceExpressionsInternal(ReduceExpressionsRule.java:772)
at
org.apache.calcite.rel.rules.ReduceExpressionsRule.reduceExpressions(ReduceExpressionsRule.java:712)
at
org.apache.calcite.rel.rules.ReduceExpressionsRule$ProjectReduceExpressionsRule.onMatch(ReduceExpressionsRule.java:311)
at
org.apache.calcite.test.MockRelOptPlanner.matchRecursive(MockRelOptPlanner.java:130)
at
org.apache.calcite.test.MockRelOptPlanner.findBestExp(MockRelOptPlanner.java:101)
at
org.apache.calcite.sql.SqlBasicCallTest.testSqlBasicCallSetOperands(SqlBasicCallTest.java:62)
{code}
>From your reply, I understand that Calcite does not need to support SQL like
>fn TRUNCATE( \{ fn QUARTER( ...))} Or am I misunderstanding?
> 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
> Affects Versions: 1.35.0
> Reporter: Guoliang Sun
> Priority: Major
> Labels: pull-request-available
> Fix For: 1.36.0
>
>
> 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)