-
Notifications
You must be signed in to change notification settings - Fork 2.1k
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
evalengine: Implement SUBSTRING #14899
Conversation
Review ChecklistHello reviewers! 👋 Please follow this checklist when reviewing this Pull Request. General
Tests
Documentation
New flags
If a workflow is added or modified:
Backward compatibility
|
@@ -568,7 +568,7 @@ func (expr *InExpr) compile(c *compiler) (ctype, error) { | |||
|
|||
return ctype{Type: sqltypes.Int64, Col: collationNumeric, Flag: flagIsBoolean | (nullableFlags(lhs.Flag) | (rt.Flag & flagNullable))}, nil | |||
case *BindVariable: | |||
return ctype{}, c.unsupported(expr) | |||
return ctype{}, vterrors.Errorf(vtrpcpb.Code_INTERNAL, "rhs of an In operation should be a tuple") |
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 matches the error from the evaluator in the compiler here.
@@ -205,7 +205,7 @@ func (conv *ConvertExpr) compile(c *compiler) (ctype, error) { | |||
convt = c.compileToFloat(arg, 1) | |||
|
|||
case "FLOAT": | |||
return ctype{}, c.unsupported(conv) | |||
return ctype{}, conv.returnUnsupportedError() |
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 to match the evaluation path.
@@ -354,7 +354,7 @@ func (call *builtinMultiComparison) compile(c *compiler) (ctype, error) { | |||
case sqltypes.Null: | |||
nullable = true | |||
default: | |||
return ctype{}, c.unsupported(call) | |||
panic("unexpected argument 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.
Here as well, we panic in the evaluator too.
@@ -817,7 +822,7 @@ func (expr *builtinStrcmp) compile(c *compiler) (ctype, error) { | |||
return ctype{Type: sqltypes.Int64, Col: collationNumeric, Flag: nullableFlags(lt.Flag | rt.Flag)}, nil | |||
} | |||
|
|||
func (call builtinTrim) eval(env *ExpressionEnv) (eval, error) { | |||
func (call *builtinTrim) eval(env *ExpressionEnv) (eval, error) { |
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.
Incorrectly was not using pointer receivers, so fixing this up.
8cab716
to
c002cfa
Compare
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.
I don't have a ton of context here, just offering some suggestions.
@@ -932,6 +937,105 @@ func (call builtinTrim) compile(c *compiler) (ctype, error) { | |||
return ctype{Type: sqltypes.VarChar, Flag: flagNullable, Col: col}, nil | |||
} | |||
|
|||
func (call *builtinSubstring) eval(env *ExpressionEnv) (eval, error) { | |||
str, err := call.Arguments[0].eval(env) | |||
if err != nil || str == nil { |
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.
Note that line 943 could return nil, nil
if str is also nil, is that acceptable?
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.
Not sure what you mean here? We can't lose the error here?
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.
Hypothetically a return from eval of (nil, nil)
would mean that a nil eval and nil error get returned from the function. Is that okay?
I just mention it because I notice all calls to eval have to check both values, which means that it may be possible to simplify a bit by only having the result be valid when err != nil. That would be a larger refactor.
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.
@mdlayher Yep, nil, nil
is ok. A SQL NULL
inside the evalengine is represented as the Go nil
. So it's a perfectly possible and valid value here.
This implements `SUBSTRING` (and the `SUBSTR` alias) in the `evalengine`. Also fixes some unsupported calls to be more explicit with a separate error type for regexp. Those don't end up really unsupported, but we then compile a slow path. Also implement some cases that are trivial to do. Signed-off-by: Dirkjan Bussink <d.bussink@gmail.com>
c002cfa
to
f9ce09c
Compare
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.
Just a couple of nits, rest looks good to me!
Signed-off-by: Dirkjan Bussink <d.bussink@gmail.com>
This implements
SUBSTRING
(and theSUBSTR
alias) in theevalengine
.Also fixes some unsupported calls to be more explicit with a separate error type for regexp. Those don't end up really unsupported, but we then compile a slow path. Also implement some cases that are trivial to do.
Related Issue(s)
Part of #9647
Checklist