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

Aleksey Plekhanov commented on CALCITE-6714:
--------------------------------------------

The whole expression is converted to {{RexLiteral}} with numeric value 1.000000 
by {{StandardConvertletTable.convertCast}} without multiplying to interval time 
unit multiplier, since outer cast argument is not {{SqlNumericLiteral}}, but 
another cast. Value has type {{DECIMAL}} with scale 6 (1.000000), scale is 
inherited from {{DEFAULT_INTERVAL_FRACTIONAL_SECOND_PRECISION}}. In 
{{RexToLixTranslator.translateLiteral}} value of interval literal is calculated 
using expression {{value2 = literal.getValueAs(Long.class)}}, this expression 
transforms {{BigDecimal}} value using {{clazz.cast(((BigDecimal) 
value).unscaledValue().longValue())}} and for for 1.000000 returns 1000000 
(milliseconds) = 16.666 minutes.

> Cast literal to interval gives the wrong result if literal is casted
> --------------------------------------------------------------------
>
>                 Key: CALCITE-6714
>                 URL: https://issues.apache.org/jira/browse/CALCITE-6714
>             Project: Calcite
>          Issue Type: Bug
>            Reporter: Aleksey Plekhanov
>            Assignee: Aleksey Plekhanov
>            Priority: Major
>
> Expression:
> {noformat}
> cast(cast(1 as integer) as interval minute)
> {noformat}
> Returns 17 minutes instead of 1 minute.



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

Reply via email to