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/arrow-datafusion.git
The following commit(s) were added to refs/heads/main by this push:
new 6fad5ed7a3 Fix array_ndims error handling (#9272)
6fad5ed7a3 is described below
commit 6fad5ed7a37c50b9c200f214c3e13b0e1f0cecbc
Author: Alex Huang <[email protected]>
AuthorDate: Wed Feb 21 17:24:41 2024 +0800
Fix array_ndims error handling (#9272)
* Fix array_ndims error handling
* update tests
---
datafusion/physical-expr/src/array_expressions.rs | 3 +-
datafusion/sqllogictest/test_files/array.slt | 35 ++++++++++++-----------
2 files changed, 20 insertions(+), 18 deletions(-)
diff --git a/datafusion/physical-expr/src/array_expressions.rs
b/datafusion/physical-expr/src/array_expressions.rs
index 0468b3e542..38a4359b4f 100644
--- a/datafusion/physical-expr/src/array_expressions.rs
+++ b/datafusion/physical-expr/src/array_expressions.rs
@@ -2186,7 +2186,6 @@ pub fn array_ndims(args: &[ArrayRef]) -> Result<ArrayRef>
{
Ok(Arc::new(UInt64Array::from(data)) as ArrayRef)
}
-
match args[0].data_type() {
DataType::List(_) => {
let array = as_list_array(&args[0])?;
@@ -2196,7 +2195,7 @@ pub fn array_ndims(args: &[ArrayRef]) -> Result<ArrayRef>
{
let array = as_large_list_array(&args[0])?;
general_list_ndims::<i64>(array)
}
- _ => Ok(Arc::new(UInt64Array::from(vec![0; args[0].len()])) as
ArrayRef),
+ array_type => exec_err!("array_ndims does not support type
{array_type:?}"),
}
}
diff --git a/datafusion/sqllogictest/test_files/array.slt
b/datafusion/sqllogictest/test_files/array.slt
index 88bae310fb..7f263d9048 100644
--- a/datafusion/sqllogictest/test_files/array.slt
+++ b/datafusion/sqllogictest/test_files/array.slt
@@ -4287,21 +4287,26 @@ NULL [3] [4]
# array_ndims scalar function #1
-query III
+query error
+select array_ndims(1);
+
+#follow PostgreSQL
+query error
+select
+ array_ndims(null);
+
+query I
select
- array_ndims(1),
- array_ndims(null),
array_ndims([2, 3]);
----
-0 0 1
+1
statement ok
CREATE TABLE array_ndims_table
AS VALUES
- (1, [1, 2, 3], [[7]], [[[[[10]]]]]),
- (2, [4, 5], [[8]], [[[[[10]]]]]),
- (null, [6], [[9]], [[[[[10]]]]]),
- (3, [6], [[9]], [[[[[10]]]]])
+ ([1], [1, 2, 3], [[7]], [[[[[10]]]]]),
+ ([2], [4, 5], [[8]], [[[[[10]]]]]),
+ ([3], [6], [[9]], [[[[[10]]]]])
;
statement ok
@@ -4321,10 +4326,9 @@ select
array_ndims(column4)
from array_ndims_table;
----
-0 1 2 5
-0 1 2 5
-0 1 2 5
-0 1 2 5
+1 1 2 5
+1 1 2 5
+1 1 2 5
query IIII
select
@@ -4334,10 +4338,9 @@ select
array_ndims(column4)
from large_array_ndims_table;
----
-0 1 2 5
-0 1 2 5
-0 1 2 5
-0 1 2 5
+1 1 2 5
+1 1 2 5
+1 1 2 5
statement ok
drop table array_ndims_table;