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

Vladimir Sitnikov commented on CALCITE-4531:
--------------------------------------------

One more sample: "wrong data from SQL with LIMIT exceeding 2^31-1":

{code:sql}  @Test void testLimitStar2() {
    CalciteAssert.hr()
        .query("select * from \"hr\".\"emps\"\n"
            + "limit " + (1L << 40))
        .returns(""
            + "empid=100; deptno=10; name=Bill; salary=10000.0; 
commission=1000\n"
            + "empid=200; deptno=20; name=Eric; salary=8000.0; commission=500\n"
            + "empid=150; deptno=10; name=Sebastian; salary=7000.0; 
commission=null\n"
            + "empid=110; deptno=10; name=Theodore; salary=11500.0; 
commission=250\n");
  }{code}

Output:

{noformat}
Expected: is "empid=100; deptno=10; name=Bill; salary=10000.0; 
commission=1000\nempid=200; deptno=20; name=Eric; salary=8000.0; 
commission=500\nempid=150; deptno=10; name=Sebastian; salary=7000.0; 
commission=null\nempid=110; deptno=10; name=Theodore; salary=11500.0; 
commission=250\n"
     but: was ""
{noformat}

In other words, Calcite silently produces wrong (empty) results.

> 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