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

ASF GitHub Bot commented on DRILL-4970:
---------------------------------------

Github user vvysotskyi commented on a diff in the pull request:

    https://github.com/apache/drill/pull/863#discussion_r125331522
  
    --- Diff: exec/java-exec/src/main/codegen/templates/CastFunctions.java ---
    @@ -54,14 +56,14 @@ public void setup() {}
       public void eval() {
         <#if (type.from.startsWith("Float") && type.to.endsWith("Int"))>
         boolean sign = (in.value < 0);
    -    in.value = java.lang.Math.abs(in.value);
    -    ${type.native} fractional = in.value % 1;
    +    ${type.native} value = java.lang.Math.abs(in.value);
    +    ${type.native} fractional = value % 1;
    --- End diff --
    
    Thanks for the pointing this. Drill uses `half away from zero` rounding 
mode, so method `Math.round()` wouldn't help. I rewrote current code and now it 
handles boundary cases in the same way as the `Math.round()`.


> Wrong results when casting double to bigint or int
> --------------------------------------------------
>
>                 Key: DRILL-4970
>                 URL: https://issues.apache.org/jira/browse/DRILL-4970
>             Project: Apache Drill
>          Issue Type: Bug
>          Components: Execution - Data Types
>    Affects Versions: 1.8.0
>            Reporter: Robert Hou
>            Assignee: Volodymyr Vysotskyi
>         Attachments: test_table
>
>
> This query returns the wrong result
> {code:sql}
> 0: jdbc:drill:zk=10.10.100.186:5181/drill/rho> select count(\*) from 
> test_table where (int_id > -3025 and bigint_id <= -256) or (cast(double_id as 
> bigint) >= -255 and double_id <= -5);
> +---------+
> | EXPR$0  |
> +---------+
> | 2769    |
> +---------+
> {code}
> Without the cast, it returns the correct result:
> {code:sql}
> 0: jdbc:drill:zk=10.10.100.186:5181/drill/rho> select count(\*) from 
> test_table where (int_id > -3025 and bigint_id <= -256) or (double_id >= -255 
> and double_id <= -5);
> +---------+
> | EXPR$0  |
> +---------+
> | 3020    |
> +---------+
> {code}
> By itself, the result is also correct:
> {code:sql}
> 0: jdbc:drill:zk=10.10.100.186:5181/drill/rho> select count(\*) from 
> test_table where (cast(double_id as bigint) >= -255 and double_id <= -5);
> +---------+
> | EXPR$0  |
> +---------+
> | 251     |
> +---------+
> {code}



--
This message was sent by Atlassian JIRA
(v6.4.14#64029)

Reply via email to