Skip to content
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

Merged
merged 2 commits into from
Jan 9, 2024
Merged

Conversation

dbussink
Copy link
Contributor

@dbussink dbussink commented Jan 7, 2024

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.

Related Issue(s)

Part of #9647

Checklist

  • "Backport to:" labels have been added if this change should be back-ported to release branches
  • If this change is to be back-ported to previous releases, a justification is included in the PR description
  • Tests were added or are not required
  • Did the new or modified tests pass consistently locally and on CI?
  • Documentation was added or is not required

Copy link
Contributor

vitess-bot bot commented Jan 7, 2024

Review Checklist

Hello reviewers! 👋 Please follow this checklist when reviewing this Pull Request.

General

  • Ensure that the Pull Request has a descriptive title.
  • Ensure there is a link to an issue (except for internal cleanup and flaky test fixes), new features should have an RFC that documents use cases and test cases.

Tests

  • Bug fixes should have at least one unit or end-to-end test, enhancement and new features should have a sufficient number of tests.

Documentation

  • Apply the release notes (needs details) label if users need to know about this change.
  • New features should be documented.
  • There should be some code comments as to why things are implemented the way they are.
  • There should be a comment at the top of each new or modified test to explain what the test does.

New flags

  • Is this flag really necessary?
  • Flag names must be clear and intuitive, use dashes (-), and have a clear help text.

If a workflow is added or modified:

  • Each item in Jobs should be named in order to mark it as required.
  • If the workflow needs to be marked as required, the maintainer team must be notified.

Backward compatibility

  • Protobuf changes should be wire-compatible.
  • Changes to _vt tables and RPCs need to be backward compatible.
  • RPC changes should be compatible with vitess-operator
  • If a flag is removed, then it should also be removed from vitess-operator and arewefastyet, if used there.
  • vtctl command output order should be stable and awk-able.

@vitess-bot vitess-bot bot added NeedsBackportReason If backport labels have been applied to a PR, a justification is required NeedsDescriptionUpdate The description is not clear or comprehensive enough, and needs work NeedsIssue A linked issue is missing for this Pull Request NeedsWebsiteDocsUpdate What it says labels Jan 7, 2024
@github-actions github-actions bot added this to the v19.0.0 milestone Jan 7, 2024
@@ -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")
Copy link
Contributor Author

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()
Copy link
Contributor Author

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")
Copy link
Contributor Author

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) {
Copy link
Contributor Author

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.

@dbussink dbussink added Type: Enhancement Logical improvement (somewhere between a bug and feature) Component: Evalengine changes to the evaluation engine and removed NeedsDescriptionUpdate The description is not clear or comprehensive enough, and needs work NeedsWebsiteDocsUpdate What it says NeedsIssue A linked issue is missing for this Pull Request NeedsBackportReason If backport labels have been applied to a PR, a justification is required labels Jan 7, 2024
@dbussink dbussink force-pushed the evalengine-substring branch from 8cab716 to c002cfa Compare January 7, 2024 15:13
Copy link
Member

@mdlayher mdlayher left a 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 {
Copy link
Member

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?

Copy link
Contributor Author

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?

Copy link
Member

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.

Copy link
Contributor Author

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.

go/vt/vtgate/evalengine/fn_string.go Show resolved Hide resolved
go/vt/vtgate/evalengine/fn_string.go Show resolved Hide resolved
go/vt/vtgate/evalengine/fn_string.go Show resolved Hide resolved
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>
@dbussink dbussink force-pushed the evalengine-substring branch from c002cfa to f9ce09c Compare January 8, 2024 13:13
Copy link
Member

@GuptaManan100 GuptaManan100 left a 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!

go/vt/vtgate/evalengine/compiler_asm.go Outdated Show resolved Hide resolved
go/vt/vtgate/evalengine/compiler_asm.go Outdated Show resolved Hide resolved
Signed-off-by: Dirkjan Bussink <d.bussink@gmail.com>
@dbussink dbussink merged commit fab65bf into vitessio:main Jan 9, 2024
99 checks passed
@dbussink dbussink deleted the evalengine-substring branch January 9, 2024 12:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Component: Evalengine changes to the evaluation engine Type: Enhancement Logical improvement (somewhere between a bug and feature)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants