Skip to content

unnest errors in conjunction with SELECT * #12684

@ahirner

Description

@ahirner

Describe the bug

One cannot include all colums in addition to the unnested column. Consequently, excluding some of all columns also stopped working in 42.

To Reproduce

Create table with regular and to be unnested columns:

CREATE TABLE d AS VALUES
('x', 1, [named_struct('a', 1, 'b', 2)]),
('y', 2, [named_struct('a', 3, 'b', 4), named_struct('a', 5, 'b', 6)]);

Query unnested structs but also all others.

SELECT unnest(column3), * FROM d;

Error:

Schema error: No field named "*". Valid fields are "UNNEST(d.column3)", d.column1, d.column2, d.column3, "UNNEST(d.column3)", d.column1, d.column2, d.column3.

When excluding some via except:

SELECT unnest(column3), * except (column3, column1) FROM d;

.. the error becomes:

Schema error: No field named "* EXCEPT (column3, column1)". Valid fields are "UNNEST(d.column3)", d.column2, "UNNEST(d.column3)", d.column2.

Expected behavior

The qeries do work in datafusion 41:

+-------------------+---------+---------+------------------------------+
| unnest(d.column3) | column1 | column2 | column3                      |
+-------------------+---------+---------+------------------------------+
| {a: 1, b: 2}      | x       | 1       | [{a: 1, b: 2}]               |
| {a: 3, b: 4}      | y       | 2       | [{a: 3, b: 4}, {a: 5, b: 6}] |
| {a: 5, b: 6}      | y       | 2       | [{a: 3, b: 4}, {a: 5, b: 6}] |
+-------------------+---------+---------+------------------------------+

..with except (column3, column1):

+-------------------+---------+
| unnest(d.column3) | column2 |
+-------------------+---------+
| {a: 1, b: 2}      | 1       |
| {a: 3, b: 4}      | 2       |
| {a: 5, b: 6}      | 2       |
+-------------------+---------+

Additional context

It seems a to be a parsing issue, or perhaps loosing track of field names (#12560)?

Metadata

Metadata

Assignees

Labels

bugSomething isn't workinghelp wantedExtra attention is needed

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions