This is an automated email from the ASF dual-hosted git repository.
xudong963 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 f5388f76ae Fix `null` input in `map_keys/values` (#14401)
f5388f76ae is described below
commit f5388f76aea7413dbf60267b2b85d3516f9a5d91
Author: cht42 <[email protected]>
AuthorDate: Mon Feb 3 19:35:14 2025 +0400
Fix `null` input in `map_keys/values` (#14401)
* null map keys/values
* fix test
* move test to slt
---
datafusion/functions-nested/src/map_keys.rs | 2 +-
datafusion/functions-nested/src/map_values.rs | 2 +-
datafusion/sqllogictest/test_files/map.slt | 11 +++++++++--
3 files changed, 11 insertions(+), 4 deletions(-)
diff --git a/datafusion/functions-nested/src/map_keys.rs
b/datafusion/functions-nested/src/map_keys.rs
index 74a106bb0c..0dfd34b390 100644
--- a/datafusion/functions-nested/src/map_keys.rs
+++ b/datafusion/functions-nested/src/map_keys.rs
@@ -129,6 +129,6 @@ fn map_keys_inner(args: &[ArrayRef]) -> Result<ArrayRef> {
Arc::new(Field::new_list_field(map_array.key_type().clone(), false)),
map_array.offsets().clone(),
Arc::clone(map_array.keys()),
- None,
+ map_array.nulls().cloned(),
)))
}
diff --git a/datafusion/functions-nested/src/map_values.rs
b/datafusion/functions-nested/src/map_values.rs
index d2fc0a12f9..009d5c8610 100644
--- a/datafusion/functions-nested/src/map_values.rs
+++ b/datafusion/functions-nested/src/map_values.rs
@@ -129,6 +129,6 @@ fn map_values_inner(args: &[ArrayRef]) -> Result<ArrayRef> {
Arc::new(Field::new_list_field(map_array.value_type().clone(), true)),
map_array.offsets().clone(),
Arc::clone(map_array.values()),
- None,
+ map_array.nulls().cloned(),
)))
}
diff --git a/datafusion/sqllogictest/test_files/map.slt
b/datafusion/sqllogictest/test_files/map.slt
index 706a98ee8c..7ebc800253 100644
--- a/datafusion/sqllogictest/test_files/map.slt
+++ b/datafusion/sqllogictest/test_files/map.slt
@@ -23,6 +23,9 @@ AS VALUES
(MAP {7: [1, NULL, 3], 8: [9, NULL, 6], 9: [7, 8, 9]}, 4, 4.0, '4')
;
+statement ok
+INSERT INTO map_array_table_1 VALUES (NULL, 2, 1.0, '3');
+
statement ok
CREATE TABLE map_array_table_2
AS VALUES
@@ -198,7 +201,7 @@ query error DataFusion error: Execution error: map key
cannot be null
SELECT MAP(['POST', 'HEAD', null], [41, 33, 30]);
statement error DataFusion error: Execution error: map key cannot be null
-CREATE TABLE duplicated_keys_table
+CREATE TABLE duplicated_keys_table
AS VALUES
(MAP {1: [1, NULL, 3], NULL: [4, NULL, 6]});
@@ -214,7 +217,7 @@ query error DataFusion error: Execution error: map key must
be unique, duplicate
SELECT make_map('POST', 41, 'HEAD', 33, 'POST', 30);
statement error DataFusion error: Execution error: map key must be unique,
duplicate key found: 1
-CREATE TABLE duplicated_keys_table
+CREATE TABLE duplicated_keys_table
AS VALUES
(MAP {1: [1, NULL, 3], 1: [4, NULL, 6]});
@@ -587,6 +590,7 @@ select map_extract(column1, 1), map_extract(column1, 5),
map_extract(column1, 7)
[[1, NULL, 3]] [NULL] [NULL]
[NULL] [[4, NULL, 6]] [NULL]
[NULL] [NULL] [[1, NULL, 3]]
+[NULL] [NULL] [NULL]
query ???
select map_extract(column1, column2), map_extract(column1, column3),
map_extract(column1, column4) from map_array_table_1;
@@ -594,6 +598,7 @@ select map_extract(column1, column2), map_extract(column1,
column3), map_extract
[[1, NULL, 3]] [[1, NULL, 3]] [[1, NULL, 3]]
[[4, NULL, 6]] [[4, NULL, 6]] [[4, NULL, 6]]
[NULL] [NULL] [NULL]
+[NULL] [NULL] [NULL]
query ???
select map_extract(column1, column2), map_extract(column1, column3),
map_extract(column1, column4) from map_array_table_2;
@@ -658,6 +663,7 @@ SELECT map_keys(column1) from map_array_table_1;
[1, 2, 3]
[4, 5, 6]
[7, 8, 9]
+NULL
# Tests for map_values
@@ -709,6 +715,7 @@ SELECT map_values(column1) from map_array_table_1;
[[1, NULL, 3], [4, NULL, 6], [7, 8, 9]]
[[1, NULL, 3], [4, NULL, 6], [7, 8, 9]]
[[1, NULL, 3], [9, NULL, 6], [7, 8, 9]]
+NULL
statement ok
drop table map_array_table_1;
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]