This is an automated email from the ASF dual-hosted git repository.

stigahuang pushed a commit to branch branch-3.4.2
in repository https://gitbox.apache.org/repos/asf/impala.git

commit 2963b29a322744abf1882fb410cbe566e24a3024
Author: ttttttz <[email protected]>
AuthorDate: Wed Nov 15 23:01:48 2023 +0800

    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 <[email protected]>
    Tested-by: Impala Public Jenkins <[email protected]>
---
 be/src/exprs/math-functions-ir.cc                                | 4 ++--
 testdata/workloads/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 527b51b5f..a63e08295 100644
--- a/be/src/exprs/math-functions-ir.cc
+++ b/be/src/exprs/math-functions-ir.cc
@@ -434,13 +434,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 f2f396d01..5d4d05971 100644
--- a/testdata/workloads/functional-query/queries/QueryTest/exprs.test
+++ b/testdata/workloads/functional-query/queries/QueryTest/exprs.test
@@ -3093,4 +3093,12 @@ select distinct year from functional.alltypes where case 
when year = 2010 then m
 2010
 ---- TYPES
 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

Reply via email to