forked from vitessio/vitess
-
Notifications
You must be signed in to change notification settings - Fork 21
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
Add TRIM functionality #88
Merged
Merged
Changes from all commits
Commits
Show all changes
18 commits
Select commit
Hold shift + click to select a range
4bd122a
strange yacc bug?
48cbcd9
Added TRIM syntax
6cb20b2
trim syntax and functionality matches mysql
fda66f5
removed test that expects trailing to be unused
b94ec63
string is now value_expression
a4179df
TRIM can accept expression for pattern
644203f
changed %s to %v for Format print
69455f4
fixed tests and format
d52884a
Regened sql.go
zachmu a0d613c
added constants to vitess
226ad22
Merge branch 'james/fix-2297-implement-string-functions' of https://g…
1a32e7f
merging
d79b448
Regen sql.go
zachmu 5356407
renamed const variables
0e88197
Merge branch 'james/fix-2297-implement-string-functions' of https://g…
e6b3583
renaming const variables
803198c
changed make parser to be more lenient
7b19c4f
fixed format to produce parse-able sql
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 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 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 |
---|---|---|
|
@@ -2643,8 +2643,8 @@ func TestKeywords(t *testing.T) { | |
input: "select /* share and mode as cols */ share, mode from t where share = 'foo'", | ||
output: "select /* share and mode as cols */ `share`, `mode` from t where `share` = 'foo'", | ||
}, { | ||
input: "select /* unused keywords as cols */ write, virtual from t where trailing = 'foo'", | ||
output: "select /* unused keywords as cols */ `write`, `virtual` from t where `trailing` = 'foo'", | ||
input: "select /* unused keywords as cols */ write, virtual from t where varcharacter = 'foo'", | ||
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 happened to this test case? 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. Comment still applies, you changed this test case and should put it back |
||
output: "select /* unused keywords as cols */ `write`, `virtual` from t where `varcharacter` = 'foo'", | ||
}, { | ||
input: "insert into x (status) values (42)", | ||
output: "insert into x(`status`) values (42)", | ||
|
@@ -3489,6 +3489,44 @@ func TestLoadData(t *testing.T) { | |
} | ||
} | ||
|
||
func TestTrim(t *testing.T) { | ||
testCases := []parseTest{ | ||
{ | ||
input: `SELECT TRIM("foo")`, | ||
output: `select trim(both ' ' from 'foo') from dual`, | ||
serializeSelectExprs: true, | ||
}, | ||
{ | ||
input: `SELECT TRIM("bar" FROM "foo")`, | ||
output: `select trim(both 'bar' from 'foo') from dual`, | ||
serializeSelectExprs: true, | ||
}, | ||
{ | ||
input: `SELECT TRIM(LEADING "bar" FROM "foo")`, | ||
output: `select trim(leading 'bar' from 'foo') from dual`, | ||
serializeSelectExprs: true, | ||
}, | ||
{ | ||
input: `SELECT TRIM(TRAILING "bar" FROM "foo")`, | ||
output: `select trim(trailing 'bar' from 'foo') from dual`, | ||
serializeSelectExprs: true, | ||
}, | ||
{ | ||
input: `SELECT TRIM(BOTH "bar" FROM "foo")`, | ||
output: `select trim(both 'bar' from 'foo') from dual`, | ||
serializeSelectExprs: true, | ||
}, | ||
{ | ||
input: `SELECT TRIM(TRIM("foobar"))`, | ||
output: `select trim(both ' ' from trim(both ' ' from 'foobar')) from dual`, | ||
serializeSelectExprs: true, | ||
}, | ||
} | ||
for _, tcase := range testCases { | ||
runParseTestCase(t, tcase) | ||
} | ||
} | ||
|
||
func TestCreateTableLike(t *testing.T) { | ||
normal := "create table a like b" | ||
testCases := []struct { | ||
|
Oops, something went wrong.
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.
Declare some exported constants for this value