[snowflake] Support FROM (table_name) alias#260
Conversation
Pull Request Test Coverage Report for Build 303837987
💛 - Coveralls |
FROM (table_name) alias
tests/sqlparser_common.rs
Outdated
| #[macro_use] | ||
| #[path = "utils/mod.rs"] | ||
| mod utils; | ||
|
|
||
| use utils::*; |
There was a problem hiding this comment.
There's test_utils.rs for that already.
There was a problem hiding this comment.
The actual reason that i don't use the test util is that i want to share the macro between the test ,
And if I understand it correct , the src and the the test are not considered in the same crate , so i can export macro only via #[macro_export] directive, but that mean the macro will be available not only for the test but to all users of the lib , and that something that i want to avoid (please correct me if i wrong..).
Anyway - I moved the join and table macros to test_utils.rs and change the utils dir that i crated to macros dir, hope you ok with that.
btw - why test_util.rs located inside the source ?
1ad467f to
44290ab
Compare
44290ab to
7355eff
Compare
Co-authored-by: Eyal Leshem <eyal@satoricyber.com>
2280580 to
92c6b49
Compare
|
I first rebased this onto |
|
Regarding the need to share helper macros, as well as helper functions, discussed in #260 (comment) -- I added a commit a3a0d7b that demonstrates how I'd like to solve this. I added some comments that I hope will explain my reasoning, please let me know if they're not clear. The second part of the PR (and #260 (comment) ) I want to look over again before merging. |
|
Thanks a lot for the rebasing and the fixes! Is there any change needed from me , or you just want to continue review it? |
|
No, I was just running out of time that night, and wanted to share the part I believed to be ready. I'll try to get to the other one sometime "soon"... |
To share helper macros between various tests/* we added a new module (tests/macros/mod.rs). This made the prologue to be used in tests quite long and a little weird: ``` #[macro_use] #[path = "macros/mod.rs"] mod macros; use sqlparser::test_utils::*; ``` This simplifies it to: ``` #[macro_use] mod test_utils; use test_utils::*; ``` - and switches all existing tests to the new prologue simultaneously... ...while fixing a few other inconsistencies and adding a few comments about the way `test_utils` work.
It was an omission of the original implementation.
I don't know why it took me so long to realize it, but we use |
|
I am ok with that , |
Snowflake diverges from the standard and from most of the other implementations by allowing extra parentheses not only around a join, but around lone table names (e.g. `FROM (mytable [AS alias])`) and around derived tables (e.g. `FROM ((SELECT ...) [AS alias])`) as well. Initially this was implemented in apache#154 by (ab)using `TableFactor::NestedJoin` to represent anything nested in extra set of parens. Afterwards we learned in apache#223 that in cases of such extraneous nesting Snowflake allows specifying the alias both inside and outside parens, but not both - consider: FROM (table_factor AS inner_alias) AS outer_alias We've considered implementing this by changing `TableFactor::NestedJoin` to a `TableFactor::Nested { inner: TableWithJoins, alias: Option<TableAlias> }`, but that seemed too generic, as no known dialect supports duplicate aliases, as shown above, nor naming nested joins `(foo NATURAL JOIN bar) alias`. So we decided on making a smaller change (with no modifications to the AST), that is also more appropriate to the contributors to the Snowflake dialect: 1) Revert apache#154 by rejecting `FROM (table or derived table)` in most dialects. 2) For `dialect_of!(self is SnowflakeDialect | GenericDialect)` parse and strip the extraneous parentheses, e.g. `(mytable) AS alias` -> `(mytable AS alias)` Co-authored-by: Eyal Leshem <eyal@satoricyber.com>
1c546de to
ad72cda
Compare
|
@eyalleshem @nickolay i made a pull request #551 for nested table with alias |
Initially discussed in #223 and #244. Closes #223.
The description copied from the commit:
Snowflake diverges from the standard and from most of the other implementations by allowing extra parentheses not only around a join, but around lone table names (e.g.
FROM (mytable [AS alias])) and around derived tables (e.g.FROM ((SELECT ...) [AS alias])) as well.Initially this was implemented in #154 by (ab)using
TableFactor::NestedJointo represent anything nested in extra set of parens.Afterwards we learned in #223 that in cases of such extraneous nesting Snowflake allows specifying the alias both inside and outside parens, but not both - consider:
We've considered implementing this by changing
TableFactor::NestedJointo aTableFactor::Nested { inner: TableWithJoins, alias: Option<TableAlias> }, but that seemed too generic, as no known dialect supports duplicate aliases, as shown above, nor naming nested joins(foo NATURAL JOIN bar) alias. So we decided on making a smaller change (with no modifications to the AST), that is also more appropriate to the contributors to the Snowflake dialect:Revert Fail to parse - "select * from (table_name)" #154 by rejecting
FROM (table or derived table)in most dialects.For
dialect_of!(self is SnowflakeDialect | GenericDialect)parseand strip the extraneous parentheses:
(mytable) AS alias->(mytable AS alias)