You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@impala.apache.org by ta...@apache.org on 2018/01/25 21:46:42 UTC

[3/6] impala git commit: IMPALA-4924: Enable Decimal V2 by default

IMPALA-4924: Enable Decimal V2 by default

In this commit we enable Decimal_V2 by default. We also update the
expected results in many of our tests.

Testing:
Ran an exhaustive test which almost passed. Updated the few failed
tests in it.

Cherry-pick: not for 2.x

Change-Id: Ibbdd05bf986b7947f106b396017faa3a0bd87fd7
Reviewed-on: http://gerrit.cloudera.org:8080/9062
Reviewed-by: Taras Bobrovytsky <tb...@cloudera.com>
Tested-by: Impala Public Jenkins


Project: http://git-wip-us.apache.org/repos/asf/impala/repo
Commit: http://git-wip-us.apache.org/repos/asf/impala/commit/0a1d586d
Tree: http://git-wip-us.apache.org/repos/asf/impala/tree/0a1d586d
Diff: http://git-wip-us.apache.org/repos/asf/impala/diff/0a1d586d

Branch: refs/heads/master
Commit: 0a1d586d2a2822ad9b4052fef91b1d147b9b4e2b
Parents: 1fc40f4
Author: Taras Bobrovytsky <tb...@cloudera.com>
Authored: Fri Jan 12 14:05:08 2018 -0800
Committer: Impala Public Jenkins <im...@gerrit.cloudera.org>
Committed: Thu Jan 25 04:33:11 2018 +0000

----------------------------------------------------------------------
 be/src/exprs/expr-test.cc                       | 79 +++++++++++++++++++-
 common/thrift/ImpalaInternalService.thrift      |  2 +-
 .../impala/analysis/AnalyzeExprsTest.java       | 64 ++++++++++------
 .../impala/analysis/AnalyzeStmtsTest.java       |  2 +-
 .../queries/QueryTest/decimal_avro.test         | 18 ++---
 .../queries/QueryTest/exprs.test                | 13 ++--
 .../queries/QueryTest/nested-types-subplan.test | 72 +++++++++---------
 .../queries/QueryTest/spilling-aggs.test        | 16 ++--
 .../functional-query/queries/QueryTest/uda.test | 30 ++++----
 .../queries/QueryTest/values.test               |  8 +-
 testdata/workloads/tpch/queries/tpch-q1.test    |  8 +-
 testdata/workloads/tpch/queries/tpch-q14.test   |  2 +-
 testdata/workloads/tpch/queries/tpch-q17.test   |  2 +-
 testdata/workloads/tpch/queries/tpch-q8.test    |  4 +-
 .../tpch_nested/queries/tpch_nested-q1.test     | 10 +--
 .../tpch_nested/queries/tpch_nested-q14.test    |  4 +-
 .../tpch_nested/queries/tpch_nested-q17.test    |  4 +-
 .../tpch_nested/queries/tpch_nested-q8.test     |  6 +-
 tests/hs2/test_hs2.py                           |  5 +-
 tests/query_test/test_aggregation.py            |  8 +-
 tests/query_test/test_decimal_casting.py        | 12 +--
 tests/query_test/test_mem_usage_scaling.py      |  3 +-
 tests/query_test/test_tpcds_queries.py          |  2 +-
 23 files changed, 235 insertions(+), 139 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/impala/blob/0a1d586d/be/src/exprs/expr-test.cc
----------------------------------------------------------------------
diff --git a/be/src/exprs/expr-test.cc b/be/src/exprs/expr-test.cc
index c6e81f1..877127d 100644
--- a/be/src/exprs/expr-test.cc
+++ b/be/src/exprs/expr-test.cc
@@ -5093,7 +5093,8 @@ TEST_F(ExprTest, MathFunctions) {
   TestValue("cast(-12345.345 as float) % cast(-7 as float)",
       TYPE_FLOAT, fmodf(-12345.345f, -7.0f));
   TestValue("cast(12345.345 as double) % 7", TYPE_DOUBLE, fmod(12345.345, 7.0));
-  TestValue("-12345.345 % cast(7 as double)", TYPE_DOUBLE, fmod(-12345.345, 7.0));
+  TestValue("cast(-12345.345 as double) % cast(7 as double)",
+      TYPE_DOUBLE, fmod(-12345.345, 7.0));
   TestValue("cast(-12345.345 as double) % -7", TYPE_DOUBLE, fmod(-12345.345, -7.0));
   // Test floating-point modulo by zero.
   TestIsNull("fmod(cast(-12345.345 as float), cast(0 as float))", TYPE_FLOAT);
@@ -7693,7 +7694,9 @@ TEST_F(ExprTest, DecimalFunctions) {
 
 // Sanity check some overflow casting. We have a random test framework that covers
 // this more thoroughly.
-TEST_F(ExprTest, DecimalOverflowCasts) {
+TEST_F(ExprTest, DecimalOverflowCastsDecimalV1) {
+  executor_->PushExecOption("DECIMAL_V2=0");
+
   TestDecimalValue("cast(123.456 as decimal(6,3))",
       Decimal4Value(123456), ColumnType::CreateDecimalType(6, 3));
   TestDecimalValue("cast(-123.456 as decimal(6,1))",
@@ -7762,6 +7765,78 @@ TEST_F(ExprTest, DecimalOverflowCasts) {
   // Tests converting a non-trivial empty string to a decimal (IMPALA-1566).
   TestIsNull("cast(regexp_replace('','a','b') as decimal(15,2))",
       ColumnType::CreateDecimalType(15,2));
+
+  executor_->PopExecOption();
+}
+
+TEST_F(ExprTest, DecimalOverflowCastsDecimalV2) {
+  executor_->PushExecOption("DECIMAL_V2=1");
+
+  TestDecimalValue("cast(123.456 as decimal(6,3))",
+      Decimal4Value(123456), ColumnType::CreateDecimalType(6, 3));
+  TestDecimalValue("cast(-123.456 as decimal(6,1))",
+      Decimal4Value(-1235), ColumnType::CreateDecimalType(6, 1));
+  TestDecimalValue("cast(123.456 as decimal(6,0))",
+      Decimal4Value(123), ColumnType::CreateDecimalType(6, 0));
+  TestDecimalValue("cast(-123.456 as decimal(3,0))",
+      Decimal4Value(-123), ColumnType::CreateDecimalType(3, 0));
+
+  TestDecimalValue("cast(123.4567890 as decimal(10,7))",
+      Decimal8Value(1234567890L), ColumnType::CreateDecimalType(10, 7));
+
+  TestDecimalValue("cast(cast(\"123.01234567890123456789\" as decimal(23,20))\
+      as decimal(12,9))", Decimal8Value(123012345679L),
+      ColumnType::CreateDecimalType(12, 9));
+  TestDecimalValue("cast(cast(\"123.01234567890123456789\" as decimal(23,20))\
+      as decimal(4,1))", Decimal4Value(1230), ColumnType::CreateDecimalType(4, 1));
+
+  TestDecimalValue("cast(cast(\"123.0123456789\" as decimal(13,10))\
+      as decimal(5,2))", Decimal4Value(12301), ColumnType::CreateDecimalType(5, 2));
+
+  // Overflow
+  TestError("cast(123.456 as decimal(2,0))");
+  TestError("cast(123.456 as decimal(2,1))");
+  TestError("cast(123.456 as decimal(2,2))");
+  TestError("cast(99.99 as decimal(2,2))");
+  TestError("cast(99.99 as decimal(2,0))");
+  TestError("cast(-99.99 as decimal(2,2))");
+  TestError("cast(-99.99 as decimal(3,1))");
+
+  TestDecimalValue("cast(999.99 as decimal(6,3))",
+      Decimal4Value(999990), ColumnType::CreateDecimalType(6, 3));
+  TestDecimalValue("cast(-999.99 as decimal(7,4))",
+      Decimal4Value(-9999900), ColumnType::CreateDecimalType(7, 4));
+  TestError("cast(9990.99 as decimal(6,3))");
+  TestError("cast(-9990.99 as decimal(7,4))");
+
+  TestDecimalValue("cast(123.4567890 as decimal(4, 1))",
+      Decimal4Value(1235), ColumnType::CreateDecimalType(4, 1));
+  TestDecimalValue("cast(-123.4567890 as decimal(5, 2))",
+      Decimal4Value(-12346), ColumnType::CreateDecimalType(5, 2));
+  TestError("cast(123.4567890 as decimal(2, 1))");
+  TestError("cast(123.4567890 as decimal(6, 5))");
+
+  TestDecimalValue("cast(pi() as decimal(1, 0))",
+      Decimal4Value(3), ColumnType::CreateDecimalType(1,0));
+  TestDecimalValue("cast(pi() as decimal(4, 1))",
+      Decimal4Value(31), ColumnType::CreateDecimalType(4,1));
+  TestDecimalValue("cast(pi() as decimal(30, 1))",
+      Decimal8Value(31), ColumnType::CreateDecimalType(30,1));
+  TestError("cast(pi() as decimal(4, 4))");
+  TestError("cast(pi() as decimal(11, 11))");
+  TestError("cast(pi() as decimal(31, 31))");
+
+  TestError("cast(140573315541874605.4665184383287 as decimal(17, 13))");
+  TestError("cast(140573315541874605.4665184383287 as decimal(9, 3))");
+
+  // value has 30 digits before the decimal, casting to 29 is an overflow.
+  TestError("cast(99999999999999999999999999999.9 as decimal(29, 1))");
+
+  // Tests converting a non-trivial empty string to a decimal (IMPALA-1566).
+  TestIsNull("cast(regexp_replace('','a','b') as decimal(15,2))",
+      ColumnType::CreateDecimalType(15,2));
+
+  executor_->PopExecOption();
 }
 
 TEST_F(ExprTest, NullValueFunction) {

http://git-wip-us.apache.org/repos/asf/impala/blob/0a1d586d/common/thrift/ImpalaInternalService.thrift
----------------------------------------------------------------------
diff --git a/common/thrift/ImpalaInternalService.thrift b/common/thrift/ImpalaInternalService.thrift
index 121c551..9494f6b 100644
--- a/common/thrift/ImpalaInternalService.thrift
+++ b/common/thrift/ImpalaInternalService.thrift
@@ -247,7 +247,7 @@ struct TQueryOptions {
   51: optional bool enable_expr_rewrites = true
 
   // Indicates whether to use the new decimal semantics.
-  52: optional bool decimal_v2 = false
+  52: optional bool decimal_v2 = true
 
   // Indicates whether to use dictionary filtering for Parquet files
   53: optional bool parquet_dictionary_filtering = true

http://git-wip-us.apache.org/repos/asf/impala/blob/0a1d586d/fe/src/test/java/org/apache/impala/analysis/AnalyzeExprsTest.java
----------------------------------------------------------------------
diff --git a/fe/src/test/java/org/apache/impala/analysis/AnalyzeExprsTest.java b/fe/src/test/java/org/apache/impala/analysis/AnalyzeExprsTest.java
index 91d1c00..80ba630 100644
--- a/fe/src/test/java/org/apache/impala/analysis/AnalyzeExprsTest.java
+++ b/fe/src/test/java/org/apache/impala/analysis/AnalyzeExprsTest.java
@@ -2210,14 +2210,34 @@ public class AnalyzeExprsTest extends AnalyzerTest {
     testFuncExprDepthLimit("cast(", "1", " as int)");
   }
 
-  // Verifies the resulting expr decimal type is exptectedType
-  private void testDecimalExpr(String expr, Type expectedType) {
-    SelectStmt selectStmt = (SelectStmt) AnalyzesOk("select " + expr);
+  // Verifies the resulting expr decimal type is expectedType under decimal v1 and
+  // decimal v2.
+  private void testDecimalExpr(String expr,
+      Type decimalV1ExpectedType, Type decimalV2ExpectedType) {
+    Analyzer analyzer = createAnalyzer(Catalog.DEFAULT_DB);
+
+    analyzer.getQueryOptions().setDecimal_v2(false);
+    SelectStmt selectStmt = (SelectStmt) AnalyzesOk("select " + expr, analyzer);
     Expr root = selectStmt.resultExprs_.get(0);
     Type actualType = root.getType();
     Assert.assertTrue(
-        "Expr: " + expr + " Expected: " + expectedType + " Actual: " + actualType,
-        expectedType.equals(actualType));
+        "Expr: " + expr + " Decimal Version: 1" +
+        " Expected: " + decimalV1ExpectedType + " Actual: " + actualType,
+        decimalV1ExpectedType.equals(actualType));
+
+    analyzer.getQueryOptions().setDecimal_v2(true);
+    selectStmt = (SelectStmt) AnalyzesOk("select " + expr, analyzer);
+    root = selectStmt.resultExprs_.get(0);
+    actualType = root.getType();
+    Assert.assertTrue(
+        "Expr: " + expr + " Decimal Version: 2" +
+            " Expected: " + decimalV2ExpectedType + " Actual: " + actualType,
+        decimalV2ExpectedType.equals(actualType));
+  }
+
+  // Verifies the resulting expr decimal type is exptectedType
+  private void testDecimalExpr(String expr, Type expectedType) {
+    testDecimalExpr(expr, expectedType, expectedType);
   }
 
   @Test
@@ -2236,7 +2256,7 @@ public class AnalyzeExprsTest extends AnalyzerTest {
     testDecimalExpr(decimal_10_0 + " - " + decimal_10_0,
         ScalarType.createDecimalType(11, 0));
     testDecimalExpr(decimal_10_0 + " * " + decimal_10_0,
-        ScalarType.createDecimalType(20, 0));
+        ScalarType.createDecimalType(20, 0), ScalarType.createDecimalType(21, 0));
     testDecimalExpr(decimal_10_0 + " / " + decimal_10_0,
         ScalarType.createDecimalType(21, 11));
     testDecimalExpr(decimal_10_0 + " % " + decimal_10_0,
@@ -2247,7 +2267,7 @@ public class AnalyzeExprsTest extends AnalyzerTest {
     testDecimalExpr(decimal_10_0 + " - " + decimal_5_5,
         ScalarType.createDecimalType(16, 5));
     testDecimalExpr(decimal_10_0 + " * " + decimal_5_5,
-        ScalarType.createDecimalType(15, 5));
+        ScalarType.createDecimalType(15, 5), ScalarType.createDecimalType(16, 5));
     testDecimalExpr(decimal_10_0 + " / " + decimal_5_5,
         ScalarType.createDecimalType(21, 6));
     testDecimalExpr(decimal_10_0 + " % " + decimal_5_5,
@@ -2258,7 +2278,7 @@ public class AnalyzeExprsTest extends AnalyzerTest {
     testDecimalExpr(decimal_5_5 + " - " + decimal_10_0,
         ScalarType.createDecimalType(16, 5));
     testDecimalExpr(decimal_5_5 + " * " + decimal_10_0,
-        ScalarType.createDecimalType(15, 5));
+        ScalarType.createDecimalType(15, 5), ScalarType.createDecimalType(16, 5));
     testDecimalExpr(decimal_5_5 + " / " + decimal_10_0,
         ScalarType.createDecimalType(16, 16));
     testDecimalExpr(decimal_5_5 + " % " + decimal_10_0,
@@ -2266,31 +2286,31 @@ public class AnalyzeExprsTest extends AnalyzerTest {
 
     // Test some overflow cases.
     testDecimalExpr(decimal_10_0 + " + " + decimal_38_34,
-        ScalarType.createDecimalType(38, 34));
+        ScalarType.createDecimalType(38, 34), ScalarType.createDecimalType(38, 27));
     testDecimalExpr(decimal_10_0 + " - " + decimal_38_34,
-        ScalarType.createDecimalType(38, 34));
+        ScalarType.createDecimalType(38, 34), ScalarType.createDecimalType(38, 27));
     testDecimalExpr(decimal_10_0 + " * " + decimal_38_34,
-        ScalarType.createDecimalType(38, 34));
+        ScalarType.createDecimalType(38, 34), ScalarType.createDecimalType(38, 23));
     testDecimalExpr(decimal_10_0 + " / " + decimal_38_34,
-        ScalarType.createDecimalType(38, 34));
+        ScalarType.createDecimalType(38, 34), ScalarType.createDecimalType(38, 6));
     testDecimalExpr(decimal_10_0 + " % " + decimal_38_34,
         ScalarType.createDecimalType(38, 34));
 
     testDecimalExpr(decimal_38_34 + " + " + decimal_5_5,
-        ScalarType.createDecimalType(38, 34));
+        ScalarType.createDecimalType(38, 34), ScalarType.createDecimalType(38, 33));
     testDecimalExpr(decimal_38_34 + " - " + decimal_5_5,
-        ScalarType.createDecimalType(38, 34));
+        ScalarType.createDecimalType(38, 34), ScalarType.createDecimalType(38, 33));
     testDecimalExpr(decimal_38_34 + " * " + decimal_5_5,
-        ScalarType.createDecimalType(38, 38));
+        ScalarType.createDecimalType(38, 38), ScalarType.createDecimalType(38, 33));
     testDecimalExpr(decimal_38_34 + " / " + decimal_5_5,
-        ScalarType.createDecimalType(38, 34));
+        ScalarType.createDecimalType(38, 34), ScalarType.createDecimalType(38, 29));
     testDecimalExpr(decimal_38_34 + " % " + decimal_5_5,
         ScalarType.createDecimalType(34, 34));
 
     testDecimalExpr(decimal_10_0 + " + " + decimal_10_0 + " + " + decimal_10_0,
         ScalarType.createDecimalType(12, 0));
     testDecimalExpr(decimal_10_0 + " - " + decimal_10_0 + " * " + decimal_10_0,
-        ScalarType.createDecimalType(21, 0));
+        ScalarType.createDecimalType(21, 0), ScalarType.createDecimalType(22, 0));
     testDecimalExpr(decimal_10_0 + " / " + decimal_10_0 + " / " + decimal_10_0,
         ScalarType.createDecimalType(32, 22));
     testDecimalExpr(decimal_10_0 + " % " + decimal_10_0 + " + " + decimal_10_0,
@@ -2307,22 +2327,22 @@ public class AnalyzeExprsTest extends AnalyzerTest {
     testDecimalExpr(decimal_10_0 + " + cast(1 as bigint)",
         ScalarType.createDecimalType(20, 0));
     testDecimalExpr(decimal_10_0 + " + cast(1 as float)",
-        ScalarType.createDecimalType(38, 9));
+        ScalarType.createDecimalType(38, 9), ScalarType.createDecimalType(38, 8));
     testDecimalExpr(decimal_10_0 + " + cast(1 as double)",
-        ScalarType.createDecimalType(38, 17));
+        ScalarType.createDecimalType(38, 17), ScalarType.createDecimalType(38, 16));
 
     testDecimalExpr(decimal_5_5 + " + cast(1 as tinyint)",
         ScalarType.createDecimalType(9, 5));
     testDecimalExpr(decimal_5_5 + " - cast(1 as smallint)",
         ScalarType.createDecimalType(11, 5));
     testDecimalExpr(decimal_5_5 + " * cast(1 as int)",
-        ScalarType.createDecimalType(15, 5));
+        ScalarType.createDecimalType(15, 5), ScalarType.createDecimalType(16, 5));
     testDecimalExpr(decimal_5_5 + " % cast(1 as bigint)",
         ScalarType.createDecimalType(5, 5));
     testDecimalExpr(decimal_5_5 + " / cast(1 as float)",
-        ScalarType.createDecimalType(38, 9));
+        ScalarType.createDecimalType(38, 9), ScalarType.createDecimalType(38, 29));
     testDecimalExpr(decimal_5_5 + " + cast(1 as double)",
-        ScalarType.createDecimalType(38, 17));
+        ScalarType.createDecimalType(38, 17), ScalarType.createDecimalType(38, 16));
 
     AnalyzesOk("select " + decimal_5_5 + " = cast(1 as tinyint)");
     AnalyzesOk("select " + decimal_5_5 + " != cast(1 as smallint)");

http://git-wip-us.apache.org/repos/asf/impala/blob/0a1d586d/fe/src/test/java/org/apache/impala/analysis/AnalyzeStmtsTest.java
----------------------------------------------------------------------
diff --git a/fe/src/test/java/org/apache/impala/analysis/AnalyzeStmtsTest.java b/fe/src/test/java/org/apache/impala/analysis/AnalyzeStmtsTest.java
index 1d8d1be..d3311ba 100644
--- a/fe/src/test/java/org/apache/impala/analysis/AnalyzeStmtsTest.java
+++ b/fe/src/test/java/org/apache/impala/analysis/AnalyzeStmtsTest.java
@@ -2333,7 +2333,7 @@ public class AnalyzeStmtsTest extends AnalyzerTest {
     AnalysisError("select count(*) from functional.alltypes " +
         "group by bool_col having 5 + 10 * 5.6",
         "HAVING clause '5 + 10 * 5.6' requires return type 'BOOLEAN'. " +
-        "Actual type is 'DOUBLE'.");
+        "Actual type is 'DECIMAL(7,1)'.");
     AnalysisError("select count(*) from functional.alltypes " +
         "group by bool_col having int_col",
         "HAVING clause 'int_col' requires return type 'BOOLEAN'. Actual type is 'INT'.");

http://git-wip-us.apache.org/repos/asf/impala/blob/0a1d586d/testdata/workloads/functional-query/queries/QueryTest/decimal_avro.test
----------------------------------------------------------------------
diff --git a/testdata/workloads/functional-query/queries/QueryTest/decimal_avro.test b/testdata/workloads/functional-query/queries/QueryTest/decimal_avro.test
index 73fd27d..19fddcb 100644
--- a/testdata/workloads/functional-query/queries/QueryTest/decimal_avro.test
+++ b/testdata/workloads/functional-query/queries/QueryTest/decimal_avro.test
@@ -43,13 +43,13 @@ select l_shipmode, count(distinct l_quantity), avg(l_extendedprice), max(l_disco
 from tpch_avro_snap.lineitem
 group by l_shipmode
 ---- RESULTS
-'SHIP',50,38267.37,0.10,9
-'REG AIR',50,38268.41,0.10,9
-'TRUCK',50,38209.82,0.10,9
-'RAIL',50,38269.81,0.10,9
-'FOB',50,38246.23,0.10,9
-'MAIL',50,38224.29,0.10,9
-'AIR',50,38299.98,0.10,9
-----TYPES
+'SHIP',50,38267.370378,0.10,9
+'REG AIR',50,38268.410670,0.10,9
+'RAIL',50,38269.811059,0.10,9
+'MAIL',50,38224.291934,0.10,9
+'AIR',50,38299.981696,0.10,9
+'TRUCK',50,38209.826048,0.10,9
+'FOB',50,38246.233625,0.10,9
+---- TYPES
 STRING,DECIMAL,DECIMAL,DECIMAL,DECIMAL
-====
+====
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/impala/blob/0a1d586d/testdata/workloads/functional-query/queries/QueryTest/exprs.test
----------------------------------------------------------------------
diff --git a/testdata/workloads/functional-query/queries/QueryTest/exprs.test b/testdata/workloads/functional-query/queries/QueryTest/exprs.test
index 50ee288..1cb803b 100644
--- a/testdata/workloads/functional-query/queries/QueryTest/exprs.test
+++ b/testdata/workloads/functional-query/queries/QueryTest/exprs.test
@@ -72,7 +72,6 @@ bigint
 ====
 ---- QUERY
 # boolean test: IS [NOT] (TRUE | FALSE | UNKNOWN)
----- QUERY
 select count(*) from alltypesagg where (int_col < 100) is unknown;
 ---- RESULTS
 20
@@ -1879,9 +1878,9 @@ string
 ---- QUERY
 select 1.1 * 1.1 + cast(1.1 as float)
 ---- RESULTS
-2.310000023841858
+2.31000002
 ---- TYPES
-double
+DECIMAL
 ====
 ---- QUERY
 select 1.1 * 1.1 + cast(1.1 as decimal(2,1))
@@ -1900,10 +1899,10 @@ decimal
 ---- QUERY
 select 1.1 * 1.1 + float_col from functional.alltypestiny limit 2;
 ---- RESULTS
-1.21
-2.310000023841858
+1.21000000
+2.31000002
 ---- TYPES
-double
+DECIMAL
 ====
 ---- QUERY
 select 1.1 * 1.1 + c3 from functional.decimal_tiny limit 2;
@@ -2236,7 +2235,7 @@ select tmp.str from (values
 ('multi\nfield\ntwo')) as tmp
 where regexp_like(tmp.str, '^multi.*$')
 ---- RESULTS
-----TYPES
+---- TYPES
 string
 ====
 ---- QUERY

http://git-wip-us.apache.org/repos/asf/impala/blob/0a1d586d/testdata/workloads/functional-query/queries/QueryTest/nested-types-subplan.test
----------------------------------------------------------------------
diff --git a/testdata/workloads/functional-query/queries/QueryTest/nested-types-subplan.test b/testdata/workloads/functional-query/queries/QueryTest/nested-types-subplan.test
index 82930ad..2f10072 100644
--- a/testdata/workloads/functional-query/queries/QueryTest/nested-types-subplan.test
+++ b/testdata/workloads/functional-query/queries/QueryTest/nested-types-subplan.test
@@ -145,9 +145,9 @@ select c_custkey, v.* from customer c,
    from c.c_orders) v
 where c_custkey < 4
 ---- RESULTS
-1,6,587762.91,97960.48,'O','1992-04-19'
-2,7,1028273.43,146896.20,'P','1992-04-05'
+1,6,587762.91,97960.485000,'O','1992-04-19'
 3,0,NULL,NULL,'NULL','NULL'
+2,7,1028273.43,146896.204286,'P','1992-04-05'
 ---- TYPES
 bigint,bigint,decimal,decimal,string,string
 ====
@@ -189,13 +189,13 @@ select c_custkey, v.* from customer c,
    group by o_orderpriority) v
 where c_custkey < 4
 ---- RESULTS
-1,'1-URGENT',2,249248.75,124624.37,'O','1992-04-19'
-1,'2-HIGH',1,65478.05,65478.05,'O','1996-06-29'
-1,'3-MEDIUM',1,95911.01,95911.01,'O','1997-03-23'
-1,'5-LOW',2,177125.10,88562.55,'O','1992-08-22'
-2,'1-URGENT',4,670495.57,167623.89,'O','1992-04-05'
-2,'2-HIGH',1,221397.35,221397.35,'P','1995-03-10'
-2,'4-NOT SPECIFIED',2,136380.51,68190.25,'F','1994-05-21'
+1,'2-HIGH',1,65478.05,65478.050000,'O','1996-06-29'
+1,'5-LOW',2,177125.10,88562.550000,'O','1992-08-22'
+1,'1-URGENT',2,249248.75,124624.375000,'O','1992-04-19'
+1,'3-MEDIUM',1,95911.01,95911.010000,'O','1997-03-23'
+2,'2-HIGH',1,221397.35,221397.350000,'P','1995-03-10'
+2,'4-NOT SPECIFIED',2,136380.51,68190.255000,'F','1994-05-21'
+2,'1-URGENT',4,670495.57,167623.892500,'O','1992-04-05'
 ---- TYPES
 bigint,string,bigint,decimal,decimal,string,string
 ====
@@ -208,19 +208,19 @@ select c_custkey, v.* from customer c,
    from c.c_orders) v
 where c_custkey < 4
 ---- RESULTS
-1,6,587762.91,97960.48,'O','1992-04-19'
-1,6,587762.91,97960.48,'O','1992-04-19'
-1,6,587762.91,97960.48,'O','1992-04-19'
-1,6,587762.91,97960.48,'O','1992-04-19'
-1,6,587762.91,97960.48,'O','1992-04-19'
-1,6,587762.91,97960.48,'O','1992-04-19'
-2,7,1028273.43,146896.20,'P','1992-04-05'
-2,7,1028273.43,146896.20,'P','1992-04-05'
-2,7,1028273.43,146896.20,'P','1992-04-05'
-2,7,1028273.43,146896.20,'P','1992-04-05'
-2,7,1028273.43,146896.20,'P','1992-04-05'
-2,7,1028273.43,146896.20,'P','1992-04-05'
-2,7,1028273.43,146896.20,'P','1992-04-05'
+1,6,587762.91,97960.485000,'O','1992-04-19'
+1,6,587762.91,97960.485000,'O','1992-04-19'
+1,6,587762.91,97960.485000,'O','1992-04-19'
+1,6,587762.91,97960.485000,'O','1992-04-19'
+1,6,587762.91,97960.485000,'O','1992-04-19'
+1,6,587762.91,97960.485000,'O','1992-04-19'
+2,7,1028273.43,146896.204286,'P','1992-04-05'
+2,7,1028273.43,146896.204286,'P','1992-04-05'
+2,7,1028273.43,146896.204286,'P','1992-04-05'
+2,7,1028273.43,146896.204286,'P','1992-04-05'
+2,7,1028273.43,146896.204286,'P','1992-04-05'
+2,7,1028273.43,146896.204286,'P','1992-04-05'
+2,7,1028273.43,146896.204286,'P','1992-04-05'
 ---- TYPES
 bigint,bigint,decimal,decimal,string,string
 ====
@@ -236,19 +236,19 @@ select c_custkey, v.* from customer c,
 from c.c_orders) v
 where c_custkey < 4
 ---- RESULTS
-1,'F',2,197679.65,98839.82,'F','1992-04-19'
-1,'F',2,197679.65,98839.82,'F','1992-04-19'
-1,'O',4,390083.26,97520.81,'O','1996-06-29'
-1,'O',4,390083.26,97520.81,'O','1996-06-29'
-1,'O',4,390083.26,97520.81,'O','1996-06-29'
-1,'O',4,390083.26,97520.81,'O','1996-06-29'
-2,'F',4,319892.45,79973.11,'F','1992-04-05'
-2,'F',4,319892.45,79973.11,'F','1992-04-05'
-2,'F',4,319892.45,79973.11,'F','1992-04-05'
-2,'F',4,319892.45,79973.11,'F','1992-04-05'
-2,'O',2,486983.63,243491.81,'O','1996-08-05'
-2,'O',2,486983.63,243491.81,'O','1996-08-05'
-2,'P',1,221397.35,221397.35,'P','1995-03-10'
+1,'F',2,197679.65,98839.825000,'F','1992-04-19'
+1,'F',2,197679.65,98839.825000,'F','1992-04-19'
+1,'O',4,390083.26,97520.815000,'O','1996-06-29'
+1,'O',4,390083.26,97520.815000,'O','1996-06-29'
+1,'O',4,390083.26,97520.815000,'O','1996-06-29'
+1,'O',4,390083.26,97520.815000,'O','1996-06-29'
+2,'F',4,319892.45,79973.112500,'F','1992-04-05'
+2,'F',4,319892.45,79973.112500,'F','1992-04-05'
+2,'F',4,319892.45,79973.112500,'F','1992-04-05'
+2,'F',4,319892.45,79973.112500,'F','1992-04-05'
+2,'O',2,486983.63,243491.815000,'O','1996-08-05'
+2,'O',2,486983.63,243491.815000,'O','1996-08-05'
+2,'P',1,221397.35,221397.350000,'P','1995-03-10'
 ---- TYPES
 bigint,string,bigint,decimal,decimal,string,string
 ====
@@ -328,7 +328,7 @@ from tpch_nested_parquet.customer c,
 group by opriority
 ---- TYPES
 bigint, string
----- RESULTS:
+---- RESULTS
 ====
 ---- QUERY
 # Test left semi join of a relative table ref.

http://git-wip-us.apache.org/repos/asf/impala/blob/0a1d586d/testdata/workloads/functional-query/queries/QueryTest/spilling-aggs.test
----------------------------------------------------------------------
diff --git a/testdata/workloads/functional-query/queries/QueryTest/spilling-aggs.test b/testdata/workloads/functional-query/queries/QueryTest/spilling-aggs.test
index 05552d2..5a58f62 100644
--- a/testdata/workloads/functional-query/queries/QueryTest/spilling-aggs.test
+++ b/testdata/workloads/functional-query/queries/QueryTest/spilling-aggs.test
@@ -32,9 +32,9 @@ from lineitem
 group by 1,2
 order by 1,2 limit 3
 ---- RESULTS
-'A',3,0.05,'RAIL'
-'A',5,0.03,'AIR'
-'A',6,0.03,'TRUCK'
+'A',3,0.050000,'RAIL'
+'A',5,0.030000,'AIR'
+'A',6,0.030000,'TRUCK'
 ---- TYPES
 STRING, BIGINT, DECIMAL, STRING
 ---- RUNTIME_PROFILE
@@ -194,11 +194,11 @@ limit 5
 ---- TYPES
 BIGINT,DECIMAL,DECIMAL,DECIMAL,DECIMAL
 ---- RESULTS
-3811460,0.05,50.00,0.05,104899.50
-1744195,0.04,50.00,0.09,104649.50
-5151266,0.07,50.00,0.00,104449.50
-4571042,0.03,50.00,0.09,104399.50
-1198304,0.01,50.00,0.02,104299.50
+3811460,0.050000,50.000000,0.050000,104899.500000
+1744195,0.040000,50.000000,0.090000,104649.500000
+5151266,0.070000,50.000000,0.000000,104449.500000
+4571042,0.030000,50.000000,0.090000,104399.500000
+1198304,0.010000,50.000000,0.020000,104299.500000
 ---- RUNTIME_PROFILE
 row_regex: .*SpilledPartitions: .* \([1-9][0-9]*\)
 ====

http://git-wip-us.apache.org/repos/asf/impala/blob/0a1d586d/testdata/workloads/functional-query/queries/QueryTest/uda.test
----------------------------------------------------------------------
diff --git a/testdata/workloads/functional-query/queries/QueryTest/uda.test b/testdata/workloads/functional-query/queries/QueryTest/uda.test
index ef3f1a6..62812e6 100644
--- a/testdata/workloads/functional-query/queries/QueryTest/uda.test
+++ b/testdata/workloads/functional-query/queries/QueryTest/uda.test
@@ -82,10 +82,10 @@ bigint,bigint
 ---- QUERY
 # Test that all types are exposed via the FunctionContext correctly.
 # This relies on asserts in the UDA funciton
-select agg_decimal_intermediate(cast(d1 as decimal(2,1)), 2), count(*)
-from functional.decimal_tbl
+select agg_decimal_intermediate(cast(c3 as decimal(2,1)), 2), count(*)
+from functional.decimal_tiny
 ---- RESULTS
-NULL,5
+NULL,100
 ---- TYPES
 decimal,bigint
 ====
@@ -106,7 +106,7 @@ from
    functional.alltypesagg,
    functional.decimal_tiny
 ---- RESULTS
-100,NULL,NULL,160.49989,-10.0989,11.8989,999,499500
+100,NULL,NULL,160.499890,-10.0989,11.8989,999,499500
 ---- TYPES
 decimal,decimal,bigint,decimal,decimal,decimal,bigint,bigint
 ====
@@ -126,17 +126,17 @@ from
 group by
    year,month,day
 ---- RESULTS
-100,NULL,NULL,99,5.4994
-100,NULL,NULL,99,5.4994
-100,NULL,NULL,99,5.4994
-100,NULL,NULL,99,5.4994
-100,NULL,NULL,99,5.4994
-100,NULL,NULL,99,5.4994
-100,NULL,NULL,99,5.4994
-100,NULL,NULL,99,5.4994
-100,NULL,NULL,99,5.4994
-100,NULL,NULL,99,5.4994
-100,NULL,NULL,99,5.4994
+100,NULL,NULL,99,5.499450
+100,NULL,NULL,99,5.499450
+100,NULL,NULL,99,5.499450
+100,NULL,NULL,99,5.499450
+100,NULL,NULL,99,5.499450
+100,NULL,NULL,99,5.499450
+100,NULL,NULL,99,5.499450
+100,NULL,NULL,99,5.499450
+100,NULL,NULL,99,5.499450
+100,NULL,NULL,99,5.499450
+100,NULL,NULL,99,5.499450
 ---- TYPES
 decimal,decimal,bigint,bigint,decimal
 ====

http://git-wip-us.apache.org/repos/asf/impala/blob/0a1d586d/testdata/workloads/functional-query/queries/QueryTest/values.test
----------------------------------------------------------------------
diff --git a/testdata/workloads/functional-query/queries/QueryTest/values.test b/testdata/workloads/functional-query/queries/QueryTest/values.test
index 8cdf23c..ac33e3d 100644
--- a/testdata/workloads/functional-query/queries/QueryTest/values.test
+++ b/testdata/workloads/functional-query/queries/QueryTest/values.test
@@ -84,10 +84,10 @@ insert overwrite table i_2749 values
 ---- QUERY
 select dbl1 * dec * dbl2, dbl1 + dec, dbl1 - dec, dbl1 / dec from i_2749;
 ---- RESULTS
-0.1547289,90.00170000000000000,-89.99830000000000000,0.00001888888888888
-3.112781400000001,90.03420000000000000,-89.96580000000000000,0.00038000000000000
-1.1650176,90.01280000000000000,-89.98720000000000000,0.00014222222222222
-1.4835771,90.01629999999999999,-89.98370000000000001,0.00018111111111111
+0.1547289,90.0017000000000000,-89.9983000000000000,0.0000188888889
+3.112781400000001,90.0342000000000000,-89.9658000000000000,0.0003800000000
+1.1650176,90.0128000000000000,-89.9872000000000000,0.0001422222222
+1.4835771,90.0163000000000000,-89.9837000000000000,0.0001811111111
 ---- TYPES
 DOUBLE,DECIMAL,DECIMAL,DECIMAL
 ====

http://git-wip-us.apache.org/repos/asf/impala/blob/0a1d586d/testdata/workloads/tpch/queries/tpch-q1.test
----------------------------------------------------------------------
diff --git a/testdata/workloads/tpch/queries/tpch-q1.test b/testdata/workloads/tpch/queries/tpch-q1.test
index 4147efe..08cb7cc 100644
--- a/testdata/workloads/tpch/queries/tpch-q1.test
+++ b/testdata/workloads/tpch/queries/tpch-q1.test
@@ -23,10 +23,10 @@ order by
   l_returnflag,
   l_linestatus
 ---- RESULTS
-'A','F',37734107.00,56586554400.73,53758257134.8700,55909065222.827692,25.52,38273.12,0.04,1478493
-'N','F',991417.00,1487504710.38,1413082168.0541,1469649223.194375,25.51,38284.46,0.05,38854
-'N','O',74476040.00,111701729697.74,106118230307.6056,110367043872.497010,25.50,38249.11,0.04,2920374
-'R','F',37719753.00,56568041380.90,53741292684.6040,55889619119.831932,25.50,38250.85,0.05,1478870
+'A','F',37734107.00,56586554400.73,53758257134.8700,55909065222.827692,25.522006,38273.129735,0.049985,1478493
+'N','F',991417.00,1487504710.38,1413082168.0541,1469649223.194375,25.516472,38284.467761,0.050093,38854
+'N','O',74476040.00,111701729697.74,106118230307.6056,110367043872.497010,25.502227,38249.117989,0.049997,2920374
+'R','F',37719753.00,56568041380.90,53741292684.6040,55889619119.831932,25.505794,38250.854626,0.050009,1478870
 ---- TYPES
 string, string, decimal, decimal, decimal, decimal, decimal, decimal, decimal, bigint
 ====
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/impala/blob/0a1d586d/testdata/workloads/tpch/queries/tpch-q14.test
----------------------------------------------------------------------
diff --git a/testdata/workloads/tpch/queries/tpch-q14.test b/testdata/workloads/tpch/queries/tpch-q14.test
index d84b9bb..8fb41b4 100644
--- a/testdata/workloads/tpch/queries/tpch-q14.test
+++ b/testdata/workloads/tpch/queries/tpch-q14.test
@@ -15,7 +15,7 @@ where
   and l_shipdate >= '1995-09-01'
   and l_shipdate < '1995-10-01'
 ---- RESULTS
-16.380778
+16.380779
 ---- TYPES
 decimal
 ====
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/impala/blob/0a1d586d/testdata/workloads/tpch/queries/tpch-q17.test
----------------------------------------------------------------------
diff --git a/testdata/workloads/tpch/queries/tpch-q17.test b/testdata/workloads/tpch/queries/tpch-q17.test
index e7ccfb4..ab4a62e 100644
--- a/testdata/workloads/tpch/queries/tpch-q17.test
+++ b/testdata/workloads/tpch/queries/tpch-q17.test
@@ -19,7 +19,7 @@ where
       l_partkey = p_partkey
   )
 ---- RESULTS
-348406.05
+348406.054286
 ---- TYPES
 decimal
 ====
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/impala/blob/0a1d586d/testdata/workloads/tpch/queries/tpch-q8.test
----------------------------------------------------------------------
diff --git a/testdata/workloads/tpch/queries/tpch-q8.test b/testdata/workloads/tpch/queries/tpch-q8.test
index 1b7fe8c..01ed843 100644
--- a/testdata/workloads/tpch/queries/tpch-q8.test
+++ b/testdata/workloads/tpch/queries/tpch-q8.test
@@ -39,8 +39,8 @@ group by
 order by
   o_year
 ---- RESULTS
-1995,0.0344
-1996,0.0414
+1995,0.034436
+1996,0.041486
 ---- TYPES
 int, decimal
 ====
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/impala/blob/0a1d586d/testdata/workloads/tpch_nested/queries/tpch_nested-q1.test
----------------------------------------------------------------------
diff --git a/testdata/workloads/tpch_nested/queries/tpch_nested-q1.test b/testdata/workloads/tpch_nested/queries/tpch_nested-q1.test
index e0ff4e9..8077b55 100644
--- a/testdata/workloads/tpch_nested/queries/tpch_nested-q1.test
+++ b/testdata/workloads/tpch_nested/queries/tpch_nested-q1.test
@@ -23,10 +23,10 @@ order by
   l_returnflag,
   l_linestatus
 ---- RESULTS
-'A','F',37734107.00,56586554400.73,53758257134.8700,55909065222.827692,25.52,38273.12,0.04,1478493
-'N','F',991417.00,1487504710.38,1413082168.0541,1469649223.194375,25.51,38284.46,0.05,38854
-'N','O',74476040.00,111701729697.74,106118230307.6056,110367043872.497010,25.50,38249.11,0.04,2920374
-'R','F',37719753.00,56568041380.90,53741292684.6040,55889619119.831932,25.50,38250.85,0.05,1478870
+'A','F',37734107.00,56586554400.73,53758257134.8700,55909065222.827692,25.522006,38273.129735,0.049985,1478493
+'N','F',991417.00,1487504710.38,1413082168.0541,1469649223.194375,25.516472,38284.467761,0.050093,38854
+'N','O',74476040.00,111701729697.74,106118230307.6056,110367043872.497010,25.502227,38249.117989,0.049997,2920374
+'R','F',37719753.00,56568041380.90,53741292684.6040,55889619119.831932,25.505794,38250.854626,0.050009,1478870
 ---- TYPES
 string, string, decimal, decimal, decimal, decimal, decimal, decimal, decimal, bigint
-====
+====
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/impala/blob/0a1d586d/testdata/workloads/tpch_nested/queries/tpch_nested-q14.test
----------------------------------------------------------------------
diff --git a/testdata/workloads/tpch_nested/queries/tpch_nested-q14.test b/testdata/workloads/tpch_nested/queries/tpch_nested-q14.test
index b4c66ff..87abd7e 100644
--- a/testdata/workloads/tpch_nested/queries/tpch_nested-q14.test
+++ b/testdata/workloads/tpch_nested/queries/tpch_nested-q14.test
@@ -15,7 +15,7 @@ where
   and l_shipdate >= '1995-09-01'
   and l_shipdate < '1995-10-01'
 ---- RESULTS
-16.380778
+16.380779
 ---- TYPES
 decimal
-====
+====
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/impala/blob/0a1d586d/testdata/workloads/tpch_nested/queries/tpch_nested-q17.test
----------------------------------------------------------------------
diff --git a/testdata/workloads/tpch_nested/queries/tpch_nested-q17.test b/testdata/workloads/tpch_nested/queries/tpch_nested-q17.test
index d4b59f3..d07e724 100644
--- a/testdata/workloads/tpch_nested/queries/tpch_nested-q17.test
+++ b/testdata/workloads/tpch_nested/queries/tpch_nested-q17.test
@@ -19,7 +19,7 @@ where
       l_partkey = p_partkey
   )
 ---- RESULTS
-348406.05
+348406.054286
 ---- TYPES
 decimal
-====
+====
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/impala/blob/0a1d586d/testdata/workloads/tpch_nested/queries/tpch_nested-q8.test
----------------------------------------------------------------------
diff --git a/testdata/workloads/tpch_nested/queries/tpch_nested-q8.test b/testdata/workloads/tpch_nested/queries/tpch_nested-q8.test
index 94d91a6..19b083b 100644
--- a/testdata/workloads/tpch_nested/queries/tpch_nested-q8.test
+++ b/testdata/workloads/tpch_nested/queries/tpch_nested-q8.test
@@ -36,8 +36,8 @@ group by
 order by
   o_year
 ---- RESULTS
-1995,0.0344
-1996,0.0414
+1995,0.034436
+1996,0.041486
 ---- TYPES
 int, decimal
-====
+====
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/impala/blob/0a1d586d/tests/hs2/test_hs2.py
----------------------------------------------------------------------
diff --git a/tests/hs2/test_hs2.py b/tests/hs2/test_hs2.py
index 040d997..c90113c 100644
--- a/tests/hs2/test_hs2.py
+++ b/tests/hs2/test_hs2.py
@@ -439,9 +439,8 @@ class TestHS2(HS2TestSuite):
     log = self.get_log("select * from functional.alltypeserror")
     assert "Error converting column" in log
 
-    # Test overflow warning
-    log = self.get_log("select cast(1000 as decimal(2, 1))")
-    assert "Decimal expression overflowed, returning NULL" in log
+    log = self.get_log("select base64decode('foo')")
+    assert "Invalid base64 string; input length is 3, which is not a multiple of 4" in log
 
   @needs_session()
   def test_get_exec_summary(self):

http://git-wip-us.apache.org/repos/asf/impala/blob/0a1d586d/tests/query_test/test_aggregation.py
----------------------------------------------------------------------
diff --git a/tests/query_test/test_aggregation.py b/tests/query_test/test_aggregation.py
index aee2236..97c0e41 100644
--- a/tests/query_test/test_aggregation.py
+++ b/tests/query_test/test_aggregation.py
@@ -297,10 +297,10 @@ class TestAggregationQueries(ImpalaTestSuite):
                ndv(smallint_col), ndv(int_col),
                ndv(bigint_col), ndv(float_col),
                ndv(double_col), ndv(string_col),
-               ndv(cast(double_col as decimal(3, 0))),
+               ndv(cast(double_col as decimal(5, 0))),
                ndv(cast(double_col as decimal(10, 5))),
                ndv(cast(double_col as decimal(20, 10))),
-               ndv(cast(double_col as decimal(38, 35))),
+               ndv(cast(double_col as decimal(38, 33))),
                ndv(cast(string_col as varchar(20))),
                ndv(cast(string_col as char(10))),
                ndv(timestamp_col), ndv(id)
@@ -314,10 +314,10 @@ class TestAggregationQueries(ImpalaTestSuite):
                  sampled_ndv(smallint_col, {0}), sampled_ndv(int_col, {0}),
                  sampled_ndv(bigint_col, {0}), sampled_ndv(float_col, {0}),
                  sampled_ndv(double_col, {0}), sampled_ndv(string_col, {0}),
-                 sampled_ndv(cast(double_col as decimal(3, 0)), {0}),
+                 sampled_ndv(cast(double_col as decimal(5, 0)), {0}),
                  sampled_ndv(cast(double_col as decimal(10, 5)), {0}),
                  sampled_ndv(cast(double_col as decimal(20, 10)), {0}),
-                 sampled_ndv(cast(double_col as decimal(38, 35)), {0}),
+                 sampled_ndv(cast(double_col as decimal(38, 33)), {0}),
                  sampled_ndv(cast(string_col as varchar(20)), {0}),
                  sampled_ndv(cast(string_col as char(10)), {0}),
                  sampled_ndv(timestamp_col, {0}), sampled_ndv(id, {0})

http://git-wip-us.apache.org/repos/asf/impala/blob/0a1d586d/tests/query_test/test_decimal_casting.py
----------------------------------------------------------------------
diff --git a/tests/query_test/test_decimal_casting.py b/tests/query_test/test_decimal_casting.py
index 445fe6b..3becc3f 100644
--- a/tests/query_test/test_decimal_casting.py
+++ b/tests/query_test/test_decimal_casting.py
@@ -81,9 +81,7 @@ class TestDecimalCasting(ImpalaTestSuite):
         expected, actual)
 
   def _normalize_cast_expr(self, decimal_val, precision, cast_from):
-    # Due to IMPALA-4936, casts from double which overflows decimal type don't work
-    # reliably. So casting from string for now until IMPALA-4936 is fixed.
-    if precision > 38 or cast_from == 'string':
+    if cast_from == 'string':
       return "select cast('{0}' as Decimal({1},{2}))"
     else:
       return "select cast({0} as Decimal({1},{2}))"
@@ -139,8 +137,12 @@ class TestDecimalCasting(ImpalaTestSuite):
       val = self._gen_decimal_val(from_precision, scale)
       cast = self._normalize_cast_expr(val, from_precision,\
           vector.get_value('cast_from')).format(val, precision, scale)
-      res = self.execute_scalar(cast)
-      self._assert_decimal_result(cast, res, 'NULL')
+      if vector.get_value('cast_from') == "string":
+        # TODO: This should be an error in both cases (IMPALA-6405).
+        res = self.execute_scalar(cast)
+        self._assert_decimal_result(cast, res, 'NULL')
+      else:
+        res = self.execute_query_expect_failure(self.client, cast)
 
   def test_underflow(self, vector):
     """Test to verify that we truncate when the scale of the number being cast is higher

http://git-wip-us.apache.org/repos/asf/impala/blob/0a1d586d/tests/query_test/test_mem_usage_scaling.py
----------------------------------------------------------------------
diff --git a/tests/query_test/test_mem_usage_scaling.py b/tests/query_test/test_mem_usage_scaling.py
index efc500b..3a9f5ee 100644
--- a/tests/query_test/test_mem_usage_scaling.py
+++ b/tests/query_test/test_mem_usage_scaling.py
@@ -289,4 +289,5 @@ class TestTpcdsMemLimitError(TestLowMemoryLimits):
         v.get_value('table_format').file_format in ['parquet'])
 
   def test_low_mem_limit_q53(self, vector):
-    self.low_memory_limit_test(vector, 'tpcds-q53', self.MIN_MEM_FOR_TPCDS['q53'])
+    self.low_memory_limit_test(
+        vector, 'tpcds-decimal_v2-q53', self.MIN_MEM_FOR_TPCDS['q53'])

http://git-wip-us.apache.org/repos/asf/impala/blob/0a1d586d/tests/query_test/test_tpcds_queries.py
----------------------------------------------------------------------
diff --git a/tests/query_test/test_tpcds_queries.py b/tests/query_test/test_tpcds_queries.py
index 9cec9f7..4b937b1 100644
--- a/tests/query_test/test_tpcds_queries.py
+++ b/tests/query_test/test_tpcds_queries.py
@@ -36,6 +36,7 @@ class TestTpcdsQuery(ImpalaTestSuite):
         v.get_value('table_format').file_format not in ['rc', 'hbase', 'kudu'] and\
         v.get_value('table_format').compression_codec in ['none', 'snap'] and\
         v.get_value('table_format').compression_type != 'record')
+    cls.ImpalaTestMatrix.add_mandatory_exec_option('decimal_v2', 0)
 
     if cls.exploration_strategy() != 'exhaustive':
       # Cut down on the execution time for these tests in core by running only
@@ -277,7 +278,6 @@ class TestTpcdsDecimalV2Query(ImpalaTestSuite):
         v.get_value('table_format').file_format not in ['rc', 'hbase', 'kudu'] and\
         v.get_value('table_format').compression_codec in ['none', 'snap'] and\
         v.get_value('table_format').compression_type != 'record')
-    cls.ImpalaTestMatrix.add_mandatory_exec_option('decimal_v2', 1)
 
     if cls.exploration_strategy() != 'exhaustive':
       # Cut down on the execution time for these tests in core by running only