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

Support mysql partition to table selection #959

Merged
merged 7 commits into from
Sep 14, 2023

Conversation

chunshao90
Copy link
Contributor

@chunshao90 chunshao90 commented Aug 29, 2023

Support mysql partition selection, example:

SELECT * FROM employees PARTITION (p0, p2)

Refer to https://dev.mysql.com/doc/refman/8.0/en/partitioning-selection.html

@chunshao90 chunshao90 marked this pull request as draft August 29, 2023 11:28
@chunshao90 chunshao90 force-pushed the support-mysql-partition-selection branch from f2b7af9 to d441f7d Compare August 29, 2023 11:50
@chunshao90 chunshao90 marked this pull request as ready for review August 29, 2023 11:51
@chunshao90
Copy link
Contributor Author

@alamb PTAL

@alamb
Copy link
Contributor

alamb commented Sep 7, 2023

Sorry for the delay -- I was away last week. I am looking at this PR now

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 @chunshao90 -- this is looking pretty close. I left some suggestions for your consideration

src/ast/query.rs Outdated Show resolved Hide resolved
src/parser/mod.rs Outdated Show resolved Hide resolved
let partitions = if dialect_of!(self is MySqlDialect)
&& self.parse_keyword(Keyword::PARTITION)
{
let mut partitions = self.parse_comma_separated(|p| p.parse_tuple(true, false))?;
Copy link
Contributor

Choose a reason for hiding this comment

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

As written I think this only checks the first partition for having more than one tuple element (what about values after index 0?)

I think if you used parse_expr here this code would be significantly simpler and there would be no need for error checking

Suggested change
let mut partitions = self.parse_comma_separated(|p| p.parse_tuple(true, false))?;
let mut partitions = self.parse_comma_separated(Parser::parse_expr)?;

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Returns an error if there are multiple tuples.

src/ast/query.rs Outdated Show resolved Hide resolved
@chunshao90 chunshao90 force-pushed the support-mysql-partition-selection branch from f287cec to f3f5c9e Compare September 12, 2023 08:28
@chunshao90
Copy link
Contributor Author

chunshao90 commented Sep 12, 2023

@alamb Please review again.

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.

Looks good to me -- thank you @chunshao90

@alamb
Copy link
Contributor

alamb commented Sep 14, 2023

I'll clean up the clippy failures

@alamb alamb changed the title feat: support mysql partition selection Support mysql partition to table selection Sep 14, 2023
@alamb alamb merged commit f6e4be4 into apache:main Sep 14, 2023
10 checks passed
@alamb
Copy link
Contributor

alamb commented Sep 14, 2023

Thanks again @chunshao90 !

serprex pushed a commit to serprex/sqlparser-rs that referenced this pull request Nov 6, 2023
Co-authored-by: Andrew Lamb <andrew@nerdnetworks.org>
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.

2 participants