Skip to content

Fixing alter table multi partition #657

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

Conversation

bitemyapp
Copy link
Contributor

Fixes examples like this:

ALTER TABLE `database`.`table` ADD IF NOT EXISTS PARTITION (`hour` = '2020-12-24T17') PARTITION (`hour` = '2020-12-24T18') PARTITION (`hour` = '2020-12-24T19')

This includes the backtick commit by necessity but we can merge them all at once or the backtick commit separately, your choice.

@bitemyapp bitemyapp force-pushed the bitemyapp/fixing-alter-table-multi-partition branch from 7c74aa9 to 879f529 Compare October 5, 2022 16:20
@coveralls
Copy link

coveralls commented Oct 5, 2022

Pull Request Test Coverage Report for Build 3206495452

  • 0 of 0 changed or added relevant lines in 0 files are covered.
  • 328 unchanged lines in 2 files lost coverage.
  • Overall coverage increased (+0.01%) to 85.673%

Files with Coverage Reduction New Missed Lines %
src/ast/ddl.rs 1 81.37%
src/parser.rs 327 83.18%
Totals Coverage Status
Change from base Build 3199854514: 0.01%
Covered Lines: 10339
Relevant Lines: 12068

💛 - Coveralls

@bitemyapp bitemyapp force-pushed the bitemyapp/fixing-alter-table-multi-partition branch from 879f529 to 03d778d Compare October 5, 2022 17:59
@bitemyapp
Copy link
Contributor Author

Buhhhh forgot to cargo fmt again, force-pushed an amended commit for this.

@bitemyapp bitemyapp force-pushed the bitemyapp/fixing-alter-table-multi-partition branch from 03d778d to d5c9854 Compare October 6, 2022 14:57
@bitemyapp
Copy link
Contributor Author

Switched the match expression to matches! because clippy bullied me.

@AugustoFKL
Copy link
Contributor

@bitemyapp please add information about sources and references. Only putting the query there makes me search for 5 dialects at least before making sure that's valid

self.expect_token(&Token::LParen)?;
let partitions = self.parse_comma_separated(Parser::parse_expr)?;
self.expect_token(&Token::RParen)?;
if self.peek_keyword(Keyword::PARTITION) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Is this hive-specific? It looks like so, right?

Could you please guarantee that the dialect is Hive or Generic before accepting more than one partition?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

To be frank I'd rather not. It's logic that shouldn't break the parser for anyone parsing a different dialect and it's abundantly clear that this library is not attempting to be a validation/standards-verification parser. If you have a contrary example where this breaks a parse that should've worked in another context I'll see what I can do to deal with that. I don't think that exists yet though. I lost a lot of time to being confused by the dialect specialization and I'd rather not add more of it.

There isn't any dialect specialization happening anywhere else near this part of the parser that I can recall either.

Copy link
Contributor

Choose a reason for hiding this comment

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

Following are three examples of specialization by dialect inside the code.

My problem is that if you can validate a specific structure for a dialect and know which dialect supports that pattern, you could parse based on the dialect. Since your PR is related to an extension, not a completely different of doing the parse, I don't see why it is a problem to allow Hive and Generic to have that syntax, while other dialects not.

image

image

image

Copy link
Contributor

Choose a reason for hiding this comment

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

In general, I think the crate takes the approach of if we can parse the syntax unambiguously we'll accept it even if certain syntax would not be accepted by the various dialects. This is definitely not totally consistent as @bitemyapp has noticed

I tend to agree that in this case we aren't adding any ambiguity so this implementation is fine

@bitemyapp bitemyapp force-pushed the bitemyapp/fixing-alter-table-multi-partition branch from d5c9854 to fe55986 Compare October 7, 2022 17:17
@bitemyapp
Copy link
Contributor Author

Removed #[must_use] from the peek helper I wrote and lifted the backtick acceptance out of the trait default to GenericDialect. Tests still passed.

Copy link
Contributor

@alamb alamb left a comment

Choose a reason for hiding this comment

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

Thank you for the contribution @bitemyapp

self.expect_token(&Token::LParen)?;
let partitions = self.parse_comma_separated(Parser::parse_expr)?;
self.expect_token(&Token::RParen)?;
if self.peek_keyword(Keyword::PARTITION) {
Copy link
Contributor

Choose a reason for hiding this comment

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

In general, I think the crate takes the approach of if we can parse the syntax unambiguously we'll accept it even if certain syntax would not be accepted by the various dialects. This is definitely not totally consistent as @bitemyapp has noticed

I tend to agree that in this case we aren't adding any ambiguity so this implementation is fine

@alamb
Copy link
Contributor

alamb commented Oct 7, 2022

I'll wait for the token parsing thing to merge and we can then merge this one

@bitemyapp bitemyapp force-pushed the bitemyapp/fixing-alter-table-multi-partition branch from fe55986 to 438c515 Compare October 18, 2022 17:43
@bitemyapp bitemyapp force-pushed the bitemyapp/fixing-alter-table-multi-partition branch from 438c515 to 2016b64 Compare October 18, 2022 18:13
@alamb alamb marked this pull request as draft October 19, 2022 21:22
@alamb
Copy link
Contributor

alamb commented Oct 19, 2022

CI is failing so marking as draft

@alamb
Copy link
Contributor

alamb commented Aug 17, 2023

Closing this PR as it is more than 6 months old without activity. Please reopen or make another PR if you plan to keep working on this.

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