-
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: serialize to SQL #14337
evalengine: serialize to SQL #14337
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
|
1fdf96c
to
9345ca7
Compare
4a4a03f
to
f9794e2
Compare
affc1eb
to
f57f7a5
Compare
return 1 | ||
} | ||
|
||
func (asm *assembler) PushColumn_datetime(offset 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.
@vmg Do we treat timestamp
columns the same as datetime
?
Nvm, I read this further down that we do.
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.
Yes, we've always done so in the evalengine. All the existing code does.
Signed-off-by: Vicent Marti <vmg@strn.cat>
Signed-off-by: Vicent Marti <vmg@strn.cat>
Signed-off-by: Vicent Marti <vmg@strn.cat>
Signed-off-by: Vicent Marti <vmg@strn.cat>
Key string | ||
Type sqltypes.Type | ||
Collation collations.ID | ||
dynamicTypeOffset 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.
maybe a little comment explaining this field?
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.
Done 👍
"[COLUMN 4] as weight_string(us.bar)" | ||
"count(*) * count(*) as count(*)", | ||
"count(ue.foo) * count(*) as count(ue.foo)", | ||
":3 as bar", |
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 clear to me why some offsets are serialized as column names and some as offsets
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.
That's up to the planner: if you passed the original column sqlparser.Expr
when translating the expression, we'll keep it when serializing. Otherwise, we'll print an offset.
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.
lovely stuff
@@ -31,6 +31,9 @@ import ( | |||
) | |||
|
|||
func start(t *testing.T) (utils.MySQLCompare, func()) { | |||
// ensure that the vschema and the tables have been created before running any tests | |||
_ = utils.WaitForAuthoritative(t, keyspaceName, "t1", clusterInstance.VtgateProcess.ReadVSchema) | |||
|
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.
Is this something we also want on the older release branches to avoid flaky tests there?
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.
whenever we have established that the schema tracking is what is introducing the flakiness, this is an excellent way to stop if from flaking
} | ||
} | ||
|
||
// NewTupleExpr returns a tuple expression | ||
func NewTupleExpr(exprs ...Expr) TupleExpr { | ||
tupleExpr := make(TupleExpr, 0, len(exprs)) | ||
for _, f := range exprs { | ||
tupleExpr = append(tupleExpr, f) | ||
tupleExpr = append(tupleExpr, f.(IR)) |
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.
Assuming this can never be anything but an IR
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.
Yeah I should lift that into the signature TBH.
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.
Fixed
@@ -39,7 +45,11 @@ func (asm *assembler) PushColumn_i(offset int) { | |||
asm.adjustStack(1) | |||
|
|||
asm.emit(func(env *ExpressionEnv) int { | |||
return push_i(env, env.Row[offset].Raw()) | |||
col := env.Row[offset] | |||
if col.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.
It was not possible to get a NULL
here before or was this an existing bug that was uncovered? And could we avoid emitting this if we know it's NOT NULL
?
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 is an existing bug! It would crash the compiler when a value from a nullable column contains a null
(which is, huh, very frequent). The extra null checks can be removed by specializing: we would need to add a dependency on Fields
, however, which the compiler doesn't have right now. Alternatively, we'd need to gather the nullability information from the VSchema, which may or may not be supported yet. Definitely something to follow up on a separate PR.
Signed-off-by: Vicent Marti <vmg@strn.cat>
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.
LGTM! 🚀
t.Skipf("TODO: these tests are not green") | ||
|
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.
Is this left to be addressed in this PR or do we plan to fix it 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.
@GuptaManan100 oops just saw this. Will follow up. These tests are no longer relevant, they need to be refactored.
Description
As part of some planner refactorings, we'd like to depend more on the evalengine for its type definitions. To accomplish this more efficiently, we want to keep the evalengine AST expressions inside the planner, but these expressions need to be able to be serialized back into SQL for all the plans that will be relayed to the upstream MySQL. This PR implements this functionality by making
evalengine.Expr
implementsqlparser.Expr
.cc @dbussink @systay
Related Issue(s)
Part of #14310
Checklist
Deployment Notes