-
Notifications
You must be signed in to change notification settings - Fork 895
Support SHOW TABLES LIKE pattern and Where expr #1518
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
Merged
Merged
Changes from all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
b77be14
Init: Extent DfShowTables and parsing it
mapleFU a5ef5a0
ximplement basic logics and tests
mapleFU 77c27ac
fix a place for token
mapleFU e37835d
adding more test about complex expr
mapleFU 7baecf6
test: adding extra checking for comma
mapleFU 1e30fbf
bugfix and add testing
mapleFU 8da0e67
finish stateless tests
mapleFU d9eaee0
remove: remove handling column
mapleFU 60fa56a
Add newline
sundy-li 756ae2d
Update plan_parser.rs
sundy-li 51c7e89
Update plan_parser.rs
sundy-li File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -163,7 +163,20 @@ impl<'a> DfParser<'a> { | |
| self.parser.next_token(); | ||
|
|
||
| if self.consume_token("TABLES") { | ||
| Ok(DfStatement::ShowTables(DfShowTables)) | ||
| let tok = self.parser.next_token(); | ||
| match &tok { | ||
| Token::EOF => Ok(DfStatement::ShowTables(DfShowTables::All)), | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What happens to the following SQL? SHOW TABLES ;
SHOW TABLES -- comment
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I will add some tests and check if it's ok tonight. |
||
| Token::Word(w) => match w.keyword { | ||
| Keyword::LIKE => Ok(DfStatement::ShowTables( | ||
| DfShowTables::Like(self.parser.parse_identifier()?), | ||
| )), | ||
| Keyword::WHERE => Ok(DfStatement::ShowTables( | ||
| DfShowTables::Where(self.parser.parse_expr()?), | ||
| )), | ||
| _ => self.expected("like or where", tok), | ||
| }, | ||
| _ => self.expected("like or where", tok), | ||
| } | ||
| } else if self.consume_token("DATABASES") { | ||
| Ok(DfStatement::ShowDatabases(DfShowDatabases)) | ||
| } else if self.consume_token("SETTINGS") { | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1 +1,14 @@ | ||
| t | ||
| t1 | ||
| t2 | ||
| t3 | ||
| t1 | ||
| t2 | ||
| t3 | ||
| t2 | ||
| t1 | ||
| t2 | ||
| t3 | ||
| t1 | ||
| t2 | ||
| t3 | ||
| t2 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,6 +1,22 @@ | ||
| DROP TABLE IF EXISTS t; | ||
| DROP TABLE IF EXISTS t1; | ||
| DROP TABLE IF EXISTS t2; | ||
| DROP TABLE IF EXISTS t3; | ||
|
|
||
| CREATE TABLE t1(c1 int) ENGINE = Null; | ||
| CREATE TABLE t2(c1 int) ENGINE = Null; | ||
| CREATE TABLE t3(c1 int) ENGINE = Null; | ||
|
|
||
| CREATE TABLE t(c1 int) ENGINE = Null; | ||
| SHOW TABLES; | ||
|
|
||
| DROP TABLE IF EXISTS t; | ||
| SHOW TABLES LIKE 't%'; | ||
| SHOW TABLES LIKE 't2'; | ||
| SHOW TABLES LIKE 't'; | ||
|
|
||
| SHOW TABLES WHERE name LIKE 't%'; | ||
| SHOW TABLES WHERE name = 't%' AND 1 = 0; | ||
| SHOW TABLES WHERE name = 't2' OR 1 = 1; | ||
| SHOW TABLES WHERE name = 't2' AND 1 = 1; | ||
|
|
||
| DROP TABLE IF EXISTS t1; | ||
| DROP TABLE IF EXISTS t2; | ||
| DROP TABLE IF EXISTS t3; |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What happens to the following SQL?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's ok, we don't care about it, just let it be any complex expr. The optimize / select executor will handle that.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
According to MySQL standard,
parse_exprcan handle all of them: https://dev.mysql.com/doc/refman/5.7/en/expressions.htmlBuf I didn't check the code in sqlparse-rs, so I cannot guarantee it works well.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
May this change the behavior of the query?
After format:
SELECT name FROM system.tables where database = '{}' AND 1 = 1 OR 1 = 1 ORDER BY database, nameThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Got It. Sorry for misunderstanding this case! I will adding tests about it in stateless test.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
According to https://dev.mysql.com/doc/refman/8.0/en/operator-precedence.html , it will not return all tables. But I think maybe it's proper to build sql like:
@zhang2014 do you think it's ok?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It looks ok