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
Remove parenthesis from the AST #5906
Conversation
8bc5874
to
dcb6504
Compare
go/vt/sqlparser/tracked_buffer.go
Outdated
case 'a': | ||
buf.WriteArg(values[fieldnum].(string)) | ||
case 'p': |
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 part feels like it can lead to future bugs. Is there a way to make %v handle this correctly?
The main concern is this: someone may call Myprintf with %v without knowing that they should have called ExprPrintf with %p.
b4e8c10
to
47a57a6
Compare
@sougou I've squashed, rebased and generally cleaned up this PR Is there anything else you think needs to change before we can merge it? |
Instead of keeping this information in the AST, we put in parens in the string representation of queries when needed when printing. This includes adding code that takes precendence into consideration - something that already we already need to do when parsing. Unfortunately I haven't found a good way to use the same source information for both sides of the precedence puzzle. Signed-off-by: Andres Taylor <andres@planetscale.com>
Myprintf uses from AST now include the parent struct. In order to get better readability and guarantees that we don't introduce regressions in the future, this refactoring changes Myprintf uses from the AST to always provide the parent structure. Using this information, Myprintf can figure out when parens are needed. Signed-off-by: Harshit Gangal <harshit@planetscale.com> Signed-off-by: Andres Taylor <andres@planetscale.com>
Signed-off-by: Andres Taylor <andres@planetscale.com>
Signed-off-by: Andres Taylor <andres@planetscale.com>
To make sure that the meaning of queries didn't change by mistake, Vitess used to keep parens around in the AST even though they are nog strictly speaking needed there.
This change set solves the parens problem by taking precedence into consideration, and adding parens to the output string when needed instead of keeping them in the AST structure.
The benefit is that other parts of the code can just ignore parenthesis and trust that the AST will handle it for them.
NOTE: This introduces a behaviour change that can be noticable for end-users. Unaliased SELECT expressions can get the column name used changed (by parens being removed).
Example:
Vitess already did some changing of column names (white spaces were not kept around). Now it does it a little differently. If you need a specific name, it's advisable to use the
AS columnAlias
construct.