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