You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@calcite.apache.org by Sachin Rohaj <sa...@gmail.com> on 2019/08/23 08:52:45 UTC
Mapping arithmetic '+' operator with Date and Timestamp operands to
target dialect functions
Hello,
In one of my use case i am working on DATE and TIMESTAMP based operands. We
have
select date + interval '1' DAY from table;
I need to map this to target dialect.
select target_func(date, interval '1' DAY) from table;
*Approach*: I am planning to intercept the '+' operator in the
'SqlImplementor' class using 'call.type.getSqlTypeName()' and delegate that
responsibility to get the 'target_func' from the specific dialect.
For exampe: 'dialect.getTargetFunction(SqlTypeName)'.
Thanks,
Sachin
Re: Mapping arithmetic '+' operator with Date and Timestamp operands to target dialect functions
Posted by Julian Hyde <jh...@gmail.com>.
I like the idea of transforming the Rex/Rel tree for the target dialect.
Via a RelOptRule or other means.
Or perhaps transform the SqlNode tree (which is how we deal with ORDER BY ... NULLS LAST).
That’s better, in general, than making the SqlNode-to-string logic more and more complex, because that doesn’t scale, and is not easily shared among dialects.
Julian
> On Aug 25, 2019, at 23:12, XING JIN <ji...@gmail.com> wrote:
>
> I guess in your approach, you need to maintain a customized
> `SqlImplementor` ?
> How about add a RelOptRule and detect pattern of "date + interval '1' DAY"
> and use a RexShuttle to convert to "target_func(date, interval '1' DAY)"
> Thus only a RelOptRule needs to be maintained.
>
> Sachin Rohaj <sa...@gmail.com> 于2019年8月23日周五 下午11:32写道:
>
>> Hello,
>>
>> In one of my use case i am working on DATE and TIMESTAMP based operands. We
>> have
>> select date + interval '1' DAY from table;
>>
>> I need to map this to target dialect.
>> select target_func(date, interval '1' DAY) from table;
>>
>> *Approach*: I am planning to intercept the '+' operator in the
>> 'SqlImplementor' class using 'call.type.getSqlTypeName()' and delegate that
>> responsibility to get the 'target_func' from the specific dialect.
>> For exampe: 'dialect.getTargetFunction(SqlTypeName)'.
>>
>> Thanks,
>> Sachin
>>
Re: Mapping arithmetic '+' operator with Date and Timestamp operands
to target dialect functions
Posted by XING JIN <ji...@gmail.com>.
I guess in your approach, you need to maintain a customized
`SqlImplementor` ?
How about add a RelOptRule and detect pattern of "date + interval '1' DAY"
and use a RexShuttle to convert to "target_func(date, interval '1' DAY)"
Thus only a RelOptRule needs to be maintained.
Sachin Rohaj <sa...@gmail.com> 于2019年8月23日周五 下午11:32写道:
> Hello,
>
> In one of my use case i am working on DATE and TIMESTAMP based operands. We
> have
> select date + interval '1' DAY from table;
>
> I need to map this to target dialect.
> select target_func(date, interval '1' DAY) from table;
>
> *Approach*: I am planning to intercept the '+' operator in the
> 'SqlImplementor' class using 'call.type.getSqlTypeName()' and delegate that
> responsibility to get the 'target_func' from the specific dialect.
> For exampe: 'dialect.getTargetFunction(SqlTypeName)'.
>
> Thanks,
> Sachin
>