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/08/07 00:56:12 UTC
[5/5] impala git commit: IMPALA-7242/IMPALA-7243: check for overflow
when converting IntVal to DecimalValue
IMPALA-7242/IMPALA-7243: check for overflow when converting IntVal to DecimalValue
This change adds a check for an overflow which can happen during
converting num_buckets from IntVal to a DecimalValue during width_bucket
evaluation. An overflow can result in hitting a DCHECK if it needs int256
for intermediate evaluations or returns a wrong result otherwise.
Change-Id: Ie5808802096bb0e6cfd4ab6464538474e42cab60
Reviewed-on: http://gerrit.cloudera.org:8080/11020
Reviewed-by: Tim Armstrong <ta...@cloudera.com>
Tested-by: Impala Public Jenkins <im...@cloudera.com>
Project: http://git-wip-us.apache.org/repos/asf/impala/repo
Commit: http://git-wip-us.apache.org/repos/asf/impala/commit/df3f1658
Tree: http://git-wip-us.apache.org/repos/asf/impala/tree/df3f1658
Diff: http://git-wip-us.apache.org/repos/asf/impala/diff/df3f1658
Branch: refs/heads/master
Commit: df3f1658461553a174dd27fce2edce8594aefd16
Parents: 70bf9ea
Author: aphadke <ap...@cloudera.com>
Authored: Tue Jul 10 15:39:45 2018 -0700
Committer: Impala Public Jenkins <im...@cloudera.com>
Committed: Tue Aug 7 00:36:15 2018 +0000
----------------------------------------------------------------------
be/src/exprs/expr-test.cc | 11 ++++++++++-
be/src/exprs/math-functions-ir.cc | 7 +++++++
2 files changed, 17 insertions(+), 1 deletion(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/impala/blob/df3f1658/be/src/exprs/expr-test.cc
----------------------------------------------------------------------
diff --git a/be/src/exprs/expr-test.cc b/be/src/exprs/expr-test.cc
index e03f458..b50ba23 100644
--- a/be/src/exprs/expr-test.cc
+++ b/be/src/exprs/expr-test.cc
@@ -5379,7 +5379,16 @@ TEST_F(ExprTest, MathFunctions) {
// max and min value that would require int256_t for evalation
TestValue("width_bucket(10000000000000000000000000000000000000, 1,"
"99999999999999999999999999999999999999, 15)", TYPE_BIGINT, 2);
-
+ // IMPALA-7242/IMPALA-7243: check for overflow when converting IntVal to DecimalValue
+ TestErrorString("width_bucket(cast(-0.10 as decimal(37,30)), cast(-0.36028797018963968 "
+ "as decimal(25,25)), cast(9151517.4969773200562764155787276999832"
+ "as decimal(38,31)), 1328180220)",
+ "UDF ERROR: Overflow while representing the num_buckets:1328180220 as a "
+ "DecimalVal\n");
+ TestErrorString("width_bucket(cast(9 as decimal(10,7)), cast(-60000 as decimal(11,6)), "
+ "cast(10 as decimal(7,5)), 249895273);",
+ "UDF ERROR: Overflow while representing the num_buckets:249895273 as a "
+ "DecimalVal\n");
// Run twice to test deterministic behavior.
for (uint32_t seed : {0, 1234}) {
stringstream rand, random;
http://git-wip-us.apache.org/repos/asf/impala/blob/df3f1658/be/src/exprs/math-functions-ir.cc
----------------------------------------------------------------------
diff --git a/be/src/exprs/math-functions-ir.cc b/be/src/exprs/math-functions-ir.cc
index 91af3f4..28c9e1e 100644
--- a/be/src/exprs/math-functions-ir.cc
+++ b/be/src/exprs/math-functions-ir.cc
@@ -537,6 +537,13 @@ BigIntVal MathFunctions::WidthBucketImpl(FunctionContext* ctx,
Decimal16Value buckets = Decimal16Value::FromInt(input_precision, input_scale,
num_buckets.val, &overflow);
+ if (UNLIKELY(overflow)) {
+ stringstream error_msg;
+ error_msg << "Overflow while representing the num_buckets:" << num_buckets.val
+ << " as a DecimalVal";
+ ctx->SetError(error_msg.str().c_str());
+ return BigIntVal::null();
+ }
bool needs_int256 = false;
// Check if dist_from_min * buckets would overflow and if there is a need to
// store the intermediate results in int256_t to avoid an overflows