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

Julian Hyde commented on CALCITE-4531:
--------------------------------------

The method is not documented, but people would reasonably surmise that it has 
the same behavior as 
[Number.intValue|https://docs.oracle.com/javase/8/docs/api/java/lang/Number.html#intValue--],
 and they'd be right.

There are 34 uses of the method in Calcite. I looked at a few, and they seemed 
to be valid. For example, the 2 uses in {{CassandraLimit.implement}} reference 
the {{offset}} and {{fetch}} fields, which if they are literals are always 
literals of type {{INTEGER}}.

[~vladimirsitnikov], Which uses of this method do you think are incorrect? 
(Which is different than not provably correct.)

If there's a problem with {{RexLiteral.intValue}} then there are also problems 
with {{RexLiteral.getValueAs(Class)}} for values of class including 
{{Long.class}}, {{Integer.class}}, {{Short.class}}, {{Byte.class}}, 
{{Double.class}}, {{Float.class}}. But frankly, I don't think there is.

> Deprecate RexLiteral#intValue since it performs silent truncation
> -----------------------------------------------------------------
>
>                 Key: CALCITE-4531
>                 URL: https://issues.apache.org/jira/browse/CALCITE-4531
>             Project: Calcite
>          Issue Type: Improvement
>          Components: core
>            Reporter: Vladimir Sitnikov
>            Priority: Critical
>
> {{RexLiteral#intValue}} is prone to errors since it silently truncates values 
> to {{int}} so the developers might fail to know that at the compile time.
> It might be safer to expose {{BigDecimal}} or {{intValueExact}} or 
> {{doubleValue}} alternatives which would be "enough for all the possible 
> cases".
> An alternative option is to mark the method as deprecated, so every use of 
> the method would require users to suppress the warning, so they know why the 
> method is deprecated.
> I guess the most common use case for {{RexLiteral.intValue}} is {{offset}} 
> and {{fetch}} in {{Sort}}, however, the misuse is hard to spot, and it might 
> result in hard to notice data corruptions.



--
This message was sent by Atlassian Jira
(v8.3.4#803005)

Reply via email to