Skip to content

map_extract returns [NULL] instead of [] for missing keys #24981

Description

@neilconway

Describe the bug

The docs for map_extract say that it returns an empty list if the requested key is not present in the map, but that is not the implemented behavior: [NULL] is returned instead. This behavior does not match how map_extract behaves in DuckDB; it also makes it impossible to distinguish between an absent key and a key whose associated value is NULL, which is arguably the point of having map_extract return a list in the first place.

To Reproduce

SELECT
    map_extract(MAP {'a': 1, 'b': NULL}, 'a') AS present,
    map_extract(MAP {'a': 1, 'b': NULL}, 'b') AS present_null,
    map_extract(MAP {'a': 1, 'b': NULL}, 'c') AS missing,
    element_at(MAP {'a': 1, 'b': NULL}, 'c') AS alias_missing;

Verified using DataFusion CLI 55.0.0 and DuckDB v1.5.5:

Engine present present_null missing alias_missing
DataFusion [1] [NULL] [NULL] [NULL]
DuckDB [1] [NULL] [] []

Expected behavior

map_extract should return [] for a missing key.

Additional context

No response

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

bugSomething isn't working

Type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions