Skip to content
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

CTE/WITH .. UNION ALL confuses name resolution in WHERE #1509

Closed
FauxFaux opened this issue Dec 30, 2021 · 0 comments · Fixed by #1781
Closed

CTE/WITH .. UNION ALL confuses name resolution in WHERE #1509

FauxFaux opened this issue Dec 30, 2021 · 0 comments · Fixed by #1781
Labels
bug Something isn't working datafusion Changes in the datafusion crate help wanted Extra attention is needed

Comments

@FauxFaux
Copy link

Describe the bug
A construction like:

with x as (
  select a from baz
  union all
  select a from bar
)
select a 
from x
where a=1

..gives the error:

Plan("No field named 'x.a'. Valid fields are 'baz.a'.")

Explicitly specifying where x.a gives the same error, so that is resolving correctly?

Writing the query as where baz.a=1 instead gives:

Plan("No field named 'baz.a'. Valid fields are 'x.a'.")

To Reproduce
Steps to reproduce the behavior:

❯ create table bar as select 1 as a;
❯ create table baz as select 1 as a;
❯ with x as (select a from baz union all select a from bar) select a from x;
+---+
| a |
+---+
| 1 |
| 1 |
+---+
❯ with x as (select a from baz union all select a from bar) select a from x where a=1;
Plan("No field named 'x.a'. Valid fields are 'baz.a'.")

Expected behavior
I believe SELECT a FROM x WHERE a=1 should function as if x was a single table containing a column named a, as shown in non-filtered select in the reproduction steps above.

Additional context
This isn't something to do with memory tables; it happens to my Parquet EXTERNAL tables too.

The error messaging here isn't great for my parquet files, which already use dotted notation, like select "address.line1" from address, now we have "address.address.line1".

@FauxFaux FauxFaux added the bug Something isn't working label Dec 30, 2021
@houqp houqp added the help wanted Extra attention is needed label Jan 12, 2022
@alamb alamb added the datafusion Changes in the datafusion crate label Feb 10, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working datafusion Changes in the datafusion crate help wanted Extra attention is needed
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants