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

Gen4: Filter primitive and planning #9017

Merged
merged 43 commits into from
Nov 3, 2021

Conversation

frouioui
Copy link
Member

@frouioui frouioui commented Oct 19, 2021

Description

This pull request adds the Filter engine primitive along with the filter logical plan. A basic version of the ComparisonExpr (implementation of EvalEngine's Expr) is added through this pull request too. ComparisonExpr supports basic operations (=, !=, <, <=, >, >=) on values that can be transformed to numerical values, i.e support for type coercion will come in the following pull request.

Related Issue(s)

Checklist

  • Tests were added or are not required
  • Documentation was added or is not required

@frouioui frouioui added Type: Enhancement Logical improvement (somewhere between a bug and feature) Component: Query Serving release notes labels Oct 19, 2021
@frouioui frouioui self-assigned this Oct 20, 2021
@frouioui frouioui marked this pull request as ready for review October 20, 2021 09:11
@frouioui frouioui marked this pull request as draft October 20, 2021 09:15
@frouioui frouioui marked this pull request as ready for review October 20, 2021 09:21
@frouioui frouioui requested a review from systay October 20, 2021 09:21
go/test/endtoend/vtgate/utils/utils.go Outdated Show resolved Hide resolved
go/vt/sqlparser/expression_converter.go Outdated Show resolved Hide resolved
go/vt/vtgate/planbuilder/filter.go Outdated Show resolved Hide resolved
go/vt/vtgate/planbuilder/horizon_planning.go Show resolved Hide resolved
Copy link
Collaborator

@systay systay left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice stuff

@frouioui frouioui marked this pull request as draft October 21, 2021 08:28
go/vt/vtgate/planbuilder/system_tables.go Outdated Show resolved Hide resolved
go/vt/vtgate/planbuilder/rewrite_test.go Show resolved Hide resolved
go/vt/vtgate/planbuilder/filter.go Outdated Show resolved Hide resolved
go/vt/vtgate/evalengine/arithmetic.go Outdated Show resolved Hide resolved
go/vt/vtgate/evalengine/comparisons.go Outdated Show resolved Hide resolved
go/vt/vtgate/engine/filter.go Show resolved Hide resolved
@frouioui frouioui force-pushed the gen4-filter-planning branch 4 times, most recently from 1309eb0 to af16294 Compare October 25, 2021 15:51
return 0, vterrors.Errorf(vtrpcpb.Code_UNIMPLEMENTED, "cannot compare a date with a numeric value")

default:
// Quoting MySQL Docs:
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

❤️

…rther error analisis

Signed-off-by: Florent Poinsard <florent.poinsard@outlook.fr>
Signed-off-by: Florent Poinsard <florent.poinsard@outlook.fr>
Signed-off-by: Florent Poinsard <florent.poinsard@outlook.fr>
Signed-off-by: Florent Poinsard <florent.poinsard@outlook.fr>
Signed-off-by: Florent Poinsard <florent.poinsard@outlook.fr>
Signed-off-by: Florent Poinsard <florent.poinsard@outlook.fr>
Signed-off-by: Florent Poinsard <florent.poinsard@outlook.fr>
Signed-off-by: Florent Poinsard <florent.poinsard@outlook.fr>
Signed-off-by: Florent Poinsard <florent.poinsard@outlook.fr>
Signed-off-by: Florent Poinsard <florent.poinsard@outlook.fr>
Signed-off-by: Florent Poinsard <florent.poinsard@outlook.fr>
Signed-off-by: Florent Poinsard <florent.poinsard@outlook.fr>
Signed-off-by: Florent Poinsard <florent.poinsard@outlook.fr>
…mports

Signed-off-by: Florent Poinsard <florent.poinsard@outlook.fr>
…nbuilder package instead of ints

Signed-off-by: Florent Poinsard <florent.poinsard@outlook.fr>
…on to an evalengine.expression

Signed-off-by: Florent Poinsard <florent.poinsard@outlook.fr>
Signed-off-by: Florent Poinsard <florent.poinsard@outlook.fr>
Signed-off-by: Florent Poinsard <florent.poinsard@outlook.fr>
Signed-off-by: Florent Poinsard <florent.poinsard@outlook.fr>
Signed-off-by: Florent Poinsard <florent.poinsard@outlook.fr>
Signed-off-by: Florent Poinsard <florent.poinsard@outlook.fr>
@systay systay marked this pull request as ready for review November 3, 2021 12:33
Copy link
Collaborator

@systay systay left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks great. Just two minor comments that we could address in a future PR as well

@frouioui
Copy link
Member Author

frouioui commented Nov 3, 2021

Looks great. Just two minor comments that we could address in a future PR as well

I will address the two comments via #9097

@frouioui frouioui merged commit 1b52453 into vitessio:main Nov 3, 2021
@frouioui frouioui deleted the gen4-filter-planning branch November 3, 2021 15:01
Comment on lines -499 to +500
"d|null|1",
"d|1|2",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see that you added a test row d|1|1 due to which you changed the test expectation from d|null|1 to d|1|2, any reason for doing this change in the test?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we wanted to test more cases

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree with @harshit-gangal, naming is now confusing, in the test input we are saying // Single null even though we have two rows with only one of them being null. I'll fix the naming and add another row to test single null behavior.

Comment on lines +351 to +356
now := time.Now()
// setting the date to today's date, because we use AddDate on t
// which is "0000-01-01 xx:xx:xx", we do minus one on the month
// and day to take into account the 01 in both month and day of t
t = t.AddDate(now.Year(), int(now.Month()-1), now.Day()-1)
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

do you have a test case for this? looks like there can be corner cases with timezone (set on MySQL vs VTGate instance)

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what type of tests do you feel would be helpful here?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is just an internal behavior of Golang where time.Times with no date have their dates set by default to 0000-01-01

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

filtering on column with time column on left and date column on right.
not sure if evalengine supports that, that would lead the test to come to this code path.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the EvalEngine supports it thanks to this code snippet you highlighted. we also have tests for it:

{
name: "date equal time",
v1: NewColumn(0, defaultCollation), v2: NewColumn(1, defaultCollation),
out: &T, op: &EqualOp{},
row: []sqltypes.Value{sqltypes.NewDate(time.Now().Format("2006-01-02")), sqltypes.NewTime("00:00:00")},
},
{
name: "date not equal time",
v1: NewColumn(0, defaultCollation), v2: NewColumn(1, defaultCollation),
out: &T, op: &NotEqualOp{},
row: []sqltypes.Value{sqltypes.NewDate(time.Now().Format("2006-01-02")), sqltypes.NewTime("12:00:00")},
},

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Component: Query Serving 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