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

James Duong commented on CALCITE-2339:
--------------------------------------

I've put up a PR for what I'm thinking should happen:

[https://github.com/apache/calcite/pull/721]

 

(This is an initial implementation to demonstrate the idea. I intend to add 
more tests for this).

 

This PR adds a new RexUtil method to convert a RexNode holding a datetime_plus 
call to an equivalent RexNode holding a TimestampAdd call.

I've changed RelToSqlConverter to check if a SqlDialect needs this 
transformation and apply it. However this introduces an odd bit of behavior 
where we need to use RexBuilder from within RelToSqlConverter (because the 
conversion process creates RexNodes, but we can't check if a dialect needs this 
conversion until we're in RelToSqlConverter already).

 

This patch handles interval literals as well as multiplications of interval 
literals. (the latter needed because the TimestampAddConvertlet creates a 
multiplication expression when normalizing a TimestampAdd call to a 
datetime_plus call).

 

I also noticed that CALCITE-2188 already implements dialect-level unparsing of 
datetime_plus to timestampadd. However this is only applicable to SqlDialects. 
Also, it doesn't appear to handle multiplications of interval literals.

> JDBC adapter should transform timestamp arithmetic for target database 
> -----------------------------------------------------------------------
>
>                 Key: CALCITE-2339
>                 URL: https://issues.apache.org/jira/browse/CALCITE-2339
>             Project: Calcite
>          Issue Type: Bug
>            Reporter: Julian Hyde
>            Assignee: Julian Hyde
>            Priority: Major
>         Attachments: Datetime Addition - Calcite.pdf
>
>
> JDBC adapter should transform timestamp arithmetic for target database.
> There are two ways in Calcite to add intervals to timestamps: the 
> TIMESTAMP_ADD function and the "<timestamp> + <interval>" operator.
> The attached document (authored by James Doung) describes their pros and cons.



--
This message was sent by Atlassian JIRA
(v7.6.3#76005)

Reply via email to