Copilot commented on code in PR #18531:
URL: https://github.com/apache/datafusion/pull/18531#discussion_r2506796652
##########
datafusion/sqllogictest/test_files/map.slt:
##########
@@ -854,3 +854,168 @@ NULL
statement ok
drop table tt;
+
+# Test for issue with NULL map values
+# When a map column contains NULL values (not null keys/values within maps),
+
+statement ok
+CREATE TABLE test_null_map AS VALUES
+ ('1', MAP {'a': 'ab'}),
+ ('2', NULL),
+ ('3', MAP {'b': 'cd'});
+
+query T?
+SELECT * FROM test_null_map ORDER BY column1;
+----
+1 {a: ab}
+2 NULL
+3 {b: cd}
+
+# Test with mixed NULL and non-NULL maps
+statement ok
+CREATE TABLE test_null_map2 AS VALUES
+ ('1', MAP {'a': 'ab'}),
+ ('2', NULL),
+ ('3', MAP {'c': 'ef'}),
+ ('4', NULL);
+
+query T?
+SELECT * FROM test_null_map2 ORDER BY column1;
+----
+1 {a: ab}
+2 NULL
+3 {c: ef}
+4 NULL
+
+statement ok
+DROP TABLE test_null_map;
+
+statement ok
+DROP TABLE test_null_map2;
+
+# Test processing map keys with NULL map values
+# This simulates the scenario from the issue where a UDF processes map keys
+statement ok
+CREATE TABLE test_map_keys AS VALUES
+ ('1', MAP {'a': 'ab'}),
+ ('2', NULL),
+ ('3', MAP {'c': 'cd'});
+
+query ?
+SELECT map_keys(column2) FROM test_map_keys ORDER BY column1;
+----
+[a]
+NULL
+[c]
+
+# Test processing map values with NULL map values
+query ?
+SELECT map_values(column2) FROM test_map_keys ORDER BY column1;
+----
+[ab]
+NULL
+[cd]
+
+# Test with map_entries (this internally calls make_map)
+query ?
+SELECT map_entries(column2) FROM test_map_keys ORDER BY column1;
+----
+[{key: a, value: ab}]
+NULL
+[{key: c, value: cd}]
+
+statement ok
+DROP TABLE test_map_keys;
+
+# Test with Parquet storage
+# This reproduces the issue where NULL map values cause "map key cannot be
null" error
+statement ok
+CREATE TABLE test_map_parquet_temp AS VALUES
+ ('1', MAP {'a': 'ab'});
+
+statement ok
+COPY test_map_parquet_temp TO '/tmp/test_map_parquet.parquet';
+
+statement ok
+DROP TABLE test_map_parquet_temp;
+
+statement ok
+CREATE EXTERNAL TABLE test_map_parquet
+STORED AS PARQUET
+LOCATION '/tmp/test_map_parquet.parquet';
+
+query T?
+SELECT * FROM test_map_parquet;
+----
+1 {a: ab}
+
+# Now create a table with NULL map
+statement ok
+CREATE TABLE test_map_parquet_null_temp AS VALUES
+ ('1', NULL);
+
+statement ok
+COPY test_map_parquet_null_temp TO '/tmp/test_map_parquet_null.parquet';
Review Comment:
Using '/tmp/' for test files is inconsistent with the project's standard
pattern. Other tests use 'test_files/scratch/' for temporary files. Consider
changing to: COPY test_map_parquet_null_temp TO
'test_files/scratch/map/test_map_parquet_null.parquet';
##########
datafusion/sqllogictest/test_files/map.slt:
##########
@@ -854,3 +854,168 @@ NULL
statement ok
drop table tt;
+
+# Test for issue with NULL map values
+# When a map column contains NULL values (not null keys/values within maps),
+
+statement ok
+CREATE TABLE test_null_map AS VALUES
+ ('1', MAP {'a': 'ab'}),
+ ('2', NULL),
+ ('3', MAP {'b': 'cd'});
+
+query T?
+SELECT * FROM test_null_map ORDER BY column1;
+----
+1 {a: ab}
+2 NULL
+3 {b: cd}
+
+# Test with mixed NULL and non-NULL maps
+statement ok
+CREATE TABLE test_null_map2 AS VALUES
+ ('1', MAP {'a': 'ab'}),
+ ('2', NULL),
+ ('3', MAP {'c': 'ef'}),
+ ('4', NULL);
+
+query T?
+SELECT * FROM test_null_map2 ORDER BY column1;
+----
+1 {a: ab}
+2 NULL
+3 {c: ef}
+4 NULL
+
+statement ok
+DROP TABLE test_null_map;
+
+statement ok
+DROP TABLE test_null_map2;
+
+# Test processing map keys with NULL map values
+# This simulates the scenario from the issue where a UDF processes map keys
+statement ok
+CREATE TABLE test_map_keys AS VALUES
+ ('1', MAP {'a': 'ab'}),
+ ('2', NULL),
+ ('3', MAP {'c': 'cd'});
+
+query ?
+SELECT map_keys(column2) FROM test_map_keys ORDER BY column1;
+----
+[a]
+NULL
+[c]
+
+# Test processing map values with NULL map values
+query ?
+SELECT map_values(column2) FROM test_map_keys ORDER BY column1;
+----
+[ab]
+NULL
+[cd]
+
+# Test with map_entries (this internally calls make_map)
+query ?
+SELECT map_entries(column2) FROM test_map_keys ORDER BY column1;
+----
+[{key: a, value: ab}]
+NULL
+[{key: c, value: cd}]
+
+statement ok
+DROP TABLE test_map_keys;
+
+# Test with Parquet storage
+# This reproduces the issue where NULL map values cause "map key cannot be
null" error
+statement ok
+CREATE TABLE test_map_parquet_temp AS VALUES
+ ('1', MAP {'a': 'ab'});
+
+statement ok
+COPY test_map_parquet_temp TO '/tmp/test_map_parquet.parquet';
+
+statement ok
+DROP TABLE test_map_parquet_temp;
+
+statement ok
+CREATE EXTERNAL TABLE test_map_parquet
+STORED AS PARQUET
+LOCATION '/tmp/test_map_parquet.parquet';
+
+query T?
+SELECT * FROM test_map_parquet;
+----
+1 {a: ab}
+
+# Now create a table with NULL map
+statement ok
+CREATE TABLE test_map_parquet_null_temp AS VALUES
+ ('1', NULL);
+
+statement ok
+COPY test_map_parquet_null_temp TO '/tmp/test_map_parquet_null.parquet';
+
+statement ok
+DROP TABLE test_map_parquet_null_temp;
+
+statement ok
+CREATE EXTERNAL TABLE test_map_parquet_null
+STORED AS PARQUET
+LOCATION '/tmp/test_map_parquet_null.parquet';
Review Comment:
The LOCATION path should match the updated COPY path. If following the
project's standard pattern, this should be: LOCATION
'test_files/scratch/map/test_map_parquet_null.parquet';
##########
datafusion/sqllogictest/test_files/map.slt:
##########
@@ -854,3 +854,168 @@ NULL
statement ok
drop table tt;
+
+# Test for issue with NULL map values
+# When a map column contains NULL values (not null keys/values within maps),
+
+statement ok
+CREATE TABLE test_null_map AS VALUES
+ ('1', MAP {'a': 'ab'}),
+ ('2', NULL),
+ ('3', MAP {'b': 'cd'});
+
+query T?
+SELECT * FROM test_null_map ORDER BY column1;
+----
+1 {a: ab}
+2 NULL
+3 {b: cd}
+
+# Test with mixed NULL and non-NULL maps
+statement ok
+CREATE TABLE test_null_map2 AS VALUES
+ ('1', MAP {'a': 'ab'}),
+ ('2', NULL),
+ ('3', MAP {'c': 'ef'}),
+ ('4', NULL);
+
+query T?
+SELECT * FROM test_null_map2 ORDER BY column1;
+----
+1 {a: ab}
+2 NULL
+3 {c: ef}
+4 NULL
+
+statement ok
+DROP TABLE test_null_map;
+
+statement ok
+DROP TABLE test_null_map2;
+
+# Test processing map keys with NULL map values
+# This simulates the scenario from the issue where a UDF processes map keys
+statement ok
+CREATE TABLE test_map_keys AS VALUES
+ ('1', MAP {'a': 'ab'}),
+ ('2', NULL),
+ ('3', MAP {'c': 'cd'});
+
+query ?
+SELECT map_keys(column2) FROM test_map_keys ORDER BY column1;
+----
+[a]
+NULL
+[c]
+
+# Test processing map values with NULL map values
+query ?
+SELECT map_values(column2) FROM test_map_keys ORDER BY column1;
+----
+[ab]
+NULL
+[cd]
+
+# Test with map_entries (this internally calls make_map)
+query ?
+SELECT map_entries(column2) FROM test_map_keys ORDER BY column1;
+----
+[{key: a, value: ab}]
+NULL
+[{key: c, value: cd}]
+
+statement ok
+DROP TABLE test_map_keys;
+
+# Test with Parquet storage
+# This reproduces the issue where NULL map values cause "map key cannot be
null" error
+statement ok
+CREATE TABLE test_map_parquet_temp AS VALUES
+ ('1', MAP {'a': 'ab'});
+
+statement ok
+COPY test_map_parquet_temp TO '/tmp/test_map_parquet.parquet';
Review Comment:
Using '/tmp/' for test files is inconsistent with the project's standard
pattern. Other tests in this repository use 'test_files/scratch/' for temporary
files (see copy.slt, parquet.slt, etc.). This ensures test isolation and proper
cleanup. Consider changing to: COPY test_map_parquet_temp TO
'test_files/scratch/map/test_map_parquet.parquet';
##########
datafusion/sqllogictest/test_files/map.slt:
##########
@@ -854,3 +854,168 @@ NULL
statement ok
drop table tt;
+
+# Test for issue with NULL map values
+# When a map column contains NULL values (not null keys/values within maps),
Review Comment:
The comment on line 859 is incomplete. It ends mid-sentence with a comma.
Consider completing the sentence, for example: '# When a map column contains
NULL values (not null keys/values within maps), these tests verify the map
functions handle them correctly.'
```suggestion
# When a map column contains NULL values (not null keys/values within maps),
these tests verify the map functions handle them correctly.
```
##########
datafusion/sqllogictest/test_files/map.slt:
##########
@@ -854,3 +854,168 @@ NULL
statement ok
drop table tt;
+
+# Test for issue with NULL map values
+# When a map column contains NULL values (not null keys/values within maps),
+
+statement ok
+CREATE TABLE test_null_map AS VALUES
+ ('1', MAP {'a': 'ab'}),
+ ('2', NULL),
+ ('3', MAP {'b': 'cd'});
+
+query T?
+SELECT * FROM test_null_map ORDER BY column1;
+----
+1 {a: ab}
+2 NULL
+3 {b: cd}
+
+# Test with mixed NULL and non-NULL maps
+statement ok
+CREATE TABLE test_null_map2 AS VALUES
+ ('1', MAP {'a': 'ab'}),
+ ('2', NULL),
+ ('3', MAP {'c': 'ef'}),
+ ('4', NULL);
+
+query T?
+SELECT * FROM test_null_map2 ORDER BY column1;
+----
+1 {a: ab}
+2 NULL
+3 {c: ef}
+4 NULL
+
+statement ok
+DROP TABLE test_null_map;
+
+statement ok
+DROP TABLE test_null_map2;
+
+# Test processing map keys with NULL map values
+# This simulates the scenario from the issue where a UDF processes map keys
+statement ok
+CREATE TABLE test_map_keys AS VALUES
+ ('1', MAP {'a': 'ab'}),
+ ('2', NULL),
+ ('3', MAP {'c': 'cd'});
+
+query ?
+SELECT map_keys(column2) FROM test_map_keys ORDER BY column1;
+----
+[a]
+NULL
+[c]
+
+# Test processing map values with NULL map values
+query ?
+SELECT map_values(column2) FROM test_map_keys ORDER BY column1;
+----
+[ab]
+NULL
+[cd]
+
+# Test with map_entries (this internally calls make_map)
+query ?
+SELECT map_entries(column2) FROM test_map_keys ORDER BY column1;
+----
+[{key: a, value: ab}]
+NULL
+[{key: c, value: cd}]
+
+statement ok
+DROP TABLE test_map_keys;
+
+# Test with Parquet storage
+# This reproduces the issue where NULL map values cause "map key cannot be
null" error
+statement ok
+CREATE TABLE test_map_parquet_temp AS VALUES
+ ('1', MAP {'a': 'ab'});
+
+statement ok
+COPY test_map_parquet_temp TO '/tmp/test_map_parquet.parquet';
+
+statement ok
+DROP TABLE test_map_parquet_temp;
+
+statement ok
+CREATE EXTERNAL TABLE test_map_parquet
+STORED AS PARQUET
+LOCATION '/tmp/test_map_parquet.parquet';
Review Comment:
The LOCATION path should match the updated COPY path. If following the
project's standard pattern, this should be: LOCATION
'test_files/scratch/map/test_map_parquet.parquet';
##########
datafusion/sqllogictest/test_files/map.slt:
##########
@@ -854,3 +854,168 @@ NULL
statement ok
drop table tt;
+
+# Test for issue with NULL map values
+# When a map column contains NULL values (not null keys/values within maps),
+
+statement ok
+CREATE TABLE test_null_map AS VALUES
+ ('1', MAP {'a': 'ab'}),
+ ('2', NULL),
+ ('3', MAP {'b': 'cd'});
+
+query T?
+SELECT * FROM test_null_map ORDER BY column1;
+----
+1 {a: ab}
+2 NULL
+3 {b: cd}
+
+# Test with mixed NULL and non-NULL maps
+statement ok
+CREATE TABLE test_null_map2 AS VALUES
+ ('1', MAP {'a': 'ab'}),
+ ('2', NULL),
+ ('3', MAP {'c': 'ef'}),
+ ('4', NULL);
+
+query T?
+SELECT * FROM test_null_map2 ORDER BY column1;
+----
+1 {a: ab}
+2 NULL
+3 {c: ef}
+4 NULL
+
+statement ok
+DROP TABLE test_null_map;
+
+statement ok
+DROP TABLE test_null_map2;
+
+# Test processing map keys with NULL map values
+# This simulates the scenario from the issue where a UDF processes map keys
+statement ok
+CREATE TABLE test_map_keys AS VALUES
+ ('1', MAP {'a': 'ab'}),
+ ('2', NULL),
+ ('3', MAP {'c': 'cd'});
+
+query ?
+SELECT map_keys(column2) FROM test_map_keys ORDER BY column1;
+----
+[a]
+NULL
+[c]
+
+# Test processing map values with NULL map values
+query ?
+SELECT map_values(column2) FROM test_map_keys ORDER BY column1;
+----
+[ab]
+NULL
+[cd]
+
+# Test with map_entries (this internally calls make_map)
+query ?
+SELECT map_entries(column2) FROM test_map_keys ORDER BY column1;
+----
+[{key: a, value: ab}]
+NULL
+[{key: c, value: cd}]
+
+statement ok
+DROP TABLE test_map_keys;
+
+# Test with Parquet storage
+# This reproduces the issue where NULL map values cause "map key cannot be
null" error
+statement ok
+CREATE TABLE test_map_parquet_temp AS VALUES
+ ('1', MAP {'a': 'ab'});
+
+statement ok
+COPY test_map_parquet_temp TO '/tmp/test_map_parquet.parquet';
+
+statement ok
+DROP TABLE test_map_parquet_temp;
+
+statement ok
+CREATE EXTERNAL TABLE test_map_parquet
+STORED AS PARQUET
+LOCATION '/tmp/test_map_parquet.parquet';
+
+query T?
+SELECT * FROM test_map_parquet;
+----
+1 {a: ab}
+
+# Now create a table with NULL map
+statement ok
+CREATE TABLE test_map_parquet_null_temp AS VALUES
+ ('1', NULL);
+
+statement ok
+COPY test_map_parquet_null_temp TO '/tmp/test_map_parquet_null.parquet';
+
+statement ok
+DROP TABLE test_map_parquet_null_temp;
+
+statement ok
+CREATE EXTERNAL TABLE test_map_parquet_null
+STORED AS PARQUET
+LOCATION '/tmp/test_map_parquet_null.parquet';
+
+query T?
+SELECT * FROM test_map_parquet_null;
+----
+1 NULL
+
+# Create a table with mixed NULL and non-NULL maps
+statement ok
+CREATE TABLE test_map_parquet_mixed_temp AS VALUES
+ ('1', MAP {'a': 'ab'}),
+ ('2', NULL),
+ ('3', MAP {'c': 'cd'});
+
+statement ok
+COPY test_map_parquet_mixed_temp TO '/tmp/test_map_parquet_mixed.parquet';
Review Comment:
Using '/tmp/' for test files is inconsistent with the project's standard
pattern. Other tests use 'test_files/scratch/' for temporary files. Consider
changing to: COPY test_map_parquet_mixed_temp TO
'test_files/scratch/map/test_map_parquet_mixed.parquet';
##########
datafusion/sqllogictest/test_files/map.slt:
##########
@@ -854,3 +854,168 @@ NULL
statement ok
drop table tt;
+
+# Test for issue with NULL map values
+# When a map column contains NULL values (not null keys/values within maps),
+
+statement ok
+CREATE TABLE test_null_map AS VALUES
+ ('1', MAP {'a': 'ab'}),
+ ('2', NULL),
+ ('3', MAP {'b': 'cd'});
+
+query T?
+SELECT * FROM test_null_map ORDER BY column1;
+----
+1 {a: ab}
+2 NULL
+3 {b: cd}
+
+# Test with mixed NULL and non-NULL maps
+statement ok
+CREATE TABLE test_null_map2 AS VALUES
+ ('1', MAP {'a': 'ab'}),
+ ('2', NULL),
+ ('3', MAP {'c': 'ef'}),
+ ('4', NULL);
+
+query T?
+SELECT * FROM test_null_map2 ORDER BY column1;
+----
+1 {a: ab}
+2 NULL
+3 {c: ef}
+4 NULL
+
+statement ok
+DROP TABLE test_null_map;
+
+statement ok
+DROP TABLE test_null_map2;
+
+# Test processing map keys with NULL map values
+# This simulates the scenario from the issue where a UDF processes map keys
+statement ok
+CREATE TABLE test_map_keys AS VALUES
+ ('1', MAP {'a': 'ab'}),
+ ('2', NULL),
+ ('3', MAP {'c': 'cd'});
+
+query ?
+SELECT map_keys(column2) FROM test_map_keys ORDER BY column1;
+----
+[a]
+NULL
+[c]
+
+# Test processing map values with NULL map values
+query ?
+SELECT map_values(column2) FROM test_map_keys ORDER BY column1;
+----
+[ab]
+NULL
+[cd]
+
+# Test with map_entries (this internally calls make_map)
+query ?
+SELECT map_entries(column2) FROM test_map_keys ORDER BY column1;
+----
+[{key: a, value: ab}]
+NULL
+[{key: c, value: cd}]
+
+statement ok
+DROP TABLE test_map_keys;
+
+# Test with Parquet storage
+# This reproduces the issue where NULL map values cause "map key cannot be
null" error
+statement ok
+CREATE TABLE test_map_parquet_temp AS VALUES
+ ('1', MAP {'a': 'ab'});
+
+statement ok
+COPY test_map_parquet_temp TO '/tmp/test_map_parquet.parquet';
+
+statement ok
+DROP TABLE test_map_parquet_temp;
+
+statement ok
+CREATE EXTERNAL TABLE test_map_parquet
+STORED AS PARQUET
+LOCATION '/tmp/test_map_parquet.parquet';
+
+query T?
+SELECT * FROM test_map_parquet;
+----
+1 {a: ab}
+
+# Now create a table with NULL map
+statement ok
+CREATE TABLE test_map_parquet_null_temp AS VALUES
+ ('1', NULL);
+
+statement ok
+COPY test_map_parquet_null_temp TO '/tmp/test_map_parquet_null.parquet';
+
+statement ok
+DROP TABLE test_map_parquet_null_temp;
+
+statement ok
+CREATE EXTERNAL TABLE test_map_parquet_null
+STORED AS PARQUET
+LOCATION '/tmp/test_map_parquet_null.parquet';
+
+query T?
+SELECT * FROM test_map_parquet_null;
+----
+1 NULL
+
+# Create a table with mixed NULL and non-NULL maps
+statement ok
+CREATE TABLE test_map_parquet_mixed_temp AS VALUES
+ ('1', MAP {'a': 'ab'}),
+ ('2', NULL),
+ ('3', MAP {'c': 'cd'});
+
+statement ok
+COPY test_map_parquet_mixed_temp TO '/tmp/test_map_parquet_mixed.parquet';
+
+statement ok
+DROP TABLE test_map_parquet_mixed_temp;
+
+statement ok
+CREATE EXTERNAL TABLE test_map_parquet_mixed
+STORED AS PARQUET
+LOCATION '/tmp/test_map_parquet_mixed.parquet';
Review Comment:
The LOCATION path should match the updated COPY path. If following the
project's standard pattern, this should be: LOCATION
'test_files/scratch/map/test_map_parquet_mixed.parquet';
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]