-
Notifications
You must be signed in to change notification settings - Fork 605
Parse SIGNED INTEGER type in MySQL CAST #1739
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
Conversation
9616c36
to
b84315a
Compare
See relevant sqlparser [PR]. [PR]: apache/datafusion-sqlparser-rs#1739 Change-Id: I11a01b48f1649c6530cdbe7bd23c158e9fe4f888
b84315a
to
2877163
Compare
src/ast/data_type.rs
Outdated
/// Semantically equivalent to `BIGINT`. | ||
/// | ||
/// [MySQL CAST]: https://dev.mysql.com/doc/refman/8.4/en/cast-functions.html | ||
Signed(bool), |
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.
thinking it feels a unexpected to use Signed(true)
to represent SIGNED INTEGER
? and the repr assumes a mysql-only type which might not be the case going forward. Feels like it'd be clear to represent them explicitly as SIGNED
and SIGNED INTEGER
where both can be reused by other dialects later if needed?
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'm not sure exactly what you mean. Different variants Signed = SIGNED
and SignedInteger = SIGNED INTEGER
? The only reason I didn't do that is there's already UnsignedInt = INT[EGER] UNSIGNED
and it would be even more confusing to have UnsignedInteger = UNSIGNED INTEGER
, and very disruptive to change the existing UnsignedInt
to IntUnsigned
or something.
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.
Ah I see, that is what you are suggesting. I misread your previous comment, sorry! I'll try that out.
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.
Fixed. Let me know if this is what you had in mind. Definitely could be a bit disruptive to downstream users.
MySQL doesn't have the same set of possible CAST types as for e.g. column definitions. For example, it raises a syntax error for `CAST(1 AS INTEGER SIGNED)` and instead expects `CAST(1 AS SIGNED INTEGER)`. We retain the current somewhat permissive datatype parsing behavior (e.g. allowing `CAST(1 AS BIGINT)` even though MySQL would raise a syntax error), and add datatypes for this specific case (`SIGNED [INTEGER]` and `UNSIGNED [INTEGER]`). To keep the naming consistent across datatypes, we also rename `UnsignedInt` to `IntUnsigned` and similar for other unsigned datatypes. This means they display in the same way they are written, i.e. `IntUnsigned = INT UNSIGNED` instead of `UnsignedInt = INT UNSIGNED`. Closes apache#1589
2877163
to
3f70716
Compare
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.
MySQL doesn't have the same set of possible CAST types as for e.g. column definitions. For example, it raises a syntax error for
CAST(1 AS INTEGER SIGNED)
and instead expectsCAST(1 AS SIGNED INTEGER)
.We retain the current somewhat permissive datatype parsing behavior (e.g. allowing
CAST(1 AS BIGINT)
even though MySQL would raise a syntax error), and add datatypes for this specific case (SIGNED [INTEGER]
andUNSIGNED [INTEGER]
).To keep the naming consistent across datatypes, we also rename
UnsignedInt
toIntUnsigned
and similar for other unsigned datatypes. This means they display in the same way they are written, i.e.IntUnsigned = INT UNSIGNED
instead ofUnsignedInt = INT UNSIGNED
.Closes #1589