Skip to content

Use dialects in the parser for support snowflake aliasing syntax #244

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
wants to merge 2 commits into from

Conversation

eyalleshem
Copy link
Contributor

Snowflake DB allow single table to be within parenthesis.
This behaviour is diffrent than other DB ,
and it has some impact on the parsing table factor.

For supporting we do the following :

  1. Add refrence to the dialect in the parser
  2. Add Snowflake dialect
  3. add function to the dialect trait the identify if single table inside parenthesis allowed
  4. When parsing table factor in the allow/deny single table inside parenthesis according to dialect

@coveralls
Copy link

coveralls commented Jul 28, 2020

Pull Request Test Coverage Report for Build 189751011

  • 123 of 146 (84.25%) changed or added relevant lines in 6 files are covered.
  • No unchanged relevant lines lost coverage.
  • Overall coverage decreased (-0.3%) to 91.533%

Changes Missing Coverage Covered Lines Changed/Added Lines %
src/dialect/mod.rs 1 2 50.0%
src/dialect/snowflake.rs 11 12 91.67%
tests/sqlparser_common.rs 6 7 85.71%
tests/sqlparser_snowflake.rs 65 69 94.2%
src/parser.rs 37 53 69.81%
Totals Coverage Status
Change from base Build 188566846: -0.3%
Covered Lines: 4508
Relevant Lines: 4925

💛 - Coveralls

@eyalleshem eyalleshem force-pushed the master branch 3 times, most recently from 43c61af to a4787f1 Compare July 29, 2020 07:28
@eyalleshem eyalleshem changed the title [WIP] use dialects in the parser for support snowflake aliasing syntax Use dialects in the parser for support snowflake aliasing syntax Jul 29, 2020
@eyalleshem eyalleshem force-pushed the master branch 2 times, most recently from 464b770 to 2b26ac5 Compare July 31, 2020 08:21
…syntax

Snowflake DB allow single table to be within parenthesis.
This behaviour is diffrent than other DB ,
and it has some impact on the parsing table factor.

For supporting we do the following :
1. Add refrence to the dialect in the parser
2. Add Snowflake dialect
3. add function to the dialect trait the identify if single table inside parenthesis allowed
4. When parsing table factor in the allow/deny single table inside parenthesis according to dialect
Copy link
Contributor

@nickolay nickolay left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I pushed a commit with an alternative implementation of your idea: 94919ba - what do you think?

Also see some comments inline:

Comment on lines +43 to +45
fn alllow_single_table_in_parenthesis(&self) -> bool {
false
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please note #241 (comment)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry :| - I don't understand what you mean by that ..
(to note #241 in code comment ? or something in the code is not aligned with what you commented in #241 (comment) )
Can you please elborate ?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In that comment I tried to argue for using if self.dialect <is snowflake> checks rather than self.dialect.alllow_single_table_in_parenthesis(), at least until we better understand when to use which approach.

Comment on lines +3 to +4
#[derive(Debug, Default)]
pub struct SnowflakeDialect;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd like the new dialect (including a separate test file), the dialect-specific parsing infrastructure, and the table factor parsing fix to be landed separately.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You mean by different PR's or commits ?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I meant PRs.

Comment on lines +32 to +40
macro_rules! nest {
($base:expr $(, $join:expr)*) => {
TableFactor::NestedJoin(Box::new(TableWithJoins {
relation: $base,
joins: vec![$(join($join)),*]
}))
};
}

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please don't duplicate code.

Comment on lines +41 to +45
fn sf() -> TestedDialects {
TestedDialects {
dialects: vec![Box::new(SnowflakeDialect {})],
}
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please place this at the end of the file, and include a sf_and_generic() helper, as in other files.

}
}

fn get_from_section_from_select_query(query: &str) -> Vec<TableWithJoins> {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I haven't been able to carefully review the rest, because the move of existing tests and the addition of new ones are combined in a single commit (see the request above).

@eyalleshem
Copy link
Contributor Author

Thanks for your comment and for the commit with the suggestions (i also tech me some features or rust that i was not aware of ) , agree thats more elegant - and i will merge it into the PR .

I also asked inline for some clarifications for some off the comments , as i don't sure what the action item for them ..

@eyalleshem
Copy link
Contributor Author

Ok, so i am closing this PR - and will open 3 smaller..

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants