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

alamb pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/datafusion.git


The following commit(s) were added to refs/heads/main by this push:
     new 36158b6e6e Handle arguments checking of `min`/`max` function to avoid 
crashes (#12016)
36158b6e6e is described below

commit 36158b6e6e39b90cd2689f5c521d2d6964427793
Author: Tai Le Manh <[email protected]>
AuthorDate: Fri Aug 16 05:36:49 2024 +0700

    Handle arguments checking of `min`/`max` function to avoid crashes (#12016)
    
    * Handle arguments checking of min/max function to avoid crashes
    
    Signed-off-by: Tai Le Manh <[email protected]>
    
    * Fix code format error
    
    ---------
    
    Signed-off-by: Tai Le Manh <[email protected]>
---
 datafusion/functions-aggregate/src/min_max.rs | 11 +++++++++--
 1 file changed, 9 insertions(+), 2 deletions(-)

diff --git a/datafusion/functions-aggregate/src/min_max.rs 
b/datafusion/functions-aggregate/src/min_max.rs
index f9a08631bf..4dcd5ac0e9 100644
--- a/datafusion/functions-aggregate/src/min_max.rs
+++ b/datafusion/functions-aggregate/src/min_max.rs
@@ -48,7 +48,9 @@ use arrow::datatypes::{
     Int32Type, Int64Type, Int8Type, UInt16Type, UInt32Type, UInt64Type, 
UInt8Type,
 };
 use arrow_schema::IntervalUnit;
-use datafusion_common::{downcast_value, internal_err, DataFusionError, Result};
+use datafusion_common::{
+    downcast_value, exec_err, internal_err, DataFusionError, Result,
+};
 use 
datafusion_functions_aggregate_common::aggregate::groups_accumulator::prim_op::PrimitiveGroupsAccumulator;
 use std::fmt::Debug;
 
@@ -68,7 +70,12 @@ use std::ops::Deref;
 
 fn get_min_max_result_type(input_types: &[DataType]) -> Result<Vec<DataType>> {
     // make sure that the input types only has one element.
-    assert_eq!(input_types.len(), 1);
+    if input_types.len() != 1 {
+        return exec_err!(
+            "min/max was called with {} arguments. It requires only 1.",
+            input_types.len()
+        );
+    }
     // min and max support the dictionary data type
     // unpack the dictionary to get the value
     match &input_types[0] {


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to