You are viewing a plain text version of this content. The canonical link for it is here.
Posted to github@arrow.apache.org by "scsmithr (via GitHub)" <gi...@apache.org> on 2023/04/14 23:47:30 UTC
[GitHub] [arrow-datafusion] scsmithr opened a new issue, #6016: Unable to query view with a qualified name
scsmithr opened a new issue, #6016:
URL: https://github.com/apache/arrow-datafusion/issues/6016
### Describe the bug
Creating a view in a new schema then trying to querying that view using its qualified name results in an error. See below:
```
DataFusion CLI v22.0.0
❯ create schema s;
0 rows in set. Query took 0.007 seconds.
❯ create view s.v as (select 1 as a);
0 rows in set. Query took 0.004 seconds.
❯ select * from s.v;
Schema error: No field named s.v.a. Valid fields are "s.v".a.
```
I'm also not able to us fully qualified field names to select from this view either:
```
❯ select a from s.v;
Schema error: No field named s.v.a. Valid fields are "s.v".a.
❯ select s.v.a;
Schema error: No field named s.v.a.
❯ select "s.v".a;
Schema error: No field named s.v.a.
```
### To Reproduce
Using datafusion-cli
```
DataFusion CLI v22.0.0
❯ create schema s;
0 rows in set. Query took 0.007 seconds.
❯ create view s.v as (select 1 as a);
0 rows in set. Query took 0.004 seconds.
❯ select * from s.v;
Schema error: No field named s.v.a. Valid fields are "s.v".a.
```
### Expected behavior
I can run `select * from s.v` (along with the qualified alternatives).
### Additional context
Also fails in DataFusion 21.1.0 & 21.0.0:
```
DataFusion CLI v21.1.0
❯ create schema s;
0 rows in set. Query took 0.007 seconds.
❯ create view s.v as select 1 as a;
0 rows in set. Query took 0.004 seconds.
❯ select * from s.v
;
Schema error: No field named "s"."v"."a". Valid fields are "s.v"."a".
```
Works as expected in 20.0.0
```
DataFusion CLI v20.0.0
❯ create schema s;
0 rows in set. Query took 0.008 seconds.
❯ create view s.v as select 1 as a;
0 rows in set. Query took 0.004 seconds.
❯ select * from s.v;
+---+
| a |
+---+
| 1 |
+---+
1 row in set. Query took 0.010 seconds.
```
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: github-unsubscribe@arrow.apache.org.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [arrow-datafusion] alamb closed issue #6016: Unable to query view with a qualified name
Posted by "alamb (via GitHub)" <gi...@apache.org>.
alamb closed issue #6016: Unable to query view with a qualified name
URL: https://github.com/apache/arrow-datafusion/issues/6016
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: github-unsubscribe@arrow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [arrow-datafusion] scsmithr commented on issue #6016: Unable to query view with a qualified name
Posted by "scsmithr (via GitHub)" <gi...@apache.org>.
scsmithr commented on issue #6016:
URL: https://github.com/apache/arrow-datafusion/issues/6016#issuecomment-1509897051
This rule was in place before (but on the `Optimizer`). I believe changes made in https://github.com/apache/arrow-datafusion/pull/5343 are what led to this.
I opened up https://github.com/apache/arrow-datafusion/pull/6022 which makes subquery aliases a table reference which should fix this issue.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: github-unsubscribe@arrow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [arrow-datafusion] Jefffrey commented on issue #6016: Unable to query view with a qualified name
Posted by "Jefffrey (via GitHub)" <gi...@apache.org>.
Jefffrey commented on issue #6016:
URL: https://github.com/apache/arrow-datafusion/issues/6016#issuecomment-1509492914
Looks to be due to the InlineTableScan analyzer rule, specifically:
https://github.com/apache/arrow-datafusion/blob/68bd113a74f045cd24d01418c92c83f2e3a18853/datafusion/optimizer/src/analyzer/inline_table_scan.rs#L56-L79
Where it converts view into a subquery alias, using the `table_name` as the subquery alias:
https://github.com/apache/arrow-datafusion/blob/68bd113a74f045cd24d01418c92c83f2e3a18853/datafusion/optimizer/src/analyzer/inline_table_scan.rs#L76
But doesn't rewrite the parent projection to use this correct subquery alias.
So given input plan:
```
Projection: cat.sch.v.c1, cat.sch.v.c2, cat.sch.v.c3
TableScan: cat.sch.v
```
After the rule this becomes:
```
Projection: cat.sch.v.c1, cat.sch.v.c2, cat.sch.v.c3
SubqueryAlias: cat.sch.v
Projection: aggregate_test_100.c1, aggregate_test_100.c2, aggregate_test_100.c3
Projection: aggregate_test_100.c1, aggregate_test_100.c2, aggregate_test_100.c3
TableScan: aggregate_test_100
```
The top level projection, `Projection: cat.sch.v.c1, cat.sch.v.c2, cat.sch.v.c3`, taking only `c1`, is better understood as:
```
Column { relation: Some(Full { catalog: "cat", schema: "sch", table: "v" }), name: "c1" }
```
Can see it still refers to specific catalog, schema, and table. Whereas the subquery alias `SubqueryAlias: cat.sch.v` has erased this since the alias is `cat.sch.v` as a whole
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: github-unsubscribe@arrow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org