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

jayzhan 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 6a0a2dce90 handle empty rows (#10786)
6a0a2dce90 is described below

commit 6a0a2dce90fde73d36a5451a59381cd357fae648
Author: Jay Zhan <[email protected]>
AuthorDate: Tue Jun 4 17:06:13 2024 +0800

    handle empty rows (#10786)
    
    Signed-off-by: jayzhan211 <[email protected]>
---
 datafusion/functions-array/src/sort.rs       |  3 +++
 datafusion/sqllogictest/test_files/array.slt | 12 ++++++++++++
 2 files changed, 15 insertions(+)

diff --git a/datafusion/functions-array/src/sort.rs 
b/datafusion/functions-array/src/sort.rs
index 0230c42175..c82dbd37be 100644
--- a/datafusion/functions-array/src/sort.rs
+++ b/datafusion/functions-array/src/sort.rs
@@ -120,6 +120,9 @@ pub fn array_sort_inner(args: &[ArrayRef]) -> 
Result<ArrayRef> {
 
     let list_array = as_list_array(&args[0])?;
     let row_count = list_array.len();
+    if row_count == 0 {
+        return Ok(args[0].clone());
+    }
 
     let mut array_lengths = vec![];
     let mut arrays = vec![];
diff --git a/datafusion/sqllogictest/test_files/array.slt 
b/datafusion/sqllogictest/test_files/array.slt
index 9b8b502012..df761e6237 100644
--- a/datafusion/sqllogictest/test_files/array.slt
+++ b/datafusion/sqllogictest/test_files/array.slt
@@ -2030,6 +2030,18 @@ NULL
 [, 51, 52, 54, 55, 56, 57, 58, 59, 60]
 [61, 62, 63, 64, 65, 66, 67, 68, 69, 70]
 
+statement ok
+create table t1(a int, b int) as values (100, 1), (101, 2), (102, 3), (101, 2);
+
+# rowsort is to ensure the order of group by is deterministic, array_sort has 
no effect here, since the sum() always returns single row.
+query ? rowsort
+select array_sort([sum(a)]) from t1 where a > 100 group by b;
+----
+[102]
+[202]
+
+statement ok
+drop table t1;
 
 ## list_sort (aliases: `array_sort`)
 query ???


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

Reply via email to