Skip to content

make_array coercion failure when argument is of type struct #20429

@Mark1626

Description

@Mark1626

Describe the bug

Not sure if this is a bug or expected behaviour. make_array works with simple structs where the keys match

The following query works

> SELECT make_array(named_struct('1', 'a'), named_struct('1', 'b'));
+---------------------------------------------------------------------------------+
| make_array(named_struct(Utf8("1"),Utf8("a")),named_struct(Utf8("1"),Utf8("b"))) |
+---------------------------------------------------------------------------------+
| [{1: a}, {1: b}]                                                                |
+---------------------------------------------------------------------------------+
1 row(s) fetched. 
Elapsed 0.013 seconds.

but fails when the struct's keys mismatch

To Reproduce

> SELECT make_array(named_struct('1', 'a'), named_struct('2', 'b'));
Error during planning: Execution error: Function 'make_array' user-defined coercion failed with "Error during planning: Failed to unify argument types of make_array: [Struct(\"1\": Utf8), Struct(\"2\": Utf8)]" No function matches the given name and argument types 'make_array(Struct("1": Utf8), Struct("2": Utf8))'. You might need to add explicit type casts.
	Candidate functions:
	make_array(UserDefined)

Expected behavior

Databricks for instance in this case assigns it's own column names col1, col2 for the struct fields. Should something like this be done? Or is it up to the user to add explicit casts

Image

Additional context

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions