-
Notifications
You must be signed in to change notification settings - Fork 5.9k
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
builtin: add instr built-in function #2857
Conversation
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.
Thanks for your PR ^_^
Rest LGTM
expression/builtin_string.go
Outdated
return d, errors.Trace(err) | ||
} | ||
// INSTR(str, substr) | ||
if args[0].IsNull() { |
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.
if args[0].IsNull() || args[1].IsNull(){
return
}
expression/builtin_string_test.go
Outdated
{[]interface{}{123456, 567}, 0}, | ||
{[]interface{}{1e10, 1e2}, 1}, | ||
{[]interface{}{1.234, ".234"}, 2}, | ||
|
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.
Please add a test case like SELECT INSTR('foobarbar', "'');
.
expression/builtin_string.go
Outdated
return d, errors.Trace(err) | ||
} | ||
pos := strings.Index(str, substr) + 1 // index starts from 1 | ||
d.SetInt64(int64(pos)) |
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.
works wrong with Chinese characters.
Try INSTR("你好世界", "世界")
First thanks @spongedu I've just read the INSTR() carefully and realized another mistake except for the problem of ignoring utf8 specified by @spongedu
We need to consider the type of arguments passed to Unfortunately, the implementation of |
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.
Please address the comments, and rest LGTM.
expression/builtin_string.go
Outdated
} | ||
|
||
var caseSensitive bool | ||
// INSTR performs case **insensitive** search by default |
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.
add .
at the end of this comment.
expression/builtin_string.go
Outdated
|
||
var caseSensitive bool | ||
// INSTR performs case **insensitive** search by default | ||
// While at least one argument is binary string we do case sensitive search |
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.
Ditto.
expression/builtin_string.go
Outdated
caseSensitive = true | ||
} | ||
|
||
var pos int |
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.
var pos, idx int
expression/builtin_string.go
Outdated
return d, nil | ||
} | ||
|
||
var str 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.
var str, substr string
LGTM |
Add
INSTR(str, substr)
built-in function