PG1204 opened a new issue, #23474:
URL: https://github.com/apache/datafusion/issues/23474

   ### Describe the bug
   
   ### Describe the bug:
   A MAP {'key': NULL} literal in a VALUES list fails type coercion when other 
rows in the same list have a concrete value type. The bare NULL gets inferred 
as Null type instead of being coerced to the value type of the surrounding rows.
   Surfaced while writing sqllogictest coverage in #23406 for #15428. Broader 
context: NULL literal type inference across a VALUES list works for scalar 
types (e.g. VALUES (1), (NULL) coerces NULL to Int64), but the same inference 
does not extend into the value type of a Map literal. An explicit CAST(NULL AS 
BIGINT) is currently required as a workaround, which is what map.slt uses.
   
   ### To Reproduce:
   Run against DataFusion main (also reproduces on DataFusion CLI v54.0.0):
   CREATE TABLE t AS VALUES
     (MAP {'k1': 1, 'k2': 2}),
     (MAP {'k1': NULL});
   
   Actual error:
   Error during planning: Inconsistent data type across values list at row 1 
column 0. Was Map("entries": non-null Struct("key": non-null Utf8, "value": 
Int64), unsorted) but found Map("entries": non-null Struct("key": non-null 
Utf8, "value": Null), unsorted)
   
   Workaround: an explicit cast works:
   CREATE TABLE t AS VALUES
     (MAP {'k1': 1, 'k2': 2}),
     (MAP {'k1': CAST(NULL AS BIGINT)});
   
   ### Expected behaviour:
   The bare NULL in MAP {'k1': NULL} should be coerced to the value type of the 
other rows in the VALUES list (Int64 in this case), so the CREATE TABLE 
succeeds with a Map(Utf8, Int64) column type where the second row has a NULL 
value.
   
   
   
   ### To Reproduce
   
   _No response_
   
   ### Expected behavior
   
   _No response_
   
   ### Additional context
   
   _No response_


-- 
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]

Reply via email to