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

Thomas D'Silva commented on CALCITE-5010:
-----------------------------------------

I tried using RexToSqlNodeConverter to convert the RexCall being created to a 
SqlNode so that we can use existing convertlets without making any code 
changes, but I could not figure out how to handle RexInputRefs 
(RexToSqlNodeConverterImpl.convertInputRef currently returns null). I created a 
PR where I added a method with the default implementation of null to 
SqlRexConvertlet
{code:java}
RexNode convertCall(RexCall call, RexBuilder rexBuilder)
{code}
I refactored the TimestampDiffConvertlet and TimestampAddConvertlet to 
implement this method so that the RexCall created in RexBuilder can be 
transformed. I did not change any of the other convertlets, I will check how 
this affects aggregate functions.
 

> Modify RexBuilder to use convertlets to transform the RexCall when possible
> ---------------------------------------------------------------------------
>
>                 Key: CALCITE-5010
>                 URL: https://issues.apache.org/jira/browse/CALCITE-5010
>             Project: Calcite
>          Issue Type: Improvement
>          Components: core
>            Reporter: Thomas D'Silva
>            Priority: Minor
>              Labels: pull-request-available
>          Time Spent: 10m
>  Remaining Estimate: 0h
>
> SqlRexConvertlets are used to transform a SqlCall into a RexCall while 
> parsing a sql string. A RelNode that is created using RelBuilder does not use 
> the same transformations. This causes the following error while trying to use 
> RelBuilder to create a relnode that use  {{{}TIMESTAMPDIFF(){}}}.
> {code:java}
> Suppressed: java.lang.RuntimeException: cannot translate call 
> TIMESTAMPDIFF($t8, $t4, $t9)
> at 
> org.apache.calcite.adapter.enumerable.RexToLixTranslator.visitCall(RexToLixTranslator.java:1157)
> at 
> org.apache.calcite.adapter.enumerable.RexToLixTranslator.visitCall(RexToLixTranslator.java:98)
> {code}
> Modify RexBuilder to check if there is a convertlet that exists for the 
> operator being constructed and transform the RexCall using the convertlet.



--
This message was sent by Atlassian Jira
(v8.20.1#820001)

Reply via email to