Skip to content

Type coercion fails for MAP literals with NULL values across a VALUES list #23474

Description

@PG1204

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': NULL});

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.

Additional context

No response

Metadata

Metadata

Assignees

Labels

bugSomething isn't working

Type

Fields

No fields configured for Bug.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions