Skip to content

Support mysql partition to table selection#959

Merged
alamb merged 7 commits into
apache:mainfrom
chunshao90:support-mysql-partition-selection
Sep 14, 2023
Merged

Support mysql partition to table selection#959
alamb merged 7 commits into
apache:mainfrom
chunshao90:support-mysql-partition-selection

Conversation

@chunshao90
Copy link
Copy Markdown
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
Copy Markdown
Contributor Author

@alamb PTAL

@alamb
Copy link
Copy Markdown
Contributor

alamb commented Sep 7, 2023

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

Copy link
Copy Markdown
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

Comment thread src/ast/query.rs Outdated
Comment thread src/parser/mod.rs Outdated
Comment thread src/parser/mod.rs Outdated
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
Copy Markdown
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
Copy Markdown
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.

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

chunshao90 commented Sep 12, 2023

@alamb Please review again.

Copy link
Copy Markdown
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
Copy Markdown
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
@alamb
Copy link
Copy Markdown
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