Skip to content

unnest + field access of "list of struct" broken #12921

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
crepererum opened this issue Oct 14, 2024 · 3 comments
Closed

unnest + field access of "list of struct" broken #12921

crepererum opened this issue Oct 14, 2024 · 3 comments
Labels
bug Something isn't working

Comments

@crepererum
Copy link
Contributor

Describe the bug

See reproducer.

To Reproduce

Use the following sqllogictest:

statement ok
CREATE TABLE lists_of_structs_table
AS VALUES 
    ('row1', [named_struct('a', 1, 'b', 2), named_struct('a', 2, 'b', 3)]),
    ('row2', [named_struct('a', 4, 'b', 5)])
;

query T?
select column1, unnest(column2) from lists_of_structs_table;
----
row1 {a: 1, b: 2}
row1 {a: 2, b: 3}
row2 {a: 4, b: 5}

# unnest + struct element access
query error DataFusion error: Schema error: No field named b. Valid fields are lists_of_structs_table.column1, lists_of_structs_table.column2.
select column1, unnest(column2)["b"] from lists_of_structs_table;

Expected behavior

Since unnest creates a struct column, I feel that this should work.

Additional context

Tested w/ 5391c98 .

@crepererum crepererum added the bug Something isn't working label Oct 14, 2024
@duongcongtoai
Copy link
Contributor

let me take a look, i'm working on some cleanup regarding this feature: #12836

@duongcongtoai
Copy link
Contributor

duongcongtoai commented Oct 15, 2024

I think this is some problem with the parser, and perhaps not yet supported.
The query will be performed correctly if replace double quote with single quote

select column1, unnest(column2)['b'] from lists_of_structs_table;

The query with double quote will fail for normal queries, not just unnest

@crepererum
Copy link
Contributor Author

Oh 🤦, I think I've tripped over the quoting then. I can never remember which is the string and which one is the identifier in SQL. In that case, the error message is actually correct, since my query tries to index the struct with a dynamic string from column b, which doesn't exist. The intention was to index with a static string 'b' (as you suggested). So that's not actually a bug.

@crepererum crepererum closed this as not planned Won't fix, can't repro, duplicate, stale Oct 16, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants