Apache DataFusion SQL Query Engine
Fix `null` input in `map_keys/values` (#14401)
cht42f5388f76aea7
diff --git a/datafusion/functions-nested/src/map_keys.rs b/datafusion/functions-nested/src/map_keys.rsindex 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.rsindex 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.sltindex 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 okCREATE TABLE map_array_table_2AS VALUES@@ -198,7 +201,7 @@ query error DataFusion error: Execution error: map key cannot be nullSELECT 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_tableAS 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, duplicateSELECT 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_tableAS 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]]+NULLstatement okdrop table map_array_table_1;