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

sqlparser: Refactor out servenv and inject everywhere #14822

Merged
merged 2 commits into from
Dec 19, 2023

Conversation

dbussink
Copy link
Contributor

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

  • "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

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

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

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

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.

Copy link
Contributor

@shlomi-noach shlomi-noach left a 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]>
@dbussink dbussink requested a review from vmg as a code owner December 19, 2023 13:57
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.

This is excellent work!!!

@dbussink dbussink merged commit 071454f into vitessio:main Dec 19, 2023
116 checks passed
@dbussink dbussink deleted the dbussink/remove-servenv-sqlparser branch December 19, 2023 15:38
ejortegau pushed a commit to slackhq/vitess that referenced this pull request Jan 24, 2024
Signed-off-by: Dirkjan Bussink <[email protected]>
Signed-off-by: Eduardo J. Ortega U. <[email protected]>
systay pushed a commit that referenced this pull request Jul 22, 2024
…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]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Component: General Changes throughout the code base Type: Internal Cleanup
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants