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

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


The following commit(s) were added to refs/heads/master by this push:
     new ea86aef2f IMPALA-12565: Fix crash triggered by calling pmod() UDF
ea86aef2f is described below

commit ea86aef2f176b866e9f2721e2eb482f968fc9bc3
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 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

Reply via email to