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

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

vvysotskyi commented on pull request #2006: DRILL-7615: UNION ALL query returns 
the wrong result for the decimal value
URL: https://github.com/apache/drill/pull/2006#discussion_r388156185
 
 

 ##########
 File path: 
exec/java-exec/src/test/java/org/apache/drill/exec/store/parquet/TestVarlenDecimal.java
 ##########
 @@ -139,8 +145,32 @@ public void testWriteReadCsv() throws Exception {
           .baselineValues(new BigDecimal(bigDecimalValue))
           .go();
     } finally {
-      resetSessionOption(ExecConstants.OUTPUT_FORMAT_OPTION);
-      test("drop table if exists dfs.tmp.%s", tableName);
+      client.resetSession(ExecConstants.OUTPUT_FORMAT_OPTION);
+      run("drop table if exists dfs.tmp.%s", tableName);
+    }
+  }
+
+  @Test
+  public void testUnionAllWithDifferentScales() throws Exception {
+    try {
+      run("create table dfs.tmp.t as select cast(999999999999999 as 
decimal(15,0)) as d");
+
+      String query = "select cast(1000 as decimal(10,1)) as d\n" +
+          "union all \n" +
+          "select 596.000 as d \n" +
+          "union all \n" +
+          "select d from dfs.tmp.t";
+
+      testBuilder()
+          .sqlQuery(query)
+          .unOrdered()
+          .baselineColumns("d")
+          .baselineValues(new BigDecimal("1000.000"))
+          .baselineValues(new BigDecimal("596.000"))
+          .baselineValues(new BigDecimal("999999999999999.000"))
 
 Review comment:
   @arina-ielchiieva, thanks for pointing to the example, initially I tried a 
similar approach, but union operator returns multiple batches, so in the case 
of using `client.queryBuilder().sql(sql).rowSet()`, it will fail with 
(`IllegalStateException`)[https://github.com/apache/drill/blob/09b805aea4dafe50555b23945302cf8f6c491de8/exec/java-exec/src/test/java/org/apache/drill/test/QueryBuilder.java#L359].
 I also tried to use `rowSetIterator()`, as it was advised in the error 
message, but it returns `QueryRowSetIterator` which actually caused 
complications for me. I tried several approaches, one of them is iterating 
through it and comparing separate row sets, which corresponds to returned 
batches, but such a check would look obscure since the first batch was empty.
   So I ended up with the simpler check for schema using `testBuilder()`.
 
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
[email protected]


> UNION ALL query returns the wrong result for the decimal value
> --------------------------------------------------------------
>
>                 Key: DRILL-7615
>                 URL: https://issues.apache.org/jira/browse/DRILL-7615
>             Project: Apache Drill
>          Issue Type: Bug
>    Affects Versions: 1.14.0
>            Reporter: Vova Vysotskyi
>            Assignee: Vova Vysotskyi
>            Priority: Major
>              Labels: ready-to-commit
>             Fix For: 1.18.0
>
>
> The following query:
> {code:java}
> select cast(1000 as decimal(10,1)) 
> union all 
> select 596.000 
> {code}
> returns incorrect result:
> {code:java}
> 10.000
> 596.000
> {code}
> The expected result is 1000.000 for the first record.



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

Reply via email to