impala-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From taras...@apache.org
Subject [3/5] incubator-impala git commit: IMPALA-5018: Error on decimal modulo or divide by zero
Date Wed, 25 Oct 2017 01:18:00 GMT
IMPALA-5018: Error on decimal modulo or divide by zero

Before this patch, decimal operations would never produce an error.
Division by and modulo zero would result in a NULL.

In this patch, we change this behavior so that we raise an error
instead of returning a NULL. We also modify the format of the decimal
expr tests format to also include an error field.

Testing:
- Added several expr and end to end tests.

Change-Id: If7a7131e657fcdd293ade78d62f851dac0f1e3eb
Reviewed-on: http://gerrit.cloudera.org:8080/8344
Reviewed-by: Dan Hecht <dhecht@cloudera.com>
Tested-by: Impala Public Jenkins


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

Branch: refs/heads/master
Commit: 5ebea0ec4db9a0b954988975b4b7c02971a780a0
Parents: e020c37
Author: Taras Bobrovytsky <tbobrovytsky@cloudera.com>
Authored: Thu Oct 19 13:43:14 2017 -0700
Committer: Impala Public Jenkins <impala-public-jenkins@gerrit.cloudera.org>
Committed: Wed Oct 25 00:44:34 2017 +0000

----------------------------------------------------------------------
 be/src/exprs/decimal-operators-ir.cc            |   23 +-
 be/src/exprs/expr-test.cc                       | 1156 +++++++++---------
 .../queries/QueryTest/decimal-exprs.test        |   68 +-
 3 files changed, 682 insertions(+), 565 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-impala/blob/5ebea0ec/be/src/exprs/decimal-operators-ir.cc
----------------------------------------------------------------------
diff --git a/be/src/exprs/decimal-operators-ir.cc b/be/src/exprs/decimal-operators-ir.cc
index 17ba972..4af2366 100644
--- a/be/src/exprs/decimal-operators-ir.cc
+++ b/be/src/exprs/decimal-operators-ir.cc
@@ -716,34 +716,43 @@ BooleanVal DecimalOperators::CastToBooleanVal(
         ctx->impl()->GetConstFnAttr(FunctionContextImpl::RETURN_TYPE_PRECISION); \
     int return_scale = \
         ctx->impl()->GetConstFnAttr(FunctionContextImpl::RETURN_TYPE_SCALE); \
-    bool round = \
+    const bool decimal_v2 = \
         ctx->impl()->GetConstFnAttr(FunctionContextImpl::DECIMAL_V2); \
     switch (ctx->impl()->GetConstFnAttr(FunctionContextImpl::RETURN_TYPE_SIZE)) { \
       case 4: { \
         Decimal4Value x_val = GetDecimal4Value(x, x_size, &overflow); \
         Decimal4Value y_val = GetDecimal4Value(y, y_size, &overflow); \
         Decimal4Value result = x_val.OP_FN<int32_t>(x_scale, y_val, y_scale, \
-            return_precision, return_scale, round, &is_nan, &overflow); \
+            return_precision, return_scale, decimal_v2, &is_nan, &overflow); \
         DCHECK(!overflow) << "Cannot overflow except with Decimal16Value"; \
-        if (is_nan) return DecimalVal::null(); \
+        if (is_nan) { \
+          if (decimal_v2) ctx->SetError("Cannot divide decimal by zero"); \
+          return DecimalVal::null(); \
+        } \
         return DecimalVal(result.value()); \
       } \
       case 8: { \
         Decimal8Value x_val = GetDecimal8Value(x, x_size, &overflow); \
         Decimal8Value y_val = GetDecimal8Value(y, y_size, &overflow); \
         Decimal8Value result = x_val.OP_FN<int64_t>(x_scale, y_val, y_scale, \
-            return_precision, return_scale, round, &is_nan, &overflow); \
+            return_precision, return_scale, decimal_v2, &is_nan, &overflow); \
         DCHECK(!overflow) << "Cannot overflow except with Decimal16Value"; \
-        if (is_nan) return DecimalVal::null(); \
+        if (is_nan) { \
+          if (decimal_v2) ctx->SetError("Cannot divide decimal by zero"); \
+          return DecimalVal::null(); \
+        } \
         return DecimalVal(result.value()); \
       } \
       case 16: { \
         Decimal16Value x_val = GetDecimal16Value(x, x_size, &overflow); \
         Decimal16Value y_val = GetDecimal16Value(y, y_size, &overflow); \
         Decimal16Value result = x_val.OP_FN<int128_t>(x_scale, y_val, y_scale, \
-            return_precision, return_scale, round, &is_nan, &overflow); \
+            return_precision, return_scale, decimal_v2, &is_nan, &overflow); \
         RETURN_IF_OVERFLOW(ctx, overflow, DecimalVal); \
-        if (is_nan) return DecimalVal::null(); \
+        if (is_nan) { \
+          if (decimal_v2) ctx->SetError("Cannot divide decimal by zero"); \
+          return DecimalVal::null(); \
+        } \
         return DecimalVal(result.value()); \
       } \
       default: \

http://git-wip-us.apache.org/repos/asf/incubator-impala/blob/5ebea0ec/be/src/exprs/expr-test.cc
----------------------------------------------------------------------
diff --git a/be/src/exprs/expr-test.cc b/be/src/exprs/expr-test.cc
index ed78535..b509da6 100644
--- a/be/src/exprs/expr-test.cc
+++ b/be/src/exprs/expr-test.cc
@@ -1476,6 +1476,7 @@ TEST_F(ExprTest, ArithmeticExprs) {
 // Use a table-driven approach to test DECIMAL expressions to make it easier to test
 // both the old (decimal_v2=false) and new (decimal_v2=true) DECIMAL semantics.
 struct DecimalExpectedResult {
+  bool error;
   bool null;
   int128_t scaled_val;
   int precision;
@@ -1558,921 +1559,960 @@ int128_t StringToInt128(string s) {
 
 // Format is:
 // { Test Expression (as a string),
-//  { expected null, scaled_val, precision, scale for V1
-//    expected null, scaled_val, precision, scale for V2 }}
+//  { expected error, expected null, scaled_val, precision, scale for V1
+//    expected error, expected null, scaled_val, precision, scale for V2 }}
 DecimalTestCase decimal_cases[] = {
   // Test add/subtract operators
-  { "1.23 + cast(1 as decimal(4,3))", {{ false, 2230, 5, 3 }}},
-  { "1.23 - cast(0.23 as decimal(10,3))", {{ false, 1000, 11, 3 }}},
-  { "cast(1.23 as decimal(8,2)) + cast(1 as decimal(20,3))", {{ false, 2230, 21, 3 }}},
-  { "cast(1.23 as decimal(30,2)) - cast(1 as decimal(4,3))", {{ false, 230, 32, 3 }}},
-  { "cast(1 as decimal(38,0)) + cast(.2 as decimal(38,1))", {{ false, 12, 38, 1 }}},
+  { "1.23 + cast(1 as decimal(4,3))", {{ false, false, 2230, 5, 3 }}},
+  { "1.23 - cast(0.23 as decimal(10,3))", {{ false, false, 1000, 11, 3 }}},
+  { "cast(1.23 as decimal(8,2)) + cast(1 as decimal(20,3))",
+    {{ false, false, 2230, 21, 3 }}},
+  { "cast(1.23 as decimal(30,2)) - cast(1 as decimal(4,3))",
+    {{ false, false, 230, 32, 3 }}},
+  { "cast(1 as decimal(38,0)) + cast(.2 as decimal(38,1))",
+    {{ false, false, 12, 38, 1 }}},
   // Test multiply operator
   { "cast(1.23 as decimal(30,2)) * cast(1 as decimal(10,3))",
-    {{ false, 123000, 38, 5 }}},
+    {{ false, false, 123000, 38, 5 }}},
   { "cast(1.23 as decimal(3,2)) * cast(1 as decimal(20,3))",
-    {{ false, 123000, 23, 5 },
-     { false, 123000, 24, 5 }}},
+    {{ false, false, 123000, 23, 5 },
+     { false, false, 123000, 24, 5 }}},
   { "cast(0.1 as decimal(20,20)) * cast(1 as decimal(20,19))",
-    {{ false, StringToInt128("10000000000000000000000000000000000000"), 38, 38 },
-     { false, StringToInt128("100000000000000000000000000000000000"), 38, 36 }}},
+    {{ false, false, StringToInt128("10000000000000000000000000000000000000"), 38, 38 },
+     { false, false, StringToInt128("100000000000000000000000000000000000"), 38, 36 }}},
   { "cast(111.22 as decimal(5,2)) * cast(3333.444 as decimal(7,3))",
-    {{ false, 37074564168, 12, 5 },
-     { false, 37074564168, 13, 5 }}},
+    {{ false, false, 37074564168, 12, 5 },
+     { false, false, 37074564168, 13, 5 }}},
   { "cast(0.01 as decimal(38,38)) * cast(25 as decimal(38,0))",
-    {{ false, StringToInt128("25000000000000000000000000000000000000"), 38, 38 },
-     { false, 250000, 38, 6 }}},
+    {{ false, false, StringToInt128("25000000000000000000000000000000000000"), 38, 38 },
+     { false, false, 250000, 38, 6 }}},
   { "cast(-0.01 as decimal(38,38)) * cast(25 as decimal(38,0))",
-    {{ false, StringToInt128("-25000000000000000000000000000000000000"), 38, 38 },
-     { false, -250000, 38, 6 }}},
+    {{ false, false, StringToInt128("-25000000000000000000000000000000000000"), 38, 38 },
+     { false, false, -250000, 38, 6 }}},
   { "cast(-0.01 as decimal(38,38)) * cast(-25 as decimal(38,0))",
-    {{ false, StringToInt128("25000000000000000000000000000000000000"), 38, 38 },
-     { false, 250000, 38, 6 }}},
+    {{ false, false, StringToInt128("25000000000000000000000000000000000000"), 38, 38 },
+     { false, false, 250000, 38, 6 }}},
   { "cast(0.1 as decimal(38,38)) * cast(25 as decimal(38,0))",
-    {{ true, 0, 38, 38 },
-     { false, 2500000, 38, 6 }}},
+    {{ false, true, 0, 38, 38 },
+     { false, false, 2500000, 38, 6 }}},
   { "cast(-0.1 as decimal(38,38)) * cast(25 as decimal(38,0))",
-    {{ true, 0, 38, 38 },
-     { false, -2500000, 38, 6 }}},
+    {{ false, true, 0, 38, 38 },
+     { false, false, -2500000, 38, 6 }}},
   { "cast(-0.1 as decimal(38,38)) * cast(-25 as decimal(38,0))",
-    {{ true, 0, 38, 38 },
-     { false, 2500000, 38, 6 }}},
+    {{ false, true, 0, 38, 38 },
+     { false, false, 2500000, 38, 6 }}},
   { "cast(9999999999999999.9999 as decimal(20,4)) * "
       "cast(9999999999999999.994 as decimal(19,3))",
-    {{ true, 0, 38, 7 },
-     { false, StringToInt128("99999999999999999939000000000000000001"), 38, 6 }}},
+    {{ false, true, 0, 38, 7 },
+     { false, false, StringToInt128("99999999999999999939000000000000000001"), 38, 6 }}},
   { "cast(9.99999 as decimal(6,5)) * "
       "cast(9999999999999999999999999999999.94 as decimal(33,2))",
-    {{ true, 0, 38, 7 },
-     { false, StringToInt128("99999899999999999999999999999999400001"), 38, 6 }}},
+    {{ false, true, 0, 38, 7 },
+     { false, false, StringToInt128("99999899999999999999999999999999400001"), 38, 6 }}},
   { "cast(0 as decimal(38,38)) * cast(1 as decimal(5,2))",
-    {{ false, 0, 38, 38 },
-     { false, 0, 38, 34 }}},
+    {{ false, false, 0, 38, 38 },
+     { false, false, 0, 38, 34 }}},
   { "cast(12345.67 as decimal(7,2)) * cast(12345.67 as decimal(7,2))",
-    {{ false, 1524155677489, 14, 4 },
-     { false, 1524155677489, 15, 4 }}},
+    {{ false, false, 1524155677489, 14, 4 },
+     { false, false, 1524155677489, 15, 4 }}},
   { "cast(2643918831543678.5772617359442611897419 as decimal(38,22)) * "
       "cast(3972211379387512.6946776728996748717839 as decimal(38,22))",
-    {{ true, 0, 38, 38 },
-     { false, StringToInt128("10502204468834736291038133384309593605"), 38, 6 }}},
+    {{ false, true, 0, 38, 38 },
+     { false, false, StringToInt128("10502204468834736291038133384309593605"), 38, 6 }}},
   { "cast(-2643918831543678.5772617359442611897419 as decimal(38,22)) * "
       "cast(3972211379387512.6946776728996748717839 as decimal(38,22))",
-    {{ true, 0, 38, 38 },
-     { false, StringToInt128("-10502204468834736291038133384309593605"), 38, 6 }}},
+    {{ false, true, 0, 38, 38 },
+     { false, false, StringToInt128("-10502204468834736291038133384309593605"), 38, 6 }}},
   { "cast(-2643918831543678.5772617359442611897419 as decimal(38,22)) * "
       "cast(-3972211379387512.6946776728996748717839 as decimal(38,22))",
-    {{ true, 0, 38, 38 },
-     { false, StringToInt128("10502204468834736291038133384309593605"), 38, 6 }}},
+    {{ false, true, 0, 38, 38 },
+     { false, false, StringToInt128("10502204468834736291038133384309593605"), 38, 6 }}},
   { "cast(2545664579818579.6268123468146829994472 as decimal(38,22)) * "
       "cast(8862165565622381.6689679519457799681439 as decimal(38,22))",
-    {{ true, 0, 38, 38 },
-     { false, StringToInt128("22560100980892785285767018366785939200"), 38, 6 }}},
+    {{ false, true, 0, 38, 38 },
+     { false, false, StringToInt128("22560100980892785285767018366785939200"), 38, 6 }}},
   { "cast(2575543652687181.7412422395638291836214 as decimal(38,22)) * "
       "cast(9142529549684737.3986798331295277312253 as decimal(38,22))",
-    {{ true, 0, 38, 38 },
-     { false, StringToInt128("23546983951195523383767823614338114083"), 38, 6 }}},
+    {{ false, true, 0, 38, 38 },
+     { false, false, StringToInt128("23546983951195523383767823614338114083"), 38, 6 }}},
   { "cast(6188696551164477.9944646378584981371524 as decimal(38,22)) * "
       "cast(9234914917975734.1781526147879384775182 as decimal(38,22))",
-    {{ true, 0, 38, 38 },
-     { false, StringToInt128("57152086103173814294786121078946977968"), 38, 6 }}},
+    {{ false, true, 0, 38, 38 },
+     { false, false, StringToInt128("57152086103173814294786121078946977968"), 38, 6 }}},
   { "cast(-6188696551164477.9944646378584981371524 as decimal(38,22)) * "
       "cast(9234914917975734.1781526147879384775182 as decimal(38,22))",
-    {{ true, 0, 38, 38 },
-     { false, StringToInt128("-57152086103173814294786121078946977968"), 38, 6 }}},
+    {{ false, true, 0, 38, 38 },
+     { false, false, StringToInt128("-57152086103173814294786121078946977968"), 38, 6 }}},
   { "cast(1.006 as decimal(4,2)) * cast(1.1 as decimal(4,2))",
-    {{ false, 11000, 8, 4 },
-     { false, 11110, 9, 4 }}},
+    {{ false, false, 11000, 8, 4 },
+     { false, false, 11110, 9, 4 }}},
   { "cast(0.9994 as decimal(38,4)) * cast(0.999 as decimal(38,3))",
-    {{ false, 9984006, 38, 7 },
-     { false, 998401, 38, 6 }}},
+    {{ false, false, 9984006, 38, 7 },
+     { false, false, 998401, 38, 6 }}},
   { "cast(0.000000000000000000000000000000000001 as decimal(38,38)) * "
       "cast(0.000000000000000000000000000000000001 as decimal(38,38))",
-    {{ false, 0, 38, 38 },
-     { false, 0, 38, 37 }}},
+    {{ false, false, 0, 38, 38 },
+     { false, false, 0, 38, 37 }}},
   { "cast(0.00000000000000000000000000000000001 as decimal(38,37)) * "
       "cast(0.00000000000000000000000000000000001 as decimal(38,37))",
-    {{ false, 0, 38, 38 },
-     { false, 0, 38, 35 }}},
+    {{ false, false, 0, 38, 38 },
+     { false, false, 0, 38, 35 }}},
   { "cast(0.00000000000000001 as decimal(38,37)) * "
       "cast(0.000000000000000001 as decimal(38,37))",
-    {{ false, 1000, 38, 38 },
-     { false, 1, 38, 35 }}},
+    {{ false, false, 1000, 38, 38 },
+     { false, false, 1, 38, 35 }}},
   { "cast(9e-18 as decimal(38,38)) * cast(1e-21 as decimal(38,38))",
-    {{ false, 0, 38, 38 },
-     { false, 0, 38, 37 }}},
+    {{ false, false, 0, 38, 38 },
+     { false, false, 0, 38, 37 }}},
   { "cast(1e-37 as decimal(38,38)) * cast(0.1 as decimal(38,38))",
-    {{ false, 1, 38, 38 },
-     { false, 0, 38, 37 }}},
+    {{ false, false, 1, 38, 38 },
+     { false, false, 0, 38, 37 }}},
   { "cast(1e-37 as decimal(38,38)) * cast(-0.1 as decimal(38,38))",
-    {{ false, -1, 38, 38 },
-     { false, 0, 38, 37 }}},
+    {{ false, false, -1, 38, 38 },
+     { false, false, 0, 38, 37 }}},
   { "cast(9e-36 as decimal(38,38)) * cast(0.1 as decimal(38,38))",
-    {{ false, 90, 38, 38 },
-     { false, 9, 38, 37 }}},
+    {{ false, false, 90, 38, 38 },
+     { false, false, 9, 38, 37 }}},
   { "cast(9e-37 as decimal(38,38)) * cast(0.1 as decimal(38,38))",
-    {{ false, 9, 38, 38 },
-     { false, 1, 38, 37 }}},
+    {{ false, false, 9, 38, 38 },
+     { false, false, 1, 38, 37 }}},
   // We are multiplying (2^64 - 1) * (2^63 - 1), which produces the largest intermediate
   // result that does not require int256. It overflows because the result is larger than
   // MAX_UNSCALED_DECIMAL16.
-  { "cast(18446744073709551615 as decimal(38,0)) * cast(9223372036854775807 as decimal(38,0))",
-    {{ true, 0, 38, 0 }}},
-  { "cast(-18446744073709551615 as decimal(38,0)) * cast(9223372036854775807 as decimal(38,0))",
-    {{ true, 0, 38, 0 }}},
+  { "cast(18446744073709551615 as decimal(38,0)) * "
+    "cast(9223372036854775807 as decimal(38,0))",
+    {{ false, true, 0, 38, 0 }}},
+  { "cast(-18446744073709551615 as decimal(38,0)) * "
+    "cast(9223372036854775807 as decimal(38,0))",
+    {{ false, true, 0, 38, 0 }}},
   // int256 is required. We are multiplying (2^64 - 1) * (2^63) here.
-  { "cast(18446744073709551615 as decimal(38,0)) * cast(9223372036854775808 as decimal(38,0))",
-    {{ true, 0, 38, 0 }}},
-  { "cast(-18446744073709551615 as decimal(38,0)) * cast(9223372036854775808 as decimal(38,0))",
-    {{ true, 0, 38, 0 }}},
+  { "cast(18446744073709551615 as decimal(38,0)) * "
+    "cast(9223372036854775808 as decimal(38,0))",
+    {{ false, true, 0, 38, 0 }}},
+  { "cast(-18446744073709551615 as decimal(38,0)) * "
+    "cast(9223372036854775808 as decimal(38,0))",
+    {{ false, true, 0, 38, 0 }}},
   // Largest intermediate result that does not require int256.
-  { "cast(1844674407370.9551615 as decimal(38,7)) * cast(9223372036854775807 as decimal(38,0))",
-    {{ true, 0, 38, 7 },
-     { false, StringToInt128("17014118346046923170401718760531977831"), 38, 6 }}},
-  { "cast(-1844674407370.9551615 as decimal(38,7)) * cast(9223372036854775807 as decimal(38,0))",
-    {{ true, 0, 38, 7 },
-     { false, StringToInt128("-17014118346046923170401718760531977831"), 38, 6 }}},
+  { "cast(1844674407370.9551615 as decimal(38,7)) * "
+    "cast(9223372036854775807 as decimal(38,0))",
+    {{ false, true, 0, 38, 7 },
+     { false, false, StringToInt128("17014118346046923170401718760531977831"), 38, 6 }}},
+  { "cast(-1844674407370.9551615 as decimal(38,7)) * "
+    "cast(9223372036854775807 as decimal(38,0))",
+    {{ false, true, 0, 38, 7 },
+     { false, false, StringToInt128("-17014118346046923170401718760531977831"), 38, 6 }}},
   // int256 is required.
-  { "cast(1844674407370.9551615 as decimal(38,7)) * cast(9223372036854775808 as decimal(38,0))",
-    {{ true, 0, 38, 7 },
-     { false, StringToInt128("17014118346046923172246393167902932992"), 38, 6 }}},
-  { "cast(-1844674407370.9551615 as decimal(38,7)) * cast(9223372036854775808 as decimal(38,0))",
-    {{ true, 0, 38, 7 },
-     { false, StringToInt128("-17014118346046923172246393167902932992"), 38, 6 }}},
+  { "cast(1844674407370.9551615 as decimal(38,7)) * "
+    "cast(9223372036854775808 as decimal(38,0))",
+    {{ false, true, 0, 38, 7 },
+     { false, false, StringToInt128("17014118346046923172246393167902932992"), 38, 6 }}},
+  { "cast(-1844674407370.9551615 as decimal(38,7)) * "
+    "cast(9223372036854775808 as decimal(38,0))",
+    {{ false, true, 0, 38, 7 },
+     { false, false, StringToInt128("-17014118346046923172246393167902932992"), 38, 6 }}},
   // Smallest intermediate value that requires double checking if int256 is required.
-  { "cast(9223372036854775808 as decimal(38,0)) * cast(9223372036854775808 as decimal(38,0))",
-    {{ false, StringToInt128("85070591730234615865843651857942052864"), 38, 0 }}},
-  { "cast(-9223372036854775808 as decimal(38,0)) * cast(9223372036854775808 as decimal(38,0))",
-    {{ false, StringToInt128("-85070591730234615865843651857942052864"), 38, 0 }}},
+  { "cast(9223372036854775808 as decimal(38,0)) * "
+    "cast(9223372036854775808 as decimal(38,0))",
+    {{ false, false, StringToInt128("85070591730234615865843651857942052864"), 38, 0 }}},
+  { "cast(-9223372036854775808 as decimal(38,0)) * "
+    "cast(9223372036854775808 as decimal(38,0))",
+    {{ false, false, StringToInt128("-85070591730234615865843651857942052864"), 38, 0 }}},
   // Scale down the intermediate value by 10^39.
   { "cast(0.33333333333333333333333333333333333333 as decimal(38,38)) * "
       "cast(0.00000000000000000000000000000000000003 as decimal(38,38))",
-    {{ false, 0, 38, 38 },
-     { false, 0, 38, 37 }}},
+    {{ false, false, 0, 38, 38 },
+     { false, false, 0, 38, 37 }}},
   { "cast(0.33333333333333333333333333333333333333 as decimal(38,38)) * "
       "cast(0.3 as decimal(38,38))",
-    {{ false, StringToInt128("9999999999999999999999999999999999999"), 38, 38 },
-     { false, StringToInt128("1000000000000000000000000000000000000"), 38, 37 }}},
+    {{ false, false, StringToInt128("9999999999999999999999999999999999999"), 38, 38 },
+     { false, false, StringToInt128("1000000000000000000000000000000000000"), 38, 37 }}},
   { "cast(10000000000000000000 as decimal(21,0)) * "
       "cast(10000000000000000000 as decimal(21,0))",
-    {{ true, 0, 38, 0 }}},
+    {{ false, true, 0, 38, 0 }}},
   { "cast(1000000000000000.0000 as decimal(38,4)) * "
       "cast(1000000000000000.0000 as decimal(38,4))",
-    {{ true, 0, 38, 8 },
-     { false, StringToInt128("1000000000000000000000000000000000000"), 38, 6 }}},
+    {{ false, true, 0, 38, 8 },
+     { false, false, StringToInt128("1000000000000000000000000000000000000"), 38, 6 }}},
   { "cast(-1000000000000000.0000 as decimal(38,4)) * "
       "cast(1000000000000000.0000 as decimal(38,4))",
-    {{ true, 0, 38, 8 },
-     { false, StringToInt128("-1000000000000000000000000000000000000"), 38, 6 }}},
+    {{ false, true, 0, 38, 8 },
+     { false, false, StringToInt128("-1000000000000000000000000000000000000"), 38, 6 }}},
   // Smallest 256 bit intermediate result that can't be scaled down to 128 bits.
   { "cast(10000000000000000.0000 as decimal(38,4)) * "
       "cast(10000000000000000.0000 as decimal(38,4))",
-    {{ true, 0, 38, 8 },
-     { true, 0, 38, 6 }}},
+    {{ false, true, 0, 38, 8 },
+     { false, true, 0, 38, 6 }}},
   { "cast(-10000000000000000.0000 as decimal(38,4)) * "
       "cast(10000000000000000.0000 as decimal(38,4))",
-    {{ true, 0, 38, 8 },
-     { true, 0, 38, 6 }}},
+    {{ false, true, 0, 38, 8 },
+     { false, true, 0, 38, 6 }}},
   // The reason why the result of (38,38) * (38,38) is (38,37).
   { "cast(0.99999999999999999999999999999999999999 as decimal(38,38)) * "
       "cast(0.99999999999999999999999999999999999999 as decimal(38,38))",
-    {{ false, StringToInt128("99999999999999999999999999999999999998"), 38, 38 },
-     { false, StringToInt128("10000000000000000000000000000000000000"), 38, 37 }}},
+    {{ false, false, StringToInt128("99999999999999999999999999999999999998"), 38, 38 },
+     { false, false, StringToInt128("10000000000000000000000000000000000000"), 38, 37 }}},
   { "cast(-0.99999999999999999999999999999999999999 as decimal(38,38)) * "
       "cast(0.99999999999999999999999999999999999999 as decimal(38,38))",
-    {{ false, StringToInt128("-99999999999999999999999999999999999998"), 38, 38 },
-     { false, StringToInt128("-10000000000000000000000000000000000000"), 38, 37 }}},
+    {{ false, false, StringToInt128("-99999999999999999999999999999999999998"), 38, 38 },
+     { false, false, StringToInt128("-10000000000000000000000000000000000000"), 38, 37 }}},
   { "cast(99999999999999999999999999999999999999 as decimal(38,0)) * "
       "cast(1 as decimal(38,0))",
-    {{ false, StringToInt128("99999999999999999999999999999999999999"), 38, 0 }}},
+    {{ false, false, StringToInt128("99999999999999999999999999999999999999"), 38, 0 }}},
   { "cast(99999999999999999999999999999999999999 as decimal(38,0)) * "
       "cast(-1 as decimal(38,0))",
-    {{ false, StringToInt128("-99999999999999999999999999999999999999"), 38, 0 }}},
+    {{ false, false, StringToInt128("-99999999999999999999999999999999999999"), 38, 0 }}},
   // Rounding.
   { "cast(0.000005 as decimal(38,6)) * cast(0.1 as decimal(38,1))",
-    {{ false, 5, 38, 7 },
-     { false, 1, 38, 6 }}},
+    {{ false, false, 5, 38, 7 },
+     { false, false, 1, 38, 6 }}},
   { "cast(-0.000005 as decimal(38,6)) * cast(0.1 as decimal(38,1))",
-    {{ false, -5, 38, 7 },
-     { false, -1, 38, 6 }}},
+    {{ false, false, -5, 38, 7 },
+     { false, false, -1, 38, 6 }}},
   { "cast(0.000004 as decimal(38,6)) * cast(0.1 as decimal(38,1))",
-    {{ false, 4, 38, 7 },
-     { false, 0, 38, 6 }}},
+    {{ false, false, 4, 38, 7 },
+     { false, false, 0, 38, 6 }}},
   { "cast(-0.000004 as decimal(38,6)) * cast(0.1 as decimal(38,1))",
-    {{ false, -4, 38, 7 },
-     { false, 0, 38, 6 }}},
+    {{ false, false, -4, 38, 7 },
+     { false, false, 0, 38, 6 }}},
   // Test divide operator
-  { "cast(1.23 as decimal(8,2)) / cast(1 as decimal(4,3))", {{ false, 12300000, 16, 7}}},
+  { "cast(1.23 as decimal(8,2)) / cast(1 as decimal(4,3))",
+    {{ false, false, 12300000, 16, 7}}},
   { "cast(1.23 as decimal(30,2)) / cast(1 as decimal(20,3))",
-    {{ false,     1230, 38, 3 },
-     { false, 12300000, 38, 7 }}},
+    {{ false, false,     1230, 38, 3 },
+     { false, false, 12300000, 38, 7 }}},
   { "cast(1 as decimal(38,0)) / cast(.2 as decimal(38,1))",
-    {{ false,      50, 38, 1 },
-     { false, 5000000, 38, 6 }}},
+    {{ false, false,      50, 38, 1 },
+     { false, false, 5000000, 38, 6 }}},
   { "cast(1 as decimal(38,0)) / cast(3 as decimal(38,0))",
-    {{ false,      0, 38, 0 },
-     { false, 333333, 38, 6 }}},
+    {{ false, false,      0, 38, 0 },
+     { false, false, 333333, 38, 6 }}},
   { "cast(99999999999999999999999999999999999999 as decimal(38,0)) / "
     "cast(99999999999999999999999999999999999999 as decimal(38,0))",
-    {{ false,       1, 38, 0 },
-     { false, 1000000, 38, 6 }}},
+    {{ false, false,       1, 38, 0 },
+     { false, false, 1000000, 38, 6 }}},
   { "cast(99999999999999999999999999999999999999 as decimal(38,0)) / "
     "cast(0.00000000000000000000000000000000000001 as decimal(38,38))",
-    {{ true, 0, 38, 38 },
-     { true, 0, 38,  6 }}},
+    {{ false, true, 0, 38, 38 },
+     { false, true, 0, 38,  6 }}},
   { "cast(0.00000000000000000000000000000000000001 as decimal(38,38)) / "
     "cast(99999999999999999999999999999999999999 as decimal(38,0))",
-    {{ false, 0, 38, 38 }}},
+    {{ false, false, 0, 38, 38 }}},
   { "cast(0.00000000000000000000000000000000000001 as decimal(38,38)) / "
     "cast(0.00000000000000000000000000000000000001 as decimal(38,38))",
-    {{ true,        0, 38, 38 },
-     { false, 1000000, 38,  6 }}},
+    {{ false, true,        0, 38, 38 },
+     { false, false, 1000000, 38,  6 }}},
   { "cast(9999999999999999999.9999999999999999999 as decimal(38,19)) / "
     "cast(99999999999999999999999999999.999999999 as decimal(38,9))",
-    {{ false, 1000000000, 38, 19 },
-     { false,          1, 38, 10 }}},
+    {{ false, false, 1000000000, 38, 19 },
+     { false, false,          1, 38, 10 }}},
   { "cast(999999999999999999999999999999999999.99 as decimal(38,2)) / "
     "cast(99999999999.999999999999999999999999999 as decimal(38,27))",
-    {{ true,  0, 38, 27 },
-     { false, static_cast<int128_t>(10) * 10000000000ll *
+    {{ false, true,  0, 38, 27 },
+     { false, false, static_cast<int128_t>(10) * 10000000000ll *
        10000000000ll * 10000000000ll, 38, 6 }}},
   { "cast(-2.12 as decimal(17,2)) / cast(12515.95 as decimal(17,2))",
-    {{ false, -16938386618674571, 37, 20 }}},
+    {{ false, false, -16938386618674571, 37, 20 }}},
   { "cast(-2.12 as decimal(18,2)) / cast(12515.95 as decimal(18,2))",
-    {{ false,                  0, 38,  2 },
-     { false, -16938386618674571, 38, 20 }}},
+    {{ false, false,                  0, 38,  2 },
+     { false, false, -16938386618674571, 38, 20 }}},
   { "cast(737373 as decimal(6,0)) / cast(.52525252 as decimal(38,38))",
-    {{ true,              0, 38, 38 },
-     { false, 1403844764038, 38,  6 }}},
+    {{ false, true,              0, 38, 38 },
+     { false, false, 1403844764038, 38,  6 }}},
   { "cast(0.000001 as decimal(6,6)) / "
     "cast(0.0000000000000000000000000000000000001 as decimal(38,38))",
-    {{ true, 0, 38, 38 },
-     { false, static_cast<int128_t>(10000000ll) *
+    {{ false, true, 0, 38, 38 },
+     { false, false, static_cast<int128_t>(10000000ll) *
        10000000000ll * 10000000000ll * 10000000000ll, 38, 6 }}},
   { "cast(98765432109876543210 as decimal(20,0)) / "
     "cast(98765432109876543211 as decimal(20,0))",
-    {{ false,                   0, 38,  0 },
-     { false, 1000000000000000000, 38, 18 }}},
+    {{ false, false,                   0, 38,  0 },
+     { false, false, 1000000000000000000, 38, 18 }}},
   { "cast(111111.1111 as decimal(20, 10)) / cast(.7777 as decimal(38, 38))",
-    {{ true,             0, 38, 38 },
-     { false, 142871429986, 38,  6 }}},
+    {{ false, true,             0, 38, 38 },
+     { false, false, 142871429986, 38,  6 }}},
   { "2.0 / 3.0",
-    {{ false,   6666, 6, 4},
-     { false, 666667, 8, 6}}},
+    {{ false, false,   6666, 6, 4},
+     { false, false, 666667, 8, 6}}},
   { "-2.0 / 3.0",
-    {{ false,   -6666, 6, 4},
-     { false, -666667, 8, 6}}},
+    {{ false, false,   -6666, 6, 4},
+     { false, false, -666667, 8, 6}}},
   { "2.0 / -3.0",
-    {{ false,   -6666, 6, 4},
-     { false, -666667, 8, 6}}},
+    {{ false, false,   -6666, 6, 4},
+     { false, false, -666667, 8, 6}}},
   { "-2.0 / -3.0",
-    {{ false,   6666, 6, 4},
-     { false, 666667, 8, 6}}},
+    {{ false, false,   6666, 6, 4},
+     { false, false, 666667, 8, 6}}},
   // Test divide rounding
   { "10.10 / 3.0",
-    {{ false, 336666, 8, 5 },
-     { false, 3366667, 9, 6 }}},
+    {{ false, false, 336666, 8, 5 },
+     { false, false, 3366667, 9, 6 }}},
   { "cast(-10.10 as decimal(4,2)) / 3.0", // XXX JIRA: IMPALA-4877
-    {{ false, -336666, 8, 5 },
-     { false, -3366667, 9, 6 }}},
+    {{ false, false, -336666, 8, 5 },
+     { false, false, -3366667, 9, 6 }}},
   { "10.10 / 20.3",
-    {{ false, 497536, 9, 6 },
-     { false, 497537, 9, 6 }}},
+    {{ false, false, 497536, 9, 6 },
+     { false, false, 497537, 9, 6 }}},
   { "10.10 / -20.3",
-    {{ false, -497536, 9, 6 },
-     { false, -497537, 9, 6 }}},
+    {{ false, false, -497536, 9, 6 },
+     { false, false, -497537, 9, 6 }}},
   // N.B. - Google and python both insist that 999999.998 / 999 is 1001.000999
   // However, multiplying the result back, 999 * 1001.000998999 gives the
   // original value exactly, while their answer does not, 999 * 10001.000999 =
   // 999999.998001. The same issue comes up many times during the following
   // computations.  Division is hard, let's go shopping.
   { "cast(999999.998 as decimal(9,3)) / 999",
-    {{ false, 1001000998998, 15, 9 },
-     { false, 1001000998999, 15, 9 }}},
+    {{ false, false, 1001000998998, 15, 9 },
+     { false, false, 1001000998999, 15, 9 }}},
   { "cast(999.999998 as decimal(9,3)) / 999",
-    {{ false, 1001000000, 15, 9 },
-     { false, 1001001001, 15, 9 }}},
+    {{ false, false, 1001000000, 15, 9 },
+     { false, false, 1001001001, 15, 9 }}},
   { "cast(999.999998 as decimal(9,6)) / 999",
-    {{ false, 1001000998998, 15, 12 },
-     { false, 1001000998999, 15, 12 }}},
+    {{ false, false, 1001000998998, 15, 12 },
+     { false, false, 1001000998999, 15, 12 }}},
   { "cast(0.999999998 as decimal(9,6)) / 999",
-    {{ false, 1001000000, 15, 12 },
-     { false, 1001001001, 15, 12 }}},
+    {{ false, false, 1001000000, 15, 12 },
+     { false, false, 1001001001, 15, 12 }}},
   { "cast(0.999999998 as decimal(9,9)) / 999",
-    {{ false, 1001000998998, 15, 15 },
-     { false, 1001000998999, 15, 15 }}},
+    {{ false, false, 1001000998998, 15, 15 },
+     { false, false, 1001000998999, 15, 15 }}},
   { "cast(-999999.998 as decimal(9,3)) / 999",
-    {{ false, -1001000998998, 15, 9 },
-     { false, -1001000998999, 15, 9 }}},
+    {{ false, false, -1001000998998, 15, 9 },
+     { false, false, -1001000998999, 15, 9 }}},
   { "cast(-999.999998 as decimal(9,3)) / 999",
-    {{ false, -1001000000, 15, 9 },
-     { false, -1001001001, 15, 9 }}},
+    {{ false, false, -1001000000, 15, 9 },
+     { false, false, -1001001001, 15, 9 }}},
   { "cast(-999.999998 as decimal(9,6)) / 999",
-    {{ false, -1001000998998, 15, 12 },
-     { false, -1001000998999, 15, 12 }}},
+    {{ false, false, -1001000998998, 15, 12 },
+     { false, false, -1001000998999, 15, 12 }}},
   { "cast(-0.999999998 as decimal(9,6)) / 999",
-    {{ false, -1001000000, 15, 12 },
-     { false, -1001001001, 15, 12 }}},
+    {{ false, false, -1001000000, 15, 12 },
+     { false, false, -1001001001, 15, 12 }}},
   { "cast(-0.999999998 as decimal(9,9)) / 999",
-    {{ false, -1001000998998, 15, 15 },
-     { false, -1001000998999, 15, 15 }}},
+    {{ false, false, -1001000998998, 15, 15 },
+     { false, false, -1001000998999, 15, 15 }}},
   { "cast(-999999.998 as decimal(9,3)) / -999",
-    {{ false, 1001000998998, 15, 9 },
-     { false, 1001000998999, 15, 9 }}},
+    {{ false, false, 1001000998998, 15, 9 },
+     { false, false, 1001000998999, 15, 9 }}},
   { "cast(-999.999998 as decimal(9,3)) / -999",
-    {{ false, 1001000000, 15, 9 },
-     { false, 1001001001, 15, 9 }}},
+    {{ false, false, 1001000000, 15, 9 },
+     { false, false, 1001001001, 15, 9 }}},
   { "cast(-999.999998 as decimal(9,6)) / -999",
-    {{ false, 1001000998998, 15, 12 },
-     { false, 1001000998999, 15, 12 }}},
+    {{ false, false, 1001000998998, 15, 12 },
+     { false, false, 1001000998999, 15, 12 }}},
   { "cast(-0.999999998 as decimal(9,6)) / -999",
-    {{ false, 1001000000, 15, 12 },
-     { false, 1001001001, 15, 12 }}},
+    {{ false, false, 1001000000, 15, 12 },
+     { false, false, 1001001001, 15, 12 }}},
   { "cast(-0.999999998 as decimal(9,9)) / -999",
-    {{ false, 1001000998998, 15, 15 },
-     { false, 1001000998999, 15, 15 }}},
+    {{ false, false, 1001000998998, 15, 15 },
+     { false, false, 1001000998999, 15, 15 }}},
   { "cast(999999.998 as decimal(9,3)) / -999",
-    {{ false, -1001000998998, 15, 9 },
-     { false, -1001000998999, 15, 9 }}},
+    {{ false, false, -1001000998998, 15, 9 },
+     { false, false, -1001000998999, 15, 9 }}},
   { "cast(999.999998 as decimal(9,3)) / -999",
-    {{ false, -1001000000, 15, 9 },
-     { false, -1001001001, 15, 9 }}},
+    {{ false, false, -1001000000, 15, 9 },
+     { false, false, -1001001001, 15, 9 }}},
   { "cast(999.999998 as decimal(9,6)) / -999",
-    {{ false, -1001000998998, 15, 12 },
-     { false, -1001000998999, 15, 12 }}},
+    {{ false, false, -1001000998998, 15, 12 },
+     { false, false, -1001000998999, 15, 12 }}},
   { "cast(0.999999998 as decimal(9,6)) / -999",
-    {{ false, -1001000000, 15, 12 },
-     { false, -1001001001, 15, 12 }}},
+    {{ false, false, -1001000000, 15, 12 },
+     { false, false, -1001001001, 15, 12 }}},
   { "cast(0.999999998 as decimal(9,9)) / -999",
-    {{ false, -1001000998998, 15, 15 },
-     { false, -1001000998999, 15, 15 }}},
+    {{ false, false, -1001000998998, 15, 15 },
+     { false, false, -1001000998999, 15, 15 }}},
   { "cast(999.999998 as decimal(9,3)) / 999999999",
-    {{ false, 99999900, 20, 14 },
-     { false, 100000000, 20, 14 }}},
+    {{ false, false, 99999900, 20, 14 },
+     { false, false, 100000000, 20, 14 }}},
   { "cast(999.999998 as decimal(9,6)) / 999999999",
-    {{ false, 99999999899, 20, 17 },
-     { false, 99999999900, 20, 17 }}},
+    {{ false, false, 99999999899, 20, 17 },
+     { false, false, 99999999900, 20, 17 }}},
   { "cast(0.999999998 as decimal(9,6)) / 999999999",
-    {{ false, 99999900, 20, 17 },
-     { false, 100000000, 20, 17 }}},
+    {{ false, false, 99999900, 20, 17 },
+     { false, false, 100000000, 20, 17 }}},
   { "cast(0.999999998 as decimal(9,9)) / 999999999",
-    {{ false, 99999999899, 20, 20 },
-     { false, 99999999900, 20, 20 }}},
+    {{ false, false, 99999999899, 20, 20 },
+     { false, false, 99999999900, 20, 20 }}},
   { "cast(-999999.998 as decimal(9,3)) / 999999999",
-    {{ false, -99999999899, 20, 14 },
-     { false, -99999999900, 20, 14 }}},
+    {{ false, false, -99999999899, 20, 14 },
+     { false, false, -99999999900, 20, 14 }}},
   { "cast(-999.999998 as decimal(9,3)) / 999999999",
-    {{ false, -99999900, 20, 14 },
-     { false, -100000000, 20, 14 }}},
+    {{ false, false, -99999900, 20, 14 },
+     { false, false, -100000000, 20, 14 }}},
   { "cast(-999.999998 as decimal(9,6)) / 999999999",
-    {{ false, -99999999899, 20, 17 },
-     { false, -99999999900, 20, 17 }}},
+    {{ false, false, -99999999899, 20, 17 },
+     { false, false, -99999999900, 20, 17 }}},
   { "cast(-0.999999998 as decimal(9,6)) / 999999999",
-    {{ false, -99999900, 20, 17 },
-     { false, -100000000, 20, 17 }}},
+    {{ false, false, -99999900, 20, 17 },
+     { false, false, -100000000, 20, 17 }}},
   { "cast(-0.999999998 as decimal(9,9)) / 999999999",
-    {{ false, -99999999899, 20, 20 },
-     { false, -99999999900, 20, 20 }}},
+    {{ false, false, -99999999899, 20, 20 },
+     { false, false, -99999999900, 20, 20 }}},
   { "cast(-999999.998 as decimal(9,3)) / 999999999",
-    {{ false, -99999999899, 20, 14 },
-     { false, -99999999900, 20, 14 }}},
+    {{ false, false, -99999999899, 20, 14 },
+     { false, false, -99999999900, 20, 14 }}},
   { "cast(-999.999998 as decimal(9,3)) / 999999999",
-    {{ false, -99999900, 20, 14 },
-     { false, -100000000, 20, 14 }}},
+    {{ false, false, -99999900, 20, 14 },
+     { false, false, -100000000, 20, 14 }}},
   { "cast(-999.999998 as decimal(9,6)) / 999999999",
-    {{ false, -99999999899, 20, 17 },
-     { false, -99999999900, 20, 17 }}},
+    {{ false, false, -99999999899, 20, 17 },
+     { false, false, -99999999900, 20, 17 }}},
   { "cast(-0.999999998 as decimal(9,6)) / 999999999",
-    {{ false, -99999900, 20, 17 },
-     { false, -100000000, 20, 17 }}},
+    {{ false, false, -99999900, 20, 17 },
+     { false, false, -100000000, 20, 17 }}},
   { "cast(-0.999999998 as decimal(9,9)) / 999999999",
-    {{ false, -99999999899, 20, 20 },
-     { false, -99999999900, 20, 20 }}},
+    {{ false, false, -99999999899, 20, 20 },
+     { false, false, -99999999900, 20, 20 }}},
   { "cast(999999.998 as decimal(9,3)) / -999999999",
-    {{ false, -99999999899, 20, 14 },
-     { false, -99999999900, 20, 14 }}},
+    {{ false, false, -99999999899, 20, 14 },
+     { false, false, -99999999900, 20, 14 }}},
   { "cast(999.999998 as decimal(9,3)) / -999999999",
-    {{ false, -99999900, 20, 14 },
-     { false, -100000000, 20, 14 }}},
+    {{ false, false, -99999900, 20, 14 },
+     { false, false, -100000000, 20, 14 }}},
   { "cast(999.999998 as decimal(9,6)) / -999999999",
-    {{ false, -99999999899, 20, 17 },
-     { false, -99999999900, 20, 17 }}},
+    {{ false, false, -99999999899, 20, 17 },
+     { false, false, -99999999900, 20, 17 }}},
   { "cast(0.999999998 as decimal(9,6)) / -999999999",
-    {{ false, -99999900, 20, 17 },
-     { false, -100000000, 20, 17 }}},
+    {{ false, false, -99999900, 20, 17 },
+     { false, false, -100000000, 20, 17 }}},
   { "cast(0.999999998 as decimal(9,9)) / -999999999",
-    {{ false, -99999999899, 20, 20 },
-     { false, -99999999900, 20, 20 }}},
+    {{ false, false, -99999999899, 20, 20 },
+     { false, false, -99999999900, 20, 20 }}},
   { "17014118346046923173168730371588.410/17014118346046923173168730371588.410",
-    {{ false, 1000, 38, 3 },
-     { false, 1000000, 38, 6 }}},
+    {{ false, false, 1000, 38, 3 },
+     { false, false, 1000000, 38, 6 }}},
   { "17014118346046923173168730371588.410/17014118346046923173168730371588.409",
-    {{ false, 1000, 38, 3 },
-     { false, 1000000, 38, 6 }}},
+    {{ false, false, 1000, 38, 3 },
+     { false, false, 1000000, 38, 6 }}},
   { "17014118346046923173168730371588.410/34028236692093846346337460743176820000",
-    {{ false, 0, 38, 3 },
-     { false, 1, 38, 6 }}},
+    {{ false, false, 0, 38, 3 },
+     { false, false, 1, 38, 6 }}},
   { "17014118346046923173168730371588.410/34028236692093846346337460743176820001",
-    {{ false, 0, 38, 3 },
-     { false, 0, 38, 6 }}},
+    {{ false, false, 0, 38, 3 },
+     { false, false, 0, 38, 6 }}},
   { "17014118346046923173168730371588.410/51042355038140769519506191114765230000",
-    {{ false, 0, 38, 3 },
-     { false, 0, 38, 6 }}},
+    {{ false, false, 0, 38, 3 },
+     { false, false, 0, 38, 6 }}},
   { "17014118346046923173168730371588.410/10208471007628153903901238222953046343",
-    {{ false, 0, 38, 3 },
-     { false, 2, 38, 6 }}},
+    {{ false, false, 0, 38, 3 },
+     { false, false, 2, 38, 6 }}},
   { "170141183460469231731687303715884.10/34028236692093846346337460743176820000",
-    {{ false, 0, 38, 2 },
-     { false, 5, 38, 6 }}},
+    {{ false, false, 0, 38, 2 },
+     { false, false, 5, 38, 6 }}},
   { "170141183460469231731687303715884.10/34028236692093846346337460743176820001",
-    {{ false, 0, 38, 2 },
-     { false, 5, 38, 6 }}},
+    {{ false, false, 0, 38, 2 },
+     { false, false, 5, 38, 6 }}},
   { "170141183460469231731687303715884.10/51042355038140769519506191114765230000",
-    {{ false, 0, 38, 2 },
-     { false, 3, 38, 6 }}},
+    {{ false, false, 0, 38, 2 },
+     { false, false, 3, 38, 6 }}},
   { "170141183460469231731687303715884.10/10208471007628153903901238222953046343",
-    {{ false, 0, 38, 2 },
-     { false, 17, 38, 6 }}},
+    {{ false, false, 0, 38, 2 },
+     { false, false, 17, 38, 6 }}},
   { "1701411834604692317316873037158841.0/34028236692093846346337460743176820000",
-    {{ false, 0, 38, 1 },
-     { false, 50, 38, 6 }}},
+    {{ false, false, 0, 38, 1 },
+     { false, false, 50, 38, 6 }}},
   { "1701411834604692317316873037158841.0/34028236692093846346337460743176820001",
-    {{ false, 0, 38, 1 },
-     { false, 50, 38, 6 }}},
+    {{ false, false, 0, 38, 1 },
+     { false, false, 50, 38, 6 }}},
   { "1701411834604692317316873037158841.0/51042355038140769519506191114765229999",
-    {{ false, 0, 38, 1 },
-     { false, 33, 38, 6 }}},
+    {{ false, false, 0, 38, 1 },
+     { false, false, 33, 38, 6 }}},
   { "1701411834604692317316873037158841.0/10208471007628153903901238222953046343",
-    {{ false, 0, 38, 1 },
-     { false, 167, 38, 6 }}},
+    {{ false, false, 0, 38, 1 },
+     { false, false, 167, 38, 6 }}},
   { "17014118346046923173168730371588410/34028236692093846346337460743176820000",
-    {{ false, 0, 38, 0 },
-     { false, 500, 38, 6 }}},
+    {{ false, false, 0, 38, 0 },
+     { false, false, 500, 38, 6 }}},
   { "17014118346046923173168730371588410/34028236692093846346337460743176820001",
-    {{ false, 0, 38, 0 },
-     { false, 500, 38, 6 }}},
+    {{ false, false, 0, 38, 0 },
+     { false, false, 500, 38, 6 }}},
   { "17014118346046923173168730371588410/51042355038140769519506191114765229999",
-    {{ false, 0, 38, 0 },
-     { false, 333, 38, 6 }}},
+    {{ false, false, 0, 38, 0 },
+     { false, false, 333, 38, 6 }}},
   { "17014118346046923173168730371588410/10208471007628153903901238222953046343",
-    {{ false, 0, 38, 0 },
-     { false, 1667, 38, 6 }}},
+    {{ false, false, 0, 38, 0 },
+     { false, false, 1667, 38, 6 }}},
   { "17014118346046923173168730371588410/3402823669209384634633746074317682000.0",
-    {{ false, 0, 38, 1 },
-     { false, 5000, 38, 6 }}},
+    {{ false, false, 0, 38, 1 },
+     { false, false, 5000, 38, 6 }}},
   { "17014118346046923173168730371588410/3402823669209384634633746074317682000.1",
-    {{ false, 0, 38, 1 },
-     { false, 5000, 38, 6 }}},
+    {{ false, false, 0, 38, 1 },
+     { false, false, 5000, 38, 6 }}},
   { "17014118346046923173168730371588410/5104235503814076951950619111476522999.9",
-    {{ false, 0, 38, 1 },
-     { false, 3333, 38, 6 }}},
+    {{ false, false, 0, 38, 1 },
+     { false, false, 3333, 38, 6 }}},
   { "17014118346046923173168730371588410/1020847100762815390390123822295304634.3",
-    {{ false, 0, 38, 1 },
-     { false, 16667, 38, 6 }}},
+    {{ false, false, 0, 38, 1 },
+     { false, false, 16667, 38, 6 }}},
   { "15014118346046923173168730371588.410/34028236692093846346337460743176820000",
-    {{ false, 0, 38, 3 },
-     { false, 0, 38, 6 }}},
+    {{ false, false, 0, 38, 3 },
+     { false, false, 0, 38, 6 }}},
   { "150141183460469231731687303715884.10/34028236692093846346337460743176820000",
-    {{ false, 0, 38, 2 },
-     { false, 4, 38, 6 }}},
+    {{ false, false, 0, 38, 2 },
+     { false, false, 4, 38, 6 }}},
   { "1501411834604692317316873037158841.0/34028236692093846346337460743176820000",
-    {{ false, 0, 38, 1 },
-     { false, 44, 38, 6 }}},
+    {{ false, false, 0, 38, 1 },
+     { false, false, 44, 38, 6 }}},
   { "15014118346046923173168730371588410/34028236692093846346337460743176820000",
-    {{ false, 0, 38, 0 },
-     { false, 441, 38, 6 }}},
+    {{ false, false, 0, 38, 0 },
+     { false, false, 441, 38, 6 }}},
   { "16014118346046923173168730371588.410/34028236692093846346337460743176820000",
-    {{ false, 0, 38, 3 },
-     { false, 0, 38, 6 }}},
+    {{ false, false, 0, 38, 3 },
+     { false, false, 0, 38, 6 }}},
   { "160141183460469231731687303715884.10/34028236692093846346337460743176820000",
-    {{ false, 0, 38, 2 },
-     { false, 5, 38, 6 }}},
+    {{ false, false, 0, 38, 2 },
+     { false, false, 5, 38, 6 }}},
   { "1601411834604692317316873037158841.0/34028236692093846346337460743176820000",
-    {{ false, 0, 38, 1 },
-     { false, 47, 38, 6 }}},
+    {{ false, false, 0, 38, 1 },
+     { false, false, 47, 38, 6 }}},
   { "16014118346046923173168730371588410/34028236692093846346337460743176820000",
-    {{ false, 0, 38, 0 },
-     { false, 471, 38, 6 }}},
+    {{ false, false, 0, 38, 0 },
+     { false, false, 471, 38, 6 }}},
   { "16014118346046923173168730371588410/3402823669209384634633746074317682000",
-    {{ false, 0, 38, 0 },
-     { false, 4706, 38, 6 }}},
+    {{ false, false, 0, 38, 0 },
+     { false, false, 4706, 38, 6 }}},
   { "18014118346046923173168730371588.410/34028236692093846346337460743176820000",
-    {{ false, 0, 38, 3 },
-     { false, 1, 38, 6 }}},
+    {{ false, false, 0, 38, 3 },
+     { false, false, 1, 38, 6 }}},
   { "180141183460469231731687303715884.10/34028236692093846346337460743176820000",
-    {{ false, 0, 38, 2 },
-     { false, 5, 38, 6 }}},
+    {{ false, false, 0, 38, 2 },
+     { false, false, 5, 38, 6 }}},
   { "1801411834604692317316873037158841.0/34028236692093846346337460743176820000",
-    {{ false, 0, 38, 1 },
-     { false, 53, 38, 6 }}},
+    {{ false, false, 0, 38, 1 },
+     { false, false, 53, 38, 6 }}},
   { "18014118346046923173168730371588410/34028236692093846346337460743176820000",
-    {{ false, 0, 38, 0 },
-     { false, 529, 38, 6 }}},
+    {{ false, false, 0, 38, 0 },
+     { false, false, 529, 38, 6 }}},
   { "18014118346046923173168730371588410/3402823669209384634633746074317682000",
-    {{ false, 0, 38, 0 },
-     { false, 5294, 38, 6 }}},
+    {{ false, false, 0, 38, 0 },
+     { false, false, 5294, 38, 6 }}},
   { "18014118346046923173168730371588410/340282366920938463463374607431768200",
-    {{ false, 0, 38, 0 },
-     { false, 52939, 38, 6 }}},
+    {{ false, false, 0, 38, 0 },
+     { false, false, 52939, 38, 6 }}},
   { "17014118346046923173168730371588.410/-17014118346046923173168730371588.410",
-    {{ false, -1000, 38, 3 },
-     { false, -1000000, 38, 6 }}},
+    {{ false, false, -1000, 38, 3 },
+     { false, false, -1000000, 38, 6 }}},
   { "17014118346046923173168730371588.410/-17014118346046923173168730371588.409",
-    {{ false, -1000, 38, 3 },
-     { false, -1000000, 38, 6 }}},
+    {{ false, false, -1000, 38, 3 },
+     { false, false, -1000000, 38, 6 }}},
   { "17014118346046923173168730371588.410/-34028236692093846346337460743176820000",
-    {{ false, 0, 38, 3 },
-     { false, -1, 38, 6 }}},
+    {{ false, false, 0, 38, 3 },
+     { false, false, -1, 38, 6 }}},
   { "17014118346046923173168730371588.410/-34028236692093846346337460743176820001",
-    {{ false, 0, 38, 3 },
-     { false, 0, 38, 6 }}},
+    {{ false, false, 0, 38, 3 },
+     { false, false, 0, 38, 6 }}},
   { "17014118346046923173168730371588.410/-51042355038140769519506191114765230000",
-    {{ false, 0, 38, 3 },
-     { false, 0, 38, 6 }}},
+    {{ false, false, 0, 38, 3 },
+     { false, false, 0, 38, 6 }}},
   { "17014118346046923173168730371588.410/-10208471007628153903901238222953046343",
-    {{ false, 0, 38, 3 },
-     { false, -2, 38, 6 }}},
+    {{ false, false, 0, 38, 3 },
+     { false, false, -2, 38, 6 }}},
   { "170141183460469231731687303715884.10/-34028236692093846346337460743176820000",
-    {{ false, 0, 38, 2 },
-     { false, -5, 38, 6 }}},
+    {{ false, false, 0, 38, 2 },
+     { false, false, -5, 38, 6 }}},
   { "170141183460469231731687303715884.10/-34028236692093846346337460743176820001",
-    {{ false, 0, 38, 2 },
-     { false, -5, 38, 6 }}},
+    {{ false, false, 0, 38, 2 },
+     { false, false, -5, 38, 6 }}},
   { "170141183460469231731687303715884.10/-51042355038140769519506191114765230000",
-    {{ false, 0, 38, 2 },
-     { false, -3, 38, 6 }}},
+    {{ false, false, 0, 38, 2 },
+     { false, false, -3, 38, 6 }}},
   { "170141183460469231731687303715884.10/-10208471007628153903901238222953046343",
-    {{ false, 0, 38, 2 },
-     { false, -17, 38, 6 }}},
+    {{ false, false, 0, 38, 2 },
+     { false, false, -17, 38, 6 }}},
   { "1701411834604692317316873037158841.0/-34028236692093846346337460743176820000",
-    {{ false, 0, 38, 1 },
-     { false, -50, 38, 6 }}},
+    {{ false, false, 0, 38, 1 },
+     { false, false, -50, 38, 6 }}},
   { "1701411834604692317316873037158841.0/-34028236692093846346337460743176820001",
-    {{ false, 0, 38, 1 },
-     { false, -50, 38, 6 }}},
+    {{ false, false, 0, 38, 1 },
+     { false, false, -50, 38, 6 }}},
   { "1701411834604692317316873037158841.0/-51042355038140769519506191114765229999",
-    {{ false, 0, 38, 1 },
-     { false, -33, 38, 6 }}},
+    {{ false, false, 0, 38, 1 },
+     { false, false, -33, 38, 6 }}},
   { "1701411834604692317316873037158841.0/-10208471007628153903901238222953046343",
-    {{ false, 0, 38, 1 },
-     { false, -167, 38, 6 }}},
+    {{ false, false, 0, 38, 1 },
+     { false, false, -167, 38, 6 }}},
   { "17014118346046923173168730371588410/-34028236692093846346337460743176820000",
-    {{ false, 0, 38, 0 },
-     { false, -500, 38, 6 }}},
+    {{ false, false, 0, 38, 0 },
+     { false, false, -500, 38, 6 }}},
   { "17014118346046923173168730371588410/-34028236692093846346337460743176820001",
-    {{ false, 0, 38, 0 },
-     { false, -500, 38, 6 }}},
+    {{ false, false, 0, 38, 0 },
+     { false, false, -500, 38, 6 }}},
   { "17014118346046923173168730371588410/-51042355038140769519506191114765229999",
-    {{ false, 0, 38, 0 },
-     { false, -333, 38, 6 }}},
+    {{ false, false, 0, 38, 0 },
+     { false, false, -333, 38, 6 }}},
   { "17014118346046923173168730371588410/-10208471007628153903901238222953046343",
-    {{ false, 0, 38, 0 },
-     { false, -1667, 38, 6 }}},
+    {{ false, false, 0, 38, 0 },
+     { false, false, -1667, 38, 6 }}},
   { "17014118346046923173168730371588410/-3402823669209384634633746074317682000.0",
-    {{ false, 0, 38, 1 },
-     { false, -5000, 38, 6 }}},
+    {{ false, false, 0, 38, 1 },
+     { false, false, -5000, 38, 6 }}},
   { "17014118346046923173168730371588410/-3402823669209384634633746074317682000.1",
-    {{ false, 0, 38, 1 },
-     { false, -5000, 38, 6 }}},
+    {{ false, false, 0, 38, 1 },
+     { false, false, -5000, 38, 6 }}},
   { "17014118346046923173168730371588410/-5104235503814076951950619111476522999.9",
-    {{ false, 0, 38, 1 },
-     { false, -3333, 38, 6 }}},
+    {{ false, false, 0, 38, 1 },
+     { false, false, -3333, 38, 6 }}},
   { "17014118346046923173168730371588410/-1020847100762815390390123822295304634.3",
-    {{ false, 0, 38, 1 },
-     { false, -16667, 38, 6 }}},
+    {{ false, false, 0, 38, 1 },
+     { false, false, -16667, 38, 6 }}},
   { "15014118346046923173168730371588.410/-34028236692093846346337460743176820000",
-    {{ false, 0, 38, 3 },
-     { false, 0, 38, 6 }}},
+    {{ false, false, 0, 38, 3 },
+     { false, false, 0, 38, 6 }}},
   { "150141183460469231731687303715884.10/-34028236692093846346337460743176820000",
-    {{ false, 0, 38, 2 },
-     { false, -4, 38, 6 }}},
+    {{ false, false, 0, 38, 2 },
+     { false, false, -4, 38, 6 }}},
   { "1501411834604692317316873037158841.0/-34028236692093846346337460743176820000",
-    {{ false, 0, 38, 1 },
-     { false, -44, 38, 6 }}},
+    {{ false, false, 0, 38, 1 },
+     { false, false, -44, 38, 6 }}},
   { "15014118346046923173168730371588410/-34028236692093846346337460743176820000",
-    {{ false, 0, 38, 0 },
-     { false, -441, 38, 6 }}},
+    {{ false, false, 0, 38, 0 },
+     { false, false, -441, 38, 6 }}},
   { "16014118346046923173168730371588.410/-34028236692093846346337460743176820000",
-    {{ false, 0, 38, 3 },
-     { false, 0, 38, 6 }}},
+    {{ false, false, 0, 38, 3 },
+     { false, false, 0, 38, 6 }}},
   { "160141183460469231731687303715884.10/-34028236692093846346337460743176820000",
-    {{ false, 0, 38, 2 },
-     { false, -5, 38, 6 }}},
+    {{ false, false, 0, 38, 2 },
+     { false, false, -5, 38, 6 }}},
   { "1601411834604692317316873037158841.0/-34028236692093846346337460743176820000",
-    {{ false, 0, 38, 1 },
-     { false, -47, 38, 6 }}},
+    {{ false, false, 0, 38, 1 },
+     { false, false, -47, 38, 6 }}},
   { "16014118346046923173168730371588410/-34028236692093846346337460743176820000",
-    {{ false, 0, 38, 0 },
-     { false, -471, 38, 6 }}},
+    {{ false, false, 0, 38, 0 },
+     { false, false, -471, 38, 6 }}},
   { "16014118346046923173168730371588410/-3402823669209384634633746074317682000",
-    {{ false, 0, 38, 0 },
-     { false, -4706, 38, 6 }}},
+    {{ false, false, 0, 38, 0 },
+     { false, false, -4706, 38, 6 }}},
   { "18014118346046923173168730371588.410/-34028236692093846346337460743176820000",
-    {{ false, 0, 38, 3 },
-     { false, -1, 38, 6 }}},
+    {{ false, false, 0, 38, 3 },
+     { false, false, -1, 38, 6 }}},
   { "180141183460469231731687303715884.10/-34028236692093846346337460743176820000",
-    {{ false, 0, 38, 2 },
-     { false, -5, 38, 6 }}},
+    {{ false, false, 0, 38, 2 },
+     { false, false, -5, 38, 6 }}},
   { "1801411834604692317316873037158841.0/-34028236692093846346337460743176820000",
-    {{ false, 0, 38, 1 },
-     { false, -53, 38, 6 }}},
+    {{ false, false, 0, 38, 1 },
+     { false, false, -53, 38, 6 }}},
   { "18014118346046923173168730371588410/-34028236692093846346337460743176820000",
-    {{ false, 0, 38, 0 },
-     { false, -529, 38, 6 }}},
+    {{ false, false, 0, 38, 0 },
+     { false, false, -529, 38, 6 }}},
   { "18014118346046923173168730371588410/-3402823669209384634633746074317682000",
-    {{ false, 0, 38, 0 },
-     { false, -5294, 38, 6 }}},
+    {{ false, false, 0, 38, 0 },
+     { false, false, -5294, 38, 6 }}},
   { "18014118346046923173168730371588410/-340282366920938463463374607431768200",
-    {{ false, 0, 38, 0 },
-     { false, -52939, 38, 6 }}},
+    {{ false, false, 0, 38, 0 },
+     { false, false, -52939, 38, 6 }}},
   // Test modulo operator
-  { "cast(1.23 as decimal(8,2)) % cast(1 as decimal(10,3))", {{ false, 230, 9, 3 }}},
-  { "cast(1 as decimal(38,0)) % cast(.2 as decimal(38,1))", {{ false, 0, 38, 1 }}},
-  { "cast(1 as decimal(38,0)) % cast(3 as decimal(38,0))", {{ false, 1, 38, 0 }}},
+  { "cast(1.23 as decimal(8,2)) % cast(1 as decimal(10,3))",
+    {{ false, false, 230, 9, 3 }}},
+  { "cast(1 as decimal(38,0)) % cast(.2 as decimal(38,1))",
+    {{ false, false, 0, 38, 1 }}},
+  { "cast(1 as decimal(38,0)) % cast(3 as decimal(38,0))",
+    {{ false, false, 1, 38, 0 }}},
   { "cast(-2.12 as decimal(17,2)) % cast(12515.95 as decimal(17,2))",
-    {{ false, -212, 17, 2 }}},
+    {{ false, false, -212, 17, 2 }}},
   { "cast(-2.12 as decimal(18,2)) % cast(12515.95 as decimal(18,2))",
-    {{ false, -212, 18, 2 }}},
+    {{ false, false, -212, 18, 2 }}},
   { "cast(99999999999999999999999999999999999999 as decimal(38,0)) % "
     "cast(99999999999999999999999999999999999999 as decimal(38,0))",
-    {{ false, 0, 38, 0 }}},
+    {{ false, false, 0, 38, 0 }}},
   { "cast(998 as decimal(38,0)) % cast(0.999 as decimal(38,38))",
-    {{ true, 0, 38, 38 },   // IMPALA-4964 - this should not overflow
-     { true, 0, 38, 38 }}},
+    {{ false, true, 0, 38, 38 },   // IMPALA-4964 - this should not overflow
+     { false, true, 0, 38, 38 }}},
   { "cast(0.998 as decimal(38,38)) % cast(999 as decimal(38,0))",
-    {{ true, 0, 38, 38 },   // IMPALA-4964 - this should not overflow
-     { true, 0, 38, 38 }}},
+    {{ false, true, 0, 38, 38 },   // IMPALA-4964 - this should not overflow
+     { false, true, 0, 38, 38 }}},
   { "cast(0.00000000000000000000000000000000000001 as decimal(38,38)) % "
     "cast(0.0000000000000000000000000000000000001 as decimal(38,38))",
-    {{ false, 1, 38, 38 }}},
+    {{ false, false, 1, 38, 38 }}},
   // Test MOD builtin
-  { "mod(cast('1' as decimal(2,0)), cast('10' as decimal(2,0)))", {{ false, 1, 2, 0 }}},
-  { "mod(cast('1.1' as decimal(2,1)), cast('1.0' as decimal(2,1)))", {{ false, 1, 2, 1 }}},
+  { "mod(cast('1' as decimal(2,0)), cast('10' as decimal(2,0)))",
+    {{ false, false, 1, 2, 0 }}},
+  { "mod(cast('1.1' as decimal(2,1)), cast('1.0' as decimal(2,1)))",
+    {{ false, false, 1, 2, 1 }}},
   { "mod(cast('-1.23' as decimal(5,2)), cast('1.0' as decimal(5,2)))",
-    {{ false, -23, 5, 2 }}},
-  { "mod(cast('1' as decimal(12,0)), cast('10' as decimal(12,0)))", {{ false, 1, 12, 0 }}},
+    {{ false, false, -23, 5, 2 }}},
+  { "mod(cast('1' as decimal(12,0)), cast('10' as decimal(12,0)))",
+    {{ false, false, 1, 12, 0 }}},
   { "mod(cast('1.1' as decimal(12,1)), cast('1.0' as decimal(12,1)))",
-    {{ false, 1, 12, 1 }}},
+    {{ false, false, 1, 12, 1 }}},
   { "mod(cast('-1.23' as decimal(12,2)), cast('1.0' as decimal(12,2)))",
-    {{ false, -23, 12, 2 }}},
+    {{ false, false, -23, 12, 2 }}},
   { "mod(cast('1' as decimal(32,0)), cast('10' as decimal(32,0)))",
-    {{ false, 1, 32, 0 }}},
+    {{ false, false, 1, 32, 0 }}},
   { "mod(cast('1.1' as decimal(32,1)), cast('1.0' as decimal(32,1)))",
-    {{ false, 1, 32, 1 }}},
+    {{ false, false, 1, 32, 1 }}},
   { "mod(cast('-1.23' as decimal(32,2)), cast('1.0' as decimal(32,2)))",
-    {{ false, -23, 32, 2 }}},
-  { "mod(cast(NULL as decimal(2,0)), cast('10' as decimal(2,0)))", {{ true, 0, 2, 0 }}},
-  { "mod(cast('10' as decimal(2,0)), cast(NULL as decimal(2,0)))", {{ true, 0, 2, 0 }}},
-  { "mod(cast('10' as decimal(2,0)), cast('0' as decimal(2,0)))", {{ true, 0, 2, 0 }}},
-  { "mod(cast('10' as decimal(2,0)), cast('0' as decimal(2,0)))", {{ true, 0, 2, 0 }}},
-  { "mod(cast(NULL as decimal(2,0)), NULL)", {{ true, 0, 2, 0 }}},
+    {{ false, false, -23, 32, 2 }}},
+  { "mod(cast(NULL as decimal(2,0)), cast('10' as decimal(2,0)))",
+    {{ false, true, 0, 2, 0 }}},
+  { "mod(cast('10' as decimal(2,0)), cast(NULL as decimal(2,0)))",
+    {{ false, true, 0, 2, 0 }}},
+  { "mod(cast('10' as decimal(2,0)), cast('0' as decimal(2,0)))",
+    {{ false, true, 0, 2, 0 },
+     { true, false, 0, 2, 0 }}},
+  { "mod(cast('10' as decimal(2,0)), cast('0' as decimal(2,0)))",
+    {{ false, true, 0, 2, 0 },
+     { true, false, 0, 2, 0 }}},
+  { "cast('10' as decimal(2,0)) % cast('0' as decimal(2,0))",
+    {{ false, true, 0, 2, 0 },
+     { true, false, 0, 2, 0 }}},
+  { "cast('10' as decimal(2,0)) % cast('0' as decimal(38,19))",
+    {{ false, true, 0, 21, 19 },
+     { true, false, 0, 21, 19 }}},
+  { "cast('10' as decimal(2,0)) / cast('0' as decimal(2,0))",
+    {{ false, true, 0, 6, 4 },
+     { true, false, 0, 6, 4 }}},
+  { "cast('10' as decimal(2,0)) / cast('0' as decimal(38,19))",
+    {{ false, true, 0, 38, 19 },
+     { true, false, 0, 38, 19 }}},
+  { "mod(cast(NULL as decimal(2,0)), NULL)", {{ false, true, 0, 2, 0 }}},
   // Test CAST DECIMAL -> DECIMAL
   { "cast(cast(0.12344 as decimal(6,5)) as decimal(6,4))",
-    {{ false, 1234, 6, 4 }}},
+    {{ false, false, 1234, 6, 4 }}},
   { "cast(cast(0.12345 as decimal(6,5)) as decimal(6,4))",
-    {{ false, 1234, 6, 4 },
-     { false, 1235, 6, 4 }}},
+    {{ false, false, 1234, 6, 4 },
+     { false, false, 1235, 6, 4 }}},
   { "cast(cast('0.999' as decimal(4,3)) as decimal(1,0))",
-    {{ false, 0, 1, 0 },
-     { false, 1, 1, 0 }}},
+    {{ false, false, 0, 1, 0 },
+     { false, false, 1, 1, 0 }}},
   { "cast(cast(999999999.99 as DECIMAL(11,2)) as DECIMAL(9,0))",
-    {{ false, 999999999, 9, 0 },
-     { true, 0, 9, 0 }}},
+    {{ false, false, 999999999, 9, 0 },
+     { false, true, 0, 9, 0 }}},
   { "cast(cast(-999999999.99 as DECIMAL(11,2)) as DECIMAL(9,0))",
-    {{ false, -999999999, 9, 0 },
-     { true, 0, 9, 0 }}},
+    {{ false, false, -999999999, 9, 0 },
+     { false, true, 0, 9, 0 }}},
   // IMPALA-2233: Test that implicit casts do not lose precision.
   // The overload greatest(decimal(*,*)) is available and should be used.
   { "greatest(0, cast('99999.1111' as decimal(30,10)))",
-    {{ false, 999991111000000, 30, 10 },
-     { false, 999991111000000, 30, 10 }}},
+    {{ false, false, 999991111000000, 30, 10 },
+     { false, false, 999991111000000, 30, 10 }}},
   // Test AVG() with DECIMAL
   { "avg(d) from (values((cast(100000000000000000000000000000000.00000 as DECIMAL(38,5)) "
     "as d))) as t",
-    {{ false, static_cast<int128_t>(10000000ll) *
+    {{ false, false, static_cast<int128_t>(10000000ll) *
        10000000000ll * 10000000000ll * 10000000000ll, 38, 5 },
-     { true, 0, 38, 6}}},
+     { false, true, 0, 38, 6}}},
   { "avg(d) from (values((cast(1234567890 as DECIMAL(10,0)) as d))) as t",
-    {{false, 1234567890, 10, 0},
-     {false, 1234567890000000, 16, 6}}},
+    {{ false, false, 1234567890, 10, 0},
+     { false, false, 1234567890000000, 16, 6}}},
   { "avg(d) from (values((cast(1234567.89 as DECIMAL(10,2)) as d))) as t",
-    {{false, 123456789, 10, 2},
-     {false, 1234567890000, 14, 6}}},
+    {{ false, false, 123456789, 10, 2},
+     { false, false, 1234567890000, 14, 6}}},
   { "avg(d) from (values((cast(10000000000000000000000000000000 as DECIMAL(32,0)) "
     "as d))) as t",
-    {{false, static_cast<int128_t>(10) *
+    {{ false, false, static_cast<int128_t>(10) *
       10000000000ll * 10000000000ll * 10000000000ll, 32, 0},
-     {false, static_cast<int128_t>(10000000) *
+     { false, false, static_cast<int128_t>(10000000) *
       10000000000ll * 10000000000ll * 10000000000ll, 38, 6}}},
   { "avg(d) from (values((cast(100000000000000000000000000000000 as DECIMAL(33,0)) "
     "as d))) as t",
-    {{false, static_cast<int128_t>(100) *
+    {{ false, false, static_cast<int128_t>(100) *
       10000000000ll * 10000000000ll * 10000000000ll, 33, 0},
-     {true, 0, 38, 6}}},
+     { false, true, 0, 38, 6}}},
   { "avg(d) from (values((cast(100000000000000000000000000000000.0 as DECIMAL(34,1)) "
     "as d))) as t",
-    {{false, static_cast<int128_t>(1000) *
+    {{ false, false, static_cast<int128_t>(1000) *
       10000000000ll * 10000000000ll * 10000000000ll, 34, 1},
-     {true, 0, 38, 6}}},
+     { false, true, 0, 38, 6}}},
   { "avg(d) from (values((cast(100000000000000000000000000000000.00000 as DECIMAL(38,5)) "
     "as d))) as t",
-    {{false, static_cast<int128_t>(10000000) *
+    {{ false, false, static_cast<int128_t>(10000000) *
       10000000000ll * 10000000000ll * 10000000000ll, 38, 5},
-     {true, 0, 38, 6}}},
+     { false, true, 0, 38, 6}}},
   { "avg(d) from (values((cast(10000000000000000000000000000000.000000 as DECIMAL(38,6)) "
     "as d))) as t",
-    {{false, static_cast<int128_t>(10000000) *
+    {{ false, false, static_cast<int128_t>(10000000) *
       10000000000ll * 10000000000ll * 10000000000ll, 38, 6}}},
-  { "avg(d) from (values((cast(0.10000000000000000000000000000000000000 as DECIMAL(38,38)) "
-    "as d))) as t",
-    {{false, static_cast<int128_t>(10000000) *
+  { "avg(d) from (values((cast("
+    "0.10000000000000000000000000000000000000 as DECIMAL(38,38)) as d))) as t",
+    {{ false, false, static_cast<int128_t>(10000000) *
       10000000000ll * 10000000000ll * 10000000000ll, 38, 38}}},
   // Test CAST DECIMAL -> INT
   { "cast(cast(0.5999999 AS tinyint) AS decimal(10,6))",
-    {{ false, 0, 10, 6 },
-     { false, 1000000, 10, 6 }}},
+    {{ false, false, 0, 10, 6 },
+     { false, false, 1000000, 10, 6 }}},
   { "cast(cast(99999999.4999999 AS int) AS decimal(10,2))",
-    {{ false, 9999999900, 10, 2 }}},
+    {{ false, false, 9999999900, 10, 2 }}},
   { "cast(cast(99999999.5999999 AS int) AS decimal(10,2))",
-    {{ false, 9999999900, 10, 2 },
-     { true, 0, 10, 2 }}},
+    {{ false, false, 9999999900, 10, 2 },
+     { false, true, 0, 10, 2 }}},
   { "cast(cast(10000.5999999 as int) as decimal(30,6))",
-    {{ false, 10000000000, 30, 6 },
-     { false, 10001000000, 30, 6 }}},
+    {{ false, false, 10000000000, 30, 6 },
+     { false, false, 10001000000, 30, 6 }}},
   { "cast(cast(10000.5 AS int) AS decimal(6,1))",
-    {{ false, 100000, 6, 1 },
-     { false, 100010, 6, 1 }}},
+    {{ false, false, 100000, 6, 1 },
+     { false, false, 100010, 6, 1 }}},
   { "cast(cast(-10000.5 AS int) AS decimal(6,1))",
-    {{ false, -100000, 6, 1 },
-     { false, -100010, 6, 1 }}},
+    {{ false, false, -100000, 6, 1 },
+     { false, false, -100010, 6, 1 }}},
   { "cast(cast(9999.5 AS int) AS decimal(4,0))",
-    {{ false, 9999, 4, 0 },
-     { true, 0, 4, 0 }}},
+    {{ false, false, 9999, 4, 0 },
+     { false, true, 0, 4, 0 }}},
   { "cast(cast(-9999.5 AS int) AS decimal(4,0))",
-    {{ false, -9999, 4, 0 },
-     { true, 0, 4, 0 }}},
+    {{ false, false, -9999, 4, 0 },
+     { false, true, 0, 4, 0 }}},
   { "cast(cast(127.4999 AS tinyint) AS decimal(30,0))",
-    {{ false, 127, 30, 0 }}},
+    {{ false, false, 127, 30, 0 }}},
   { "cast(cast(127.5 AS tinyint) AS decimal(30,0))",
-    {{ false, 127, 30, 0 },
-     { true, 0, 30, 0 }}},
+    {{ false, false, 127, 30, 0 },
+     { false, true, 0, 30, 0 }}},
   { "cast(cast(128.0 AS tinyint) AS decimal(30,0))",
-    {{ false, -128, 30, 0 }, // BUG: JIRA: IMPALA-865
-     { true, 0, 30, 0 }}},
+    {{ false, false, -128, 30, 0 }, // BUG: JIRA: IMPALA-865
+     { false, true, 0, 30, 0 }}},
   { "cast(cast(-128.4999 AS tinyint) AS decimal(30,0))",
-    {{ false, -128, 30, 0 }}},
+    {{ false, false, -128, 30, 0 }}},
   { "cast(cast(-128.5 AS tinyint) AS decimal(30,0))",
-    {{ false, -128, 30, 0 },
-     { true, 0, 30, 0 }}},
+    {{ false, false, -128, 30, 0 },
+     { false, true, 0, 30, 0 }}},
   { "cast(cast(-129.0 AS tinyint) AS decimal(30,0))",
-    {{ false, 127, 30, 0 }, // BUG: JIRA: IMPALA-865
-     { true, 0, 30, 0 }}},
+    {{ false, false, 127, 30, 0 }, // BUG: JIRA: IMPALA-865
+     { false, true, 0, 30, 0 }}},
   { "cast(cast(32767.4999 AS smallint) AS decimal(30,0))",
-    {{ false, 32767, 30, 0 }}},
+    {{ false, false, 32767, 30, 0 }}},
   { "cast(cast(32767.5 AS smallint) AS decimal(30,0))",
-    {{ false, 32767, 30, 0 },
-     { true, 0, 30, 0 }}},
+    {{ false, false, 32767, 30, 0 },
+     { false, true, 0, 30, 0 }}},
   { "cast(cast(32768.0 AS smallint) AS decimal(30,0))",
-    {{ false, -32768, 30, 0 }, // BUG: JIRA: IMPALA-865
-     { true, 0, 30, 0 }}},
+    {{ false, false, -32768, 30, 0 }, // BUG: JIRA: IMPALA-865
+     { false, true, 0, 30, 0 }}},
   { "cast(cast(-32768.4999 AS smallint) AS decimal(30,0))",
-    {{ false, -32768, 30, 0 }}},
+    {{ false, false, -32768, 30, 0 }}},
   { "cast(cast(-32768.5 AS smallint) AS decimal(30,0))",
-    {{ false, -32768, 30, 0 },
-     { true, 0, 30, 0 }}},
+    {{ false, false, -32768, 30, 0 },
+     { false, true, 0, 30, 0 }}},
   { "cast(cast(-32769.0 AS smallint) AS decimal(30,0))",
-    {{ false, 32767, 30, 0 }, // BUG: JIRA: IMPALA-865
-     { true, 0, 30, 0 }}},
+    {{ false, false, 32767, 30, 0 }, // BUG: JIRA: IMPALA-865
+     { false, true, 0, 30, 0 }}},
   { "cast(cast(2147483647.4999 AS int) AS decimal(30,0))",
-    {{ false, 2147483647, 30, 0 }}},
+    {{ false, false, 2147483647, 30, 0 }}},
   { "cast(cast(2147483647.5 AS int) AS decimal(30,0))",
-    {{ false, 2147483647, 30, 0 },
-     { true, 0, 30, 0 }}},
+    {{ false, false, 2147483647, 30, 0 },
+     { false, true, 0, 30, 0 }}},
   { "cast(cast(2147483648.0 AS int) AS decimal(30,0))",
-    {{ false, -2147483648, 30, 0 }, // BUG: JIRA: IMPALA-865
-     { true, 0, 30, 0 }}},
+    {{ false, false, -2147483648, 30, 0 }, // BUG: JIRA: IMPALA-865
+     { false, true, 0, 30, 0 }}},
   { "cast(cast(-2147483648.4999 AS int) AS decimal(30,0))",
-    {{ false, -2147483648, 30, 0 }}},
+    {{ false, false, -2147483648, 30, 0 }}},
   { "cast(cast(-2147483648.5 AS int) AS decimal(30,0))",
-    {{ false, -2147483648, 30, 0 },
-     { true, 0, 30, 0 }}},
+    {{ false, false, -2147483648, 30, 0 },
+     { false, true, 0, 30, 0 }}},
   { "cast(cast(-2147483649.0 AS int) AS decimal(30,0))",
-    {{ false, 2147483647, 30, 0 }, // BUG: JIRA: IMPALA-865
-     { true, 0, 30, 0 }}},
+    {{ false, false, 2147483647, 30, 0 }, // BUG: JIRA: IMPALA-865
+     { false, true, 0, 30, 0 }}},
   { "cast(cast(9223372036854775807.4999 AS bigint) AS decimal(30,0))",
-    {{ false, 9223372036854775807, 30, 0 }}},
+    {{ false, false, 9223372036854775807, 30, 0 }}},
   { "cast(cast(9223372036854775807.5 AS bigint) AS decimal(30,0))",
-    {{ false, 9223372036854775807, 30, 0 },
-     { true, 0, 30, 0 }}},
+    {{ false, false, 9223372036854775807, 30, 0 },
+     { false, true, 0, 30, 0 }}},
   { "cast(cast(9223372036854775808.0 AS bigint) AS decimal(30,0))",
-    {{ false, -9223372036854775807 - 1, 30, 0 }, // BUG; also GCC workaround with -1
+    // BUG; also GCC workaround with -1
+    {{ false, false, -9223372036854775807 - 1, 30, 0 },
      // error: integer constant is so large that it is unsigned
-     { true, 0, 30, 0 }}},
+     { false, true, 0, 30, 0 }}},
   { "cast(cast(-9223372036854775808.4999 AS bigint) AS decimal(30,0))",
-    {{ false, -9223372036854775807 - 1, 30, 0 }}},
+    {{ false, false, -9223372036854775807 - 1, 30, 0 }}},
   { "cast(cast(-9223372036854775808.5 AS bigint) AS decimal(30,0))",
-    {{ false, -9223372036854775807 - 1, 30, 0 },
-     { true, 0, 30, 0 }}},
+    {{ false, false, -9223372036854775807 - 1, 30, 0 },
+     { false, true, 0, 30, 0 }}},
   { "cast(cast(-9223372036854775809.0 AS bigint) AS decimal(30,0))",
-    {{ false, 9223372036854775807, 30, 0 }, // BUG: JIRA: IMPALA-865
-     { true, 0, 30, 0 }}},
+    {{ false, false, 9223372036854775807, 30, 0 }, // BUG: JIRA: IMPALA-865
+     { false, true, 0, 30, 0 }}},
   { "cast(cast(cast(pow(1, -38) as decimal(38,38)) as bigint) as decimal(18,10))",
-    {{ false, 0, 18, 10 },
-     { false, 10000000000, 18, 10 }}},
+    {{ false, false, 0, 18, 10 },
+     { false, false, 10000000000, 18, 10 }}},
   { "cast(cast(cast(-pow(1, -38) as decimal(38,38)) as bigint) as decimal(18,10))",
-    {{ false, 0, 18, 10 },
-     { false, -10000000000, 18, 10 }}},
+    {{ false, false, 0, 18, 10 },
+     { false, false, -10000000000, 18, 10 }}},
   // Test CAST FLOAT -> DECIMAL
   { "cast(cast(power(10, 3) - power(10, -1) as float) as decimal(4,1))",
-    {{ false, 9999, 4, 1 }}},
+    {{ false, false, 9999, 4, 1 }}},
   { "cast(cast(power(10, 3) - power(10, -2) as float) as decimal(5,1))",
-    {{ false, 9999, 5, 1 },
-     { false, 10000, 5, 1 }}},
+    {{ false, false, 9999, 5, 1 },
+     { false, false, 10000, 5, 1 }}},
   { "cast(cast(power(10, 3) - power(10, -2) as float) as decimal(4,1))",
-    {{ false, 9999, 4, 1 },
-     { true, 0, 4, 1 }}},
+    {{ false, false, 9999, 4, 1 },
+     { false, true, 0, 4, 1 }}},
   { "cast(cast(-power(10, 3) + power(10, -1) as float) as decimal(4,1))",
-    {{ false, -9999, 4, 1 }}},
+    {{ false, false, -9999, 4, 1 }}},
   { "cast(cast(-power(10, 3) + power(10, -2) as float) as decimal(5,1))",
-    {{ false, -9999, 5, 1 },
-     { false, -10000, 5, 1 }}},
+    {{ false, false, -9999, 5, 1 },
+     { false, false, -10000, 5, 1 }}},
   { "cast(cast(-power(10, 3) + power(10, -2) as float) as decimal(4,1))",
-    {{ false, -9999, 4, 1 },
-     { true, 0, 4, 1 }}},
+    {{ false, false, -9999, 4, 1 },
+     { false, true, 0, 4, 1 }}},
   { "cast(cast(power(10, 3) - 0.45 as double) as decimal(4,1))",
-    {{ false, 9995, 4, 1 },
-     { false, 9996, 4, 1 }}},
+    {{ false, false, 9995, 4, 1 },
+     { false, false, 9996, 4, 1 }}},
   { "cast(cast(power(10, 3) - 0.45 as double) as decimal(5,2))",
-    {{ false, 99955, 5, 2 }}},
+    {{ false, false, 99955, 5, 2 }}},
   { "cast(cast(power(10, 3) - 0.45 as double) as decimal(5,0))",
-    {{ false, 999, 5, 0 },
-     { false, 1000, 5, 0 }}},
+    {{ false, false, 999, 5, 0 },
+     { false, false, 1000, 5, 0 }}},
   { "cast(cast(power(10, 3) - 0.45 as double) as decimal(3,0))",
-    {{ false, 999, 3, 0 },
-     { true, 0, 3, 0 }}},
+    {{ false, false, 999, 3, 0 },
+     { false, true, 0, 3, 0 }}},
   { "cast(cast(-power(10, 3) + 0.45 as double) as decimal(4,1))",
-    {{ false, -9995, 4, 1 },
-     { false, -9996, 4, 1 }}},
+    {{ false, false, -9995, 4, 1 },
+     { false, false, -9996, 4, 1 }}},
   { "cast(cast(-power(10, 3) + 0.45 as double) as decimal(5,2))",
-    {{ false, -99955, 5, 2 }}},
+    {{ false, false, -99955, 5, 2 }}},
   { "cast(cast(-power(10, 3) + 0.45 as double) as decimal(5,0))",
-    {{ false, -999, 5, 0 },
-     { false, -1000, 5, 0 }}},
+    {{ false, false, -999, 5, 0 },
+     { false, false, -1000, 5, 0 }}},
   { "cast(cast(-power(10, 3) + 0.45 as double) as decimal(3,0))",
-    {{ false, -999, 3, 0 },
-     { true, 0, 3, 0 }}},
+    {{ false, false, -999, 3, 0 },
+     { false, true, 0, 3, 0 }}},
   { "cast(cast(power(10, 3) - 0.5 as double) as decimal(4,1))",
-    {{ false, 9995, 4, 1 }}},
+    {{ false, false, 9995, 4, 1 }}},
   { "cast(cast(power(10, 3) - 0.5 as double) as decimal(5,2))",
-    {{ false, 99950, 5, 2 }}},
+    {{ false, false, 99950, 5, 2 }}},
   { "cast(cast(power(10, 3) - 0.5 as double) as decimal(5,0))",
-    {{ false, 999, 5, 0 },
-     { false, 1000, 5, 0 }}},
+    {{ false, false, 999, 5, 0 },
+     { false, false, 1000, 5, 0 }}},
   { "cast(cast(power(10, 3) - 0.5 as double) as decimal(3,0))",
-    {{ false, 999, 3, 0 },
-     { true, 0, 3, 0 }}},
+    {{ false, false, 999, 3, 0 },
+     { false, true, 0, 3, 0 }}},
   { "cast(cast(-power(10, 3) + 0.5 as double) as decimal(4,1))",
-    {{ false, -9995, 4, 1 }}},
+    {{ false, false, -9995, 4, 1 }}},
   { "cast(cast(-power(10, 3) + 0.5 as double) as decimal(5,2))",
-    {{ false, -99950, 5, 2 }}},
+    {{ false, false, -99950, 5, 2 }}},
   { "cast(cast(-power(10, 3) + 0.5 as double) as decimal(5,0))",
-    {{ false, -999, 5, 0 },
-     { false, -1000, 5, 0 }}},
+    {{ false, false, -999, 5, 0 },
+     { false, false, -1000, 5, 0 }}},
   { "cast(cast(-power(10, 3) + 0.5 as double) as decimal(3,0))",
-    {{ false, -999, 3, 0 },
-     { true, 0, 3, 0 }}},
+    {{ false, false, -999, 3, 0 },
+     { false, true, 0, 3, 0 }}},
   { "cast(cast(power(10, 3) - 0.55 as double) as decimal(4,1))",
-    {{ false, 9994, 4, 1 },
-     { false, 9995, 4, 1 }}},
+    {{ false, false, 9994, 4, 1 },
+     { false, false, 9995, 4, 1 }}},
   { "cast(cast(power(10, 3) - 0.55 as double) as decimal(5,2))",
-    {{ false, 99945, 5, 2 }}},
+    {{ false, false, 99945, 5, 2 }}},
   { "cast(cast(power(10, 3) - 0.55 as double) as decimal(5,0))",
-    {{ false, 999, 5, 0 }}},
+    {{ false, false, 999, 5, 0 }}},
   { "cast(cast(power(10, 3) - 0.55 as double) as decimal(3,0))",
-    {{ false, 999, 3, 0 }}},
+    {{ false, false, 999, 3, 0 }}},
   { "cast(cast(-power(10, 3) + 0.55 as double) as decimal(4,1))",
-    {{ false, -9994, 4, 1 },
-     { false, -9995, 4, 1 }}},
+    {{ false, false, -9994, 4, 1 },
+     { false, false, -9995, 4, 1 }}},
   { "cast(cast(-power(10, 3) + 0.55 as double) as decimal(5,2))",
-    {{ false, -99945, 5, 2 }}},
+    {{ false, false, -99945, 5, 2 }}},
   { "cast(cast(-power(10, 3) + 0.55 as double) as decimal(5,0))",
-    {{ false, -999, 5, 0 }}},
+    {{ false, false, -999, 5, 0 }}},
   { "cast(cast(-power(10, 3) + 0.55 as double) as decimal(3,0))",
-    {{ false, -999, 3, 0 }}},
+    {{ false, false, -999, 3, 0 }}},
   { "cast(power(2, 1023) * 100 as decimal(38,0))",
-    {{ true, 0, 38, 0 }}},
+    {{ false, true, 0, 38, 0 }}},
   { "cast(power(2, 1023) * 100 as decimal(18,0))",
-    {{ true, 0, 18, 0 }}},
+    {{ false, true, 0, 18, 0 }}},
   { "cast(power(2, 1023) * 100 as decimal(9,0))",
-    {{ true, 0, 9, 0 }}},
+    {{ false, true, 0, 9, 0 }}},
   { "cast(0/0 as decimal(38,0))",
-    {{ true, 0, 38, 0 }}},
+    {{ false, true, 0, 38, 0 }}},
   { "cast(0/0 as decimal(18,0))",
-    {{ true, 0, 18, 0 }}},
+    {{ false, true, 0, 18, 0 }}},
   { "cast(0/0 as decimal(9,0))",
-    {{ true, 0, 9, 0 }}},
+    {{ false, true, 0, 9, 0 }}},
   // 39 5's - legal double but will overflow in decimal
   { "cast(555555555555555555555555555555555555555 as decimal(38,0))",
-    {{ true, 0, 38, 0 }}},
+    {{ false, true, 0, 38, 0 }}},
 };
 
 TEST_F(ExprTest, DecimalArithmeticExprs) {
@@ -2483,7 +2523,9 @@ TEST_F(ExprTest, DecimalArithmeticExprs) {
     for (const DecimalTestCase& c : decimal_cases) {
       const DecimalExpectedResult& r = c.Expected(v2);
       const ColumnType& type = ColumnType::CreateDecimalType(r.precision, r.scale);
-      if (r.null) {
+      if (r.error) {
+        TestError(c.expr);
+      } else if (r.null) {
         TestDecimalResultType(c.expr, type);
         TestIsNull(c.expr, type);
       } else {

http://git-wip-us.apache.org/repos/asf/incubator-impala/blob/5ebea0ec/testdata/workloads/functional-query/queries/QueryTest/decimal-exprs.test
----------------------------------------------------------------------
diff --git a/testdata/workloads/functional-query/queries/QueryTest/decimal-exprs.test b/testdata/workloads/functional-query/queries/QueryTest/decimal-exprs.test
index b1c62ec..ef707f2 100644
--- a/testdata/workloads/functional-query/queries/QueryTest/decimal-exprs.test
+++ b/testdata/workloads/functional-query/queries/QueryTest/decimal-exprs.test
@@ -28,6 +28,72 @@ select d1 / d2, d2 / d1, d3 / d4, d5 / d3, d3 / d5 from decimal_tbl;
 DECIMAL, DECIMAL, DECIMAL, DECIMAL, DECIMAL
 ====
 ---- QUERY
+# Test DECIMAL V1 division by zero.
+set decimal_v2=false;
+select d1 / cast(0 as decimal(7, 2)), d1 / 0, 10.0 / 0 from decimal_tbl;
+---- RESULTS
+NULL,NULL,Infinity
+NULL,NULL,Infinity
+NULL,NULL,Infinity
+NULL,NULL,Infinity
+NULL,NULL,Infinity
+---- TYPES
+DECIMAL,DECIMAL,DOUBLE
+====
+---- QUERY
+# Test DECIMAL V2 division by zero. Verify that Impala throws an error.
+set decimal_v2=true;
+select d1 / cast(0 as decimal(7, 2)) from decimal_tbl;
+---- CATCH
+UDF ERROR: Cannot divide decimal by zero
+====
+---- QUERY
+set decimal_v2=true;
+select d1 / 0 from decimal_tbl;
+---- CATCH
+UDF ERROR: Cannot divide decimal by zero
+====
+---- QUERY
+set decimal_v2=true;
+select 10.0 / 0;
+---- CATCH
+UDF ERROR: Cannot divide decimal by zero
+====
+---- QUERY
+# Test DECIMAL V1 modulo zero.
+set decimal_v2=false;
+select d1 % cast(0 as decimal(7, 2)), d1 % 0, 10.0 % 0 from decimal_tbl;
+---- RESULTS
+NULL,NULL,NULL
+NULL,NULL,NULL
+NULL,NULL,NULL
+NULL,NULL,NULL
+NULL,NULL,NULL
+---- TYPES
+DECIMAL,DECIMAL,DOUBLE
+====
+---- QUERY
+# Test DECIMAL V2 modulo zero. Verify that Impala throws an error.
+set decimal_v2=true;
+select d1 % cast(0 as decimal(7, 2)) from decimal_tbl;
+---- CATCH
+UDF ERROR: Cannot divide decimal by zero
+====
+---- QUERY
+# Test DECIMAL V2 modulo zero. Verify that Impala throws an error.
+set decimal_v2=true;
+select d1 % 0 from decimal_tbl;
+---- CATCH
+UDF ERROR: Cannot divide decimal by zero
+====
+---- QUERY
+# Test DECIMAL V2 modulo zero. Verify that Impala throws an error.
+set decimal_v2=true;
+select 10.0 % 0 from decimal_tbl;
+---- CATCH
+UDF ERROR: Cannot divide decimal by zero
+====
+---- QUERY
 # Test casting behavior without decimal_v2 query option set.
 set decimal_v2=false;
 select cast(d3 as decimal(20, 3)) from decimal_tbl;
@@ -205,4 +271,4 @@ from decimal_tiny where c2 < 112
 4.3329,647.66658,2.2,0.722150,107.944430,0.550000
 ---- TYPES
 DECIMAL,DECIMAL,DECIMAL,DECIMAL,DECIMAL,DECIMAL
-====
\ No newline at end of file
+====


Mime
View raw message