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

Mihai Budiu commented on CALCITE-7829:
--------------------------------------

Since VALUES contains an integer, this is interpreted as VALUES(0, 
CAST(CAST(... AS TIME) AS INT), 0).

The optimizer evaluates the constant expression using the built-in semantics of 
converting times to integers.

> RexSimplify rewrites Date to int
> --------------------------------
>
>                 Key: CALCITE-7829
>                 URL: https://issues.apache.org/jira/browse/CALCITE-7829
>             Project: Calcite
>          Issue Type: Bug
>            Reporter: Tomasz Gawęda
>            Priority: Major
>
> In Hazelcast we have a test called RowAssignmentTypeCoercionTest. When trying 
> to upgrade to Calcite 1.42 we've noticed, that some cases fail (despite 
> working previously). 
>  
> For example, queries:
> {code:sql}
> CREATE MAPPING m type IMap OPTIONS('keyFormat'='int', 'valueFormat'='java', 
> 'valueJavaClass'='com.hazelcast.jet.sql.impl.support.expressions.ExpressionValue$ObjectVal')
> SINK INTO m VALUES(0, cast('01:42:00' as time), 0)
> {code}
> translate to:
> {code:java}
> LogicalTableSink(table=[[hazelcast, public, m[projects=[$0, $1, $2, $3]]]], 
> operation=[INSERT], flattened=[false])
>   LogicalCalc(expr#0=[\{inputs}], expr#1=[0], expr#2=[6120000], 
> expr#3=[CAST($t2):OBJECT], expr#4=[null:OBJECT], __key=[$t1], field1=[$t3], 
> key=[$t1], this=[$t4])
>     LogicalValues(tuples=[[\{ 0 }]])
> {code}
> As you can see, `01:42:00` was translated to 6120000. This integer value is 
> then written to a field of type OBJECT.
> Previously, in 1.39 dates and times landed in "object" field with their real 
> types, not converted to integer, which makes me believe, that RexSimplify 
> tries. to simplify a bit too much.
> (cast(cast('01:42:00' as time) as object) = time written to object column, 
> not integer value.
> More from trace logs from this test:
> {code:java}
> 16:13:53,549 TRACE |test_insertValues[TestParams{id=2014, srcType=TIME, 
> targetType=OBJECT, srcValue=01:42}]| - [parser] test_insertValues - After 
> unconditional rewrite: SINK INTO `m`
> VALUES ROW(0, CAST('01:42:00' AS TIME), 0)
> 16:13:53,576 TRACE |test_insertValues[TestParams{id=2014, srcType=TIME, 
> targetType=OBJECT, srcValue=01:42}]| - [parser] test_insertValues - After 
> validation: SINK INTO `hazelcast`.`public`.`m` (`__key`, `field1`, `key`)
> VALUES ROW(CAST(0 AS INTEGER), CAST('01:42:00' AS TIME), CAST(0 AS INTEGER))
> 16:13:53,759 DEBUG |test_insertValues[TestParams{id=2014, srcType=TIME, 
> targetType=OBJECT, srcValue=01:42}]| - [sql2rel] test_insertValues - Plan 
> after converting SqlNode to RelNode
> LogicalTableSink(table=[[hazelcast, public, m[projects=[$0, $1, $2, $3]]]], 
> operation=[INSERT], flattened=[false])
>   LogicalProject(__key=[0], field1=[CAST(6120000):OBJECT], key=[0], 
> this=[null:OBJECT])
>     LogicalValues(tuples=[[{ 0 }]])
> {code}
>  



--
This message was sent by Atlassian Jira
(v8.20.10#820010)

Reply via email to