-
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
sqlparser: Refactor out servenv and inject everywhere #14822
sqlparser: Refactor out servenv and inject everywhere #14822
Conversation
This is a refactor similar as was done with collations, to remove the servenv dependency from sqlparser and to make sqlparser usable entirely with no global state for other dependencies. This means we now create a sqlparser instance with the appropriate settings instead of modifying global configuration flags for things like the version and for truncation settings. Signed-off-by: Dirkjan Bussink <[email protected]>
func (pq *ParsedQuery) MarshalJSON() ([]byte, error) { | ||
return json.Marshal(TruncateForUI(pq.Query)) | ||
return json.Marshal(pq.Query) |
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 have removed the truncation here. The JSON serialization for this was only used in tests and there we can also work fine without the truncation. Since it's not used outside of tests it looks like, it's safe here to remove. Keeping this was really annoying with how global state is affecting this, so removing it is far more trivial.
@@ -339,7 +339,7 @@ | |||
} | |||
], | |||
"FullQuery": "update d set foo = 'foo' where `name` in ('a', 'b') limit :#maxLimit", | |||
"WhereClause": "where `name` in ('a', 'b')" | |||
"WhereClause": " where `name` in ('a', 'b')" |
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.
These cases change since they use the JSON serialization mentioned earlier and a side-effect of TruncateForUI
was that it also trimmed whitespaces. We now dropped that so the original text is still here. It has no functional change though.
@@ -104,7 +107,6 @@ type vcursorImpl struct { | |||
topoServer *topo.Server | |||
logStats *logstats.LogStats | |||
collation collations.ID | |||
collationEnv *collations.Environment |
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.
Removed it from here since I realized with the parser, we can always get it from the executor already anyway. Keeping it consistent between the parser and collation env this way.
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.
All righty. Massive change. 99.9% (needs citation) of changes are functions adding a *sqlparser.Parser
argument, and using that parser.
go/vt/sqlparser/parser.go
is the main change, and that, too, is basically embedding all functions in a Parser
struct.
LGTM
This reduces the dependency on the binlog package and json logic if not strictly needed for the mysql package. Signed-off-by: Dirkjan Bussink <[email protected]>
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 excellent work!!!
Signed-off-by: Dirkjan Bussink <[email protected]> Signed-off-by: Eduardo J. Ortega U. <[email protected]>
…here (#3997) * cherry pick of 14822 Signed-off-by: Dirkjan Bussink <[email protected]> * boost: Fix injecting sqlparser everywhere as well Signed-off-by: Dirkjan Bussink <[email protected]> --------- Signed-off-by: Dirkjan Bussink <[email protected]> Co-authored-by: Dirkjan Bussink <[email protected]>
This is a refactor similar as was done with collations, to remove the servenv dependency from sqlparser and to make sqlparser usable entirely with no global state for other dependencies.
This means we now create a sqlparser instance with the appropriate settings instead of modifying global configuration flags for things like the version and for truncation settings.
Related Issue(s)
Part of #14717, follow up to #14781
Checklist