From ea86aef2f176b866e9f2721e2eb482f968fc9bc3 Mon Sep 17 00:00:00 2001 From: ttttttz <2433038802@qq.com> Date: Wed, 15 Nov 2023 23:01:48 +0800 Subject: [PATCH] IMPALA-12565: Fix crash triggered by calling pmod() UDF When the pmod() UDF is called, if the divisor is 0, it will cause the impalad to crash. In this case, the result of the pmod() UDF should be NULL. Tests: * add a test in exprs.test Change-Id: Idcc274564a4b5b0872eb0c0c882c2f15e3247785 Reviewed-on: http://gerrit.cloudera.org:8080/20709 Reviewed-by: Impala Public Jenkins Tested-by: Impala Public Jenkins --- be/src/exprs/math-functions-ir.cc | 4 ++-- .../functional-query/queries/QueryTest/exprs.test | 8 ++++++++ 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/be/src/exprs/math-functions-ir.cc b/be/src/exprs/math-functions-ir.cc index 49a9f8b06..4ef50985d 100644 --- a/be/src/exprs/math-functions-ir.cc +++ b/be/src/exprs/math-functions-ir.cc @@ -435,13 +435,13 @@ bool MathFunctions::HandleParseResult(int8_t dest_base, int64_t* num, BigIntVal MathFunctions::PmodBigInt(FunctionContext* ctx, const BigIntVal& a, const BigIntVal& b) { - if (a.is_null || b.is_null) return BigIntVal::null(); + if (a.is_null || b.is_null || b.val == 0) return BigIntVal::null(); return BigIntVal(((a.val % b.val) + b.val) % b.val); } DoubleVal MathFunctions::PmodDouble(FunctionContext* ctx, const DoubleVal& a, const DoubleVal& b) { - if (a.is_null || b.is_null) return DoubleVal::null(); + if (a.is_null || b.is_null || b.val == 0) return DoubleVal::null(); return DoubleVal(fmod(fmod(a.val, b.val) + b.val, b.val)); } diff --git a/testdata/workloads/functional-query/queries/QueryTest/exprs.test b/testdata/workloads/functional-query/queries/QueryTest/exprs.test index 30e28b39d..09a88ff6b 100644 --- a/testdata/workloads/functional-query/queries/QueryTest/exprs.test +++ b/testdata/workloads/functional-query/queries/QueryTest/exprs.test @@ -3286,4 +3286,12 @@ select bytes(string_col), bytes(date_string_col) from functional.alltypestiny; 1,8 ---- TYPES INT, INT +==== +---- QUERY +# Test for IMPALA-12565 (UDF) +select pmod(0, 0), pmod(0, 0.0); +---- RESULTS +NULL,NULL +---- TYPES +BIGINT, DOUBLE ==== \ No newline at end of file