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

Martijn Visser commented on FLINK-41571:
----------------------------------------

I looked into this and the gap is wider than the description. On master, 
COMPILE PLAN succeeds for every TIMESTAMPDIFF where exactly one operand is 
TIMESTAMP_LTZ (with DATE, TIME or TIMESTAMP), for all units and in both modes. 
The plan then fails in code generation. The Table API's timestampDiff fails in 
code generation for every pair with TIMESTAMP_LTZ or TIME, including two 
TIMESTAMP_LTZ operands, which SQL supports.

FLINK-21621 disabled the mixed case on purpose, so I think both paths should 
reject it during validation. A wrapper in FlinkSqlOperatorTable won't work 
here: Calcite registers the TIMESTAMPDIFF convertlet on the operator instance, 
so a wrapper changes the plan of every TIMESTAMPDIFF query. Are you picking 
this up [~hanyuzheng] ? 

> TIMESTAMPDIFF between TIMESTAMP_LTZ and DATE or TIMESTAMP passes validation 
> but fails in code generation
> --------------------------------------------------------------------------------------------------------
>
>                 Key: FLINK-41571
>                 URL: https://issues.apache.org/jira/browse/FLINK-41571
>             Project: Flink
>          Issue Type: Bug
>          Components: Table SQL / Planner
>    Affects Versions: 2.3.0
>            Reporter: Hanyu Zheng
>            Assignee: Hanyu Zheng
>            Priority: Major
>             Fix For: 2.3.0
>
>
> TIMESTAMPDIFF with a TIMESTAMP_LTZ argument and a DATE or TIMESTAMP argument 
> passes validation, then fails during code generation with a CodeGenException. 
> This happens in both batch and streaming mode.
> {code:sql}
> CREATE TABLE T (d DATE, ltz TIMESTAMP_LTZ(3)) WITH ('connector' = 'datagen');
> SELECT TIMESTAMPDIFF(DAY, d, ltz) FROM T;
> {code}
> {noformat}
> org.apache.flink.table.planner.codegen.CodeGenException: TIMESTAMP_LTZ only 
> supports diff between the same type.
> {noformat}
> ScalarOperatorGens.generateTemporalPlusMinus sends every (TIMESTAMP_LTZ, 
> DATETIME) pair to generateTimestampLtzMinus. That method only handles LTZ 
> minus LTZ and throws for any other pair. The same rule makes other shapes end 
> in the generic "Unsupported temporal arithmetic." error.
> Either support the mixed case by converting the DATE or TIMESTAMP operand to 
> TIMESTAMP_LTZ in the session time zone, or reject it in the validator with a 
> message that names both types and suggests a CAST.



--
This message was sent by Atlassian Jira
(v10.3.26#10030026)

Reply via email to