-
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
Refactor aggregation AST structs #10347
Conversation
Signed-off-by: Rameez Sajwani <rameezwazirali@hotmail.com>
Signed-off-by: Rameez Sajwani <rameezwazirali@hotmail.com>
Signed-off-by: Rameez Sajwani <rameezwazirali@hotmail.com>
Signed-off-by: Rameez Sajwani <rameezwazirali@hotmail.com>
Signed-off-by: Rameez Sajwani <rameezwazirali@hotmail.com>
Signed-off-by: Rameez Sajwani <rameezwazirali@hotmail.com>
Signed-off-by: Rameez Sajwani <rameezwazirali@hotmail.com>
Signed-off-by: Andres Taylor <andres@planetscale.com>
Signed-off-by: Rameez Sajwani <rameezwazirali@hotmail.com>
Signed-off-by: Rameez Sajwani <rameezwazirali@hotmail.com>
Signed-off-by: Rameez Sajwani <rameezwazirali@hotmail.com>
Signed-off-by: Andres Taylor <andres@planetscale.com>
…e#10113 Signed-off-by: Rameez Sajwani <rameezwazirali@hotmail.com>
Signed-off-by: Rameez Sajwani <rameezwazirali@hotmail.com>
Signed-off-by: Rameez Sajwani <rameezwazirali@hotmail.com>
Signed-off-by: Rameez Sajwani <rameezwazirali@hotmail.com>
Signed-off-by: Rameez Sajwani <rameezwazirali@hotmail.com>
Signed-off-by: Rameez Sajwani <rameezwazirali@hotmail.com>
Review ChecklistHello reviewers! 👋 Please follow this checklist when reviewing this Pull Request. General
Bug fixes
Non-trivial changes
New/Existing features
Backward compatibility
|
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.
overall looks really good.
just few nits here and there.
Name string | ||
} | ||
|
||
CountStar struct { | ||
Name 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.
does name represents alias 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.
does name represents alias here?
Name represent (in this case) either 'count' or 'Count' or 'COUNT' etc ... given what I made out of test cases we preserve case sensitivity of keywords in query. Hence this field preserved what has been keyed by user.
Signed-off-by: Rameez Sajwani <rameezwazirali@hotmail.com>
Signed-off-by: Rameez Sajwani <rameezwazirali@hotmail.com>
Signed-off-by: Rameez Sajwani <rameezwazirali@hotmail.com>
Signed-off-by: Rameez Sajwani <rameezwazirali@hotmail.com>
Signed-off-by: Rameez Sajwani <rameezwazirali@hotmail.com>
Signed-off-by: Rameez Sajwani <rameezwazirali@hotmail.com>
func (*VarSamp) iExpr() {} | ||
func (*Variance) iExpr() {} | ||
|
||
func (sum *Sum) GetArg() Expr { return sum.Arg } |
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.
nit: this breaks the pattern this file had before. I think it's nice to keep all the iExpr() together. maybe we could move the GetArg
, IsDistinct
and AggrName
to after the iExprs?
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 will do it in next PR .. I have already have a clean up PR following this as discussed offline ..
Signed-off-by: Rameez Sajwani <rameezwazirali@hotmail.com>
* Refactor aggregation AST structs (vitessio#10347) * SQLParser:Refactoring Add count struct Signed-off-by: Rameez Sajwani <rameezwazirali@hotmail.com> * SQLParser:Refactoring Add countStar struct Signed-off-by: Rameez Sajwani <rameezwazirali@hotmail.com> * SQLParser:Refactoring Add avg struct Signed-off-by: Rameez Sajwani <rameezwazirali@hotmail.com> * SQLParser:Refactoring Add max struct Signed-off-by: Rameez Sajwani <rameezwazirali@hotmail.com> * SQLParser:Refactoring Add min struct Signed-off-by: Rameez Sajwani <rameezwazirali@hotmail.com> * SQLParser:Refactoring Add sum struct Signed-off-by: Rameez Sajwani <rameezwazirali@hotmail.com> * SQLParser:Refactoring Fixing Parser Aggr Function Signed-off-by: Rameez Sajwani <rameezwazirali@hotmail.com> * fix: the return type of count was wrong Signed-off-by: Andres Taylor <andres@planetscale.com> * Refacotring code Signed-off-by: Rameez Sajwani <rameezwazirali@hotmail.com> * More refactoring and unit test cases fix Signed-off-by: Rameez Sajwani <rameezwazirali@hotmail.com> * removing getarg from aggregate interface Signed-off-by: Rameez Sajwani <rameezwazirali@hotmail.com> * Fixing bugs after merge Signed-off-by: Rameez Sajwani <rameezwazirali@hotmail.com> * Optimizing code Signed-off-by: Rameez Sajwani <rameezwazirali@hotmail.com> * Fixing planBuilder test cases` Signed-off-by: Rameez Sajwani <rameezwazirali@hotmail.com> * Adding more aggregate functions Signed-off-by: Rameez Sajwani <rameezwazirali@hotmail.com> * Fixing parser errors Signed-off-by: Rameez Sajwani <rameezwazirali@hotmail.com> * fixing feedback , code review Signed-off-by: Rameez Sajwani <rameezwazirali@hotmail.com> * Fix regression which making changes in previous commit Signed-off-by: Rameez Sajwani <rameezwazirali@hotmail.com> * Fixing vdiff tests Signed-off-by: Rameez Sajwani <rameezwazirali@hotmail.com> * Fixing replication test Signed-off-by: Rameez Sajwani <rameezwazirali@hotmail.com> * Fixing vstreamer planbuilder test Signed-off-by: Rameez Sajwani <rameezwazirali@hotmail.com> * remove redundant code Signed-off-by: Rameez Sajwani <rameezwazirali@hotmail.com> Co-authored-by: Andres Taylor <andres@planetscale.com> Signed-off-by: Vicent Marti <vmg@strn.cat> * Add parsing support for performance schema functions (vitessio#10478) * feat: add parsing support for performance schema functions Signed-off-by: Kushal Kumar <kushalkumargupta4@gmail.com> * fix: update sql.go by making parser Signed-off-by: Kushal Kumar <kushalkumargupta4@gmail.com> Signed-off-by: Vicent Marti <vmg@strn.cat> * Reduce shift-reduce conflicts (vitessio#10500) * feat: reduce shift-reduce conflicts by using the precedence symbol FUNCTION_CALL_NON_KEYWORD Signed-off-by: Manan Gupta <manan@planetscale.com> * feat: fix static check workflow to setup go in cases of parser changes too Signed-off-by: Manan Gupta <manan@planetscale.com> Signed-off-by: Vicent Marti <vmg@strn.cat> * Cleanup: Remove 'Name' field from aggregate structure (vitessio#10507) * Code clean up Signed-off-by: Rameez Sajwani <rameezwazirali@hotmail.com> * Fixing unit test case failures Signed-off-by: Rameez Sajwani <rameezwazirali@hotmail.com> * Fixing replicator planner unit tests Signed-off-by: Rameez Sajwani <rameezwazirali@hotmail.com> * Adding unit test cases of canonical output Signed-off-by: Rameez Sajwani <rameezwazirali@hotmail.com> * Fix unit test Signed-off-by: Rameez Sajwani <rameezwazirali@hotmail.com> Signed-off-by: Vicent Marti <vmg@strn.cat> * User defined and sys variables (vitessio#10547) * feat: add user defined variables and sys variables as separate structs and use user-defined variable in Execute statement Signed-off-by: Manan Gupta <manan@planetscale.com> * feat: remove parsing of at_id and at_at_id from places that shouldn't parse it Signed-off-by: Manan Gupta <manan@planetscale.com> Signed-off-by: Andres Taylor <andres@planetscale.com> * feat: use ci_identifier in more places Signed-off-by: Andres Taylor <andres@planetscale.com> * refactor: clean up the JSON AST structs a little Signed-off-by: Andres Taylor <andres@planetscale.com> * refactor: use remove unnesseccary scope Signed-off-by: Andres Taylor <andres@planetscale.com> * Created new Variable node to divide the work of ColName Signed-off-by: Florent Poinsard <florent.poinsard@outlook.fr> * refactor fix sqlparser: SET ast and parsing Signed-off-by: Andres Taylor <andres@planetscale.com> * refactor: remove unused ast-structs Signed-off-by: Andres Taylor <andres@planetscale.com> * refactor: clean up how variables are parsed and formatted Signed-off-by: Andres Taylor <andres@planetscale.com> * fix: make the new AST work in the planbuilder Signed-off-by: Andres Taylor <andres@planetscale.com> * refactor: rename ColIdent and TableIdent Signed-off-by: Andres Taylor <andres@planetscale.com> * fix: set name should be parsed with SessionScope Signed-off-by: Andres Taylor <andres@planetscale.com> * chore: clean and document stuff Signed-off-by: Andres Taylor <andres@planetscale.com> * test: update test expectation Signed-off-by: Andres Taylor <andres@planetscale.com> * fix: default scope for transaction isolation should not be session Signed-off-by: Andres Taylor <andres@planetscale.com> * feat: handle local as a synonym for session for variable scopes Signed-off-by: Andres Taylor <andres@planetscale.com> * comments: clean up code comments Signed-off-by: Andres Taylor <andres@planetscale.com> Co-authored-by: Manan Gupta <manan@planetscale.com> Co-authored-by: Florent Poinsard <florent.poinsard@outlook.fr> Signed-off-by: Vicent Marti <vmg@strn.cat> * Revert "[Backport 14.0] enable schema tracking by default (vitessio#10595)" This reverts commit 8ebe1cc. Signed-off-by: Vicent Marti <vmg@strn.cat> * enable schema tracking by default (vitessio#10455) * feat: enable schema tracking by default Signed-off-by: Harshit Gangal <harshit@planetscale.com> * test: fix test setup Signed-off-by: Harshit Gangal <harshit@planetscale.com> * test: fix vschema test setup Signed-off-by: Harshit Gangal <harshit@planetscale.com> * test: turn off schema tracking on the tablet Signed-off-by: Andres Taylor <andres@planetscale.com> * test: fix test assertion Signed-off-by: Andres Taylor <andres@planetscale.com> * Change read query for checks that test to which keyspace a table is routed to. This uses the /queryz vttablet endpoint where the query gets expanded if schema tracking is enabled, hence failing an exact query check Signed-off-by: Rohit Nayak <rohit@planetscale.com> * test: only use gen4 planner Signed-off-by: Harshit Gangal <harshit@planetscale.com> * fix: column list population in insert with auto-inc column Signed-off-by: Harshit Gangal <harshit@planetscale.com> * fix: change parser to keep empty column list as provided by user Signed-off-by: Harshit Gangal <harshit@planetscale.com> * test: fix test expectation Signed-off-by: Harshit Gangal <harshit@planetscale.com> Co-authored-by: Andres Taylor <andres@planetscale.com> Co-authored-by: Rohit Nayak <rohit@planetscale.com> Signed-off-by: Vicent Marti <vmg@strn.cat> * Add parsing support for GTID functions (vitessio#10579) * feat: add parsing support for GTID functions Signed-off-by: Kushal Kumar <kushalkumargupta4@gmail.com> * test: add planner and end to end tests for a few gtid functions Signed-off-by: Manan Gupta <manan@planetscale.com> Co-authored-by: Manan Gupta <manan@planetscale.com> Signed-off-by: Vicent Marti <vmg@strn.cat> * Parameterize BIT types and fixes in HEX types (vitessio#10689) * feat: add parsing for bitnums Signed-off-by: Manan Gupta <manan@planetscale.com> * test: add invalid cases to tests Signed-off-by: Manan Gupta <manan@planetscale.com> * feat: normalize bitnums to bit vals too Signed-off-by: Manan Gupta <manan@planetscale.com> * feat: add normalization for bit literals Signed-off-by: Manan Gupta <manan@planetscale.com> * feat: parameterize binary value to hex Signed-off-by: Harshit Gangal <harshit@planetscale.com> * test: added e2e test in vtgate and vttablet Signed-off-by: Harshit Gangal <harshit@planetscale.com> * fix: fix the type conversion from hexnum and hexval to binary Signed-off-by: Harshit Gangal <harshit@planetscale.com> * test: refactor test Signed-off-by: Harshit Gangal <harshit@planetscale.com> * fix: return varbinary and flaghex for hexval and hexnum in eval engine typeOf Signed-off-by: Harshit Gangal <harshit@planetscale.com> * test: separate expectation for mysql and vitess result Signed-off-by: Harshit Gangal <harshit@planetscale.com> * test: fix test expectation Signed-off-by: Harshit Gangal <harshit@planetscale.com> * feat: added bitnum bind variable and test Signed-off-by: Harshit Gangal <harshit@planetscale.com> * proto: vtadmin side update Signed-off-by: Harshit Gangal <harshit@planetscale.com> * test: fixed test and added more bitnum bind var test Signed-off-by: Harshit Gangal <harshit@planetscale.com> * added license header Signed-off-by: Harshit Gangal <harshit@planetscale.com> Co-authored-by: Manan Gupta <manan@planetscale.com> Signed-off-by: Vicent Marti <vmg@strn.cat> * Mark aggregate functions callable (vitessio#10805) These should also implement the iCallable interface as they are also callable as functions. Signed-off-by: Dirkjan Bussink <d.bussink@gmail.com> Signed-off-by: Vicent Marti <vmg@strn.cat> * cherry-pick: fix bad merge Signed-off-by: Vicent Marti <vmg@strn.cat> Co-authored-by: rsajwani <rameezwazirali@hotmail.com> Co-authored-by: Andres Taylor <andres@planetscale.com> Co-authored-by: Kushal Kumar <59891164+K-Kumar-01@users.noreply.github.com> Co-authored-by: Manan Gupta <35839558+GuptaManan100@users.noreply.github.com> Co-authored-by: Manan Gupta <manan@planetscale.com> Co-authored-by: Florent Poinsard <florent.poinsard@outlook.fr> Co-authored-by: Harshit Gangal <harshit@planetscale.com> Co-authored-by: Rohit Nayak <rohit@planetscale.com> Co-authored-by: Dirkjan Bussink <d.bussink@gmail.com>
Description
This is a refactoring, introducing new structs for aggregation functions, instead of using
sqlparser.FuncExpr
for them. It should make the rest of the code a little easier to work with. This helps us represent entities in much cleaner way and reduces the number of checks we need to perform. Putting them inside a separate interface helps us in abstraction as well.I have introduced structure for each aggregate function. Here is the list of all aggregates (https://dev.mysql.com/doc/refman/8.0/en/aggregate-functions.html). Apart from json_* every other aggregate function is covered.
There are some suggestions by fmt during the merge so I did that as part of this PR as well. chk out main_test.go and vault_server.go
TODO: While initial review Andres (@systay) gave a feedback to consolidate all these struct into single entity and that will make code much simpler. But I would like to treat that refactoring as a separate PR. Please let me know if anyone fees strongly against it and I can do this change in this PR itself.
Related Issue(s)
Checklist
Deployment Notes