-
-
Couldn't load subscription status.
- Fork 239
Added Support for Full MySQL TRIM Syntax #605
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
…o james/fix-2297-implement-string-functions
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.
Good start, see comments
Biggest missing piece is engine tests (look in queries.go). We need engine tests for every function we write. Engine tests should cover both literal and column values of various types.
| trimType | ||
| } | ||
| // Cast to string | ||
| var pat_text string |
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.
Some more tests are in order, but you probably want to use Convert() of a string type rather than a simple type assertion like this
E.g. this works:
mysql> SELECT TRIM(LEADING 1 FROM '111barxxx');
+----------------------------------+
| TRIM(LEADING 1 FROM '111barxxx') |
+----------------------------------+
| barxxx |
+----------------------------------+
| return "rtrim" | ||
| case bTrimType: | ||
| return "trim" | ||
| // Cast to string type |
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.
Same comment
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.
mysql> SELECT TRIM(LEADING 1 FROM 111222);
+-----------------------------+
| TRIM(LEADING 1 FROM 111222) |
+-----------------------------+
| 222 |
+-----------------------------+
| // Type implements the Expression interface. | ||
| func (t *Trim) Type() sql.Type { return sql.LongText } | ||
| // Evaluate direction | ||
| dir, err := t.dir.Eval(ctx, row) |
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.
This one should be a static constant, no need to eval (see other PR comment)
| expression.UnaryExpression | ||
| } | ||
|
|
||
| func NewLeftTrim(str sql.Expression) sql.Expression { |
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.
This and NewRightTrim need to be updated in registry.go
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.
Looks pretty good, but need some more test cases
| Expected: []sql.Row{{"2"}}, | ||
| }, | ||
| { | ||
| Query: `SELECT TRIM(LEADING 1 FROM 11111112)`, |
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.
You want a few test cases with a match of the trim phrase in the middle of the word that don't get trimmed, e.g. trim(trailing "a" from "baba") == bab, trim(trailing "ab" from "baba") == baba
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.
Also want some tests cases where the expressions for trimming are not literals
Some where they are column values, some where they are function calls (e.g. concat("a", "b"))
| lTrimType trimType = 'l' | ||
| rTrimType trimType = 'r' | ||
| bTrimType trimType = 'b' | ||
| LEADING string = "l" |
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.
These should go in Vitess
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.
Comment still applies
…ithub.com/dolthub/go-mysql-server into james/fix-2297-implement-string-functions
…ithub.com/dolthub/go-mysql-server into james/fix-2297-implement-string-functions
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.
Looks better, but a couple comment still need to be addressed
enginetest/queries.go
Outdated
| Query: `SELECT TRIM(LEADING "ooo" FROM TRIM("oooo"))`, | ||
| Expected: []sql.Row{{"o"}}, | ||
| }, | ||
|
|
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.
Extra line, delete
| lTrimType trimType = 'l' | ||
| rTrimType trimType = 'r' | ||
| bTrimType trimType = 'b' | ||
| LEADING string = "l" |
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.
Comment still applies
enginetest/queries.go
Outdated
| Query: `SELECT SUBSTRING_INDEX(mytable.s, "d", 1) AS s FROM mytable INNER JOIN othertable ON (SUBSTRING_INDEX(mytable.s, "d", 1) = SUBSTRING_INDEX(othertable.s2, "d", 1)) GROUP BY 1 HAVING s = 'secon'`, | ||
| Expected: []sql.Row{{"secon"}}, | ||
| }, | ||
|
|
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.
extra line
Parser recognizes keywords like: LEADING, TRAILING, and BOTH.
TRIM function can now remove prefixes.
Fixed LTRIM And RTRIM to not remove all whitespace, and just space characters.
Also added functionality for RIGHT function.
fixes: dolthub/dolt#2199