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

Fix formatting for function expressions and booleans #10255

Merged
merged 1 commit into from
May 11, 2022

Conversation

dbussink
Copy link
Contributor

These do not change casing in MySQL so they should not be canonicalized to uppercase in the canonical uppercase form either.

This also will lead to spurious incorrect diffs with schemadiff potentially.

Related Issue(s)

Found when working on #10203

Checklist

  • "Backport me!" label has been added if this change should be backported
  • Tests were added or are not required
  • Documentation was added or is not required

These do not change casing in MySQL so they should not be canonicalized
to uppercase in the canonical uppercase form either.

This also will lead to spurious incorrect diffs with schemadiff
potentially.

Signed-off-by: Dirkjan Bussink <d.bussink@gmail.com>
@github-actions
Copy link
Contributor

Review Checklist

Hello reviewers! 👋 Please follow this checklist when reviewing this Pull Request.

General

  • Ensure that the Pull Request has the correct release notes label. release notes none should only be used for PRs that are so trivial that they need not be included.
  • If a new flag is being introduced, review whether it is really needed. The flag names should be clear and intuitive (as far as possible), and the flag's help should be descriptive.

Bug fixes

  • There should be at least one unit or end-to-end test.
  • The Pull Request description should either include a link to an issue that describes the bug OR an actual description of the bug and how to reproduce, along with a description of the fix.

Non-trivial changes

  • There should be some code comments as to why things are implemented the way they are.

New/Existing features

  • Should be documented, either by modifying the existing documentation or creating new documentation.
  • New features should have a link to a feature request issue or an RFC that documents the use cases, corner cases and test cases.

Backward compatibility

  • Protobuf changes should be wire-compatible.
  • Changes to _vt tables and RPCs need to be backward compatible.
  • vtctl command output order should be stable and awk-able.

@@ -1310,7 +1310,7 @@ func (node *FuncExpr) Format(buf *TrackedBuffer) {
if containEscapableChars(funcName, NoAt) {
writeEscapedString(buf, funcName)
} else {
buf.literal(funcName)
buf.WriteString(funcName)
Copy link
Member

Choose a reason for hiding this comment

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

This would mean that function name won't be capitalised? Is that what we want? Don't we need them to be in the same case in canonical form for schema-diff?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@GuptaManan100 The thing is that MySQL doesn't capitalize it either in it's canonical form:

mysql> create table t1 (b binary(16) default (UUID_TO_BIN(UUID(), TRUE)));
Query OK, 0 rows affected (0.01 sec)

mysql> show create table t1;
+-------+--------------------------------------------------------------------------------------------------------------------------------------------+
| Table | Create Table                                                                                                                               |
+-------+--------------------------------------------------------------------------------------------------------------------------------------------+
| t1    | CREATE TABLE `t1` (
  `b` binary(16) DEFAULT (uuid_to_bin(uuid(),true))
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci |
+-------+--------------------------------------------------------------------------------------------------------------------------------------------+
1 row in set (0.00 sec)

mysql> 

As you can see above, it explicit is in lowercase. The same applies to true as well. Always upcasing it here explicitly causes problems for schemadiff that not doing solves.

Copy link
Member

Choose a reason for hiding this comment

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

Hmm okay, I am thinking what if a user gave a query like create table t1 (b binary(16) default (UuiD_TO_BiN(UUID(), TRUE))); Should we also lower-case the function name?

Copy link
Member

@GuptaManan100 GuptaManan100 May 11, 2022

Choose a reason for hiding this comment

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

Because this is the output I see from the parser right now (on main) -

create table t1 (
	b binary(16) default (UuiD_TO_BiN(UUID(), true))
)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@GuptaManan100 I thought about that, but that isn't something that so far has been done in the parser in general. For example, if you look at how collations and charsets are treated, those are not canonicalized into forced lowercase either.

So I've followed that existing situation here to at least fix the immediate problem. The issue right now is that schemas fed from MySQL itself are changing. While the case you mention can also be a problem, it's much less a practical problem since schemadiff is normally always fed schemas from MySQL, specifically from SHOW CREATE TABLE.

If the preference is to force lowercase things for stuff like this, I think we can do that, but I'd prefer if we can take a separate pass at that since it applies to a lot more cases than just these fixes here (like collations and charsets).

Copy link
Member

Choose a reason for hiding this comment

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

Okay, this makes sense

@GuptaManan100 GuptaManan100 merged commit e5e59d0 into main May 11, 2022
@GuptaManan100 GuptaManan100 deleted the dbussink/fix-ast-formatting branch May 11, 2022 06:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants