drill-issues mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "ASF GitHub Bot (JIRA)" <j...@apache.org>
Subject [jira] [Commented] (DRILL-4970) Wrong results when casting double to bigint or int
Date Mon, 03 Jul 2017 17:28:00 GMT

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

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_r125332767
  
    --- Diff: exec/java-exec/src/test/java/org/apache/drill/exec/fn/impl/TestCastFunctions.java
---
    @@ -78,4 +81,71 @@ public void testToDateForTimeStamp() throws Exception {
             .build()
             .run();
       }
    +
    +  @Test // DRILL-4970
    +  public void testCastNegativeFloatToInt() throws Exception {
    +    try {
    +      test("create table dfs_test.tmp.table_with_float as\n" +
    +              "(select cast(-255.0 as double) as double_col,\n" +
    +                      "cast(-255.0 as float) as float_col\n" +
    +              "from (values(1)))");
    +
    +      final List<String> columnNames = Lists.newArrayList();
    +      columnNames.add("float_col");
    +      columnNames.add("double_col");
    +
    +      final List<String> castTypes = Lists.newArrayList();
    +      castTypes.add("int");
    +      castTypes.add("bigInt");
    +
    +      final String query = "select count(*) as c from dfs_test.tmp.table_with_float\n"
+
    +                            "where (cast(%1$s as %2$s) >= -255 and (%1$s <= -5))
or (%1$s <= -256)";
    +
    +      for (String columnName : columnNames) {
    +        for (String castType : castTypes) {
    +          testBuilder()
    +            .sqlQuery(query, columnName, castType)
    +            .unOrdered()
    +            .baselineColumns("c")
    +            .baselineValues(1L)
    +            .build()
    +            .run();
    +        }
    +      }
    +    } finally {
    +      test("drop table if exists dfs_test.tmp.table_with_float");
    +    }
    +  }
    +
    +  @Test // DRILL-4970
    +  public void testCastNegativeDecimalToVarChar() throws Exception {
    --- End diff --
    
    The value of input holder was changing only for types that was tested. Cast function makes
only explicit cast of the value for most of the types, so this bug couldn't appear for this
types.


> 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)

Mime
View raw message