Repository navigation
Mysql unparser cast targets - #26888
Merged
Merged
Conversation
nuno-faria
approved these changes
Oct 30, 2026
nuno-faria
left a comment
Contributor
There was a problem hiding this comment.
Thanks @hozan23, I leave some suggestions below. Postgres also doesn't support unsigned types, so in the future we can use these new overrides to fix it.
hozan23
force-pushed
the
mysql-unparser-cast-targets
branch
from
October 31, 2026 19:24
9b3559c to
5ca2650
Compare
Contributor
Author
|
Thanks @nuno-faria for the review, I have combined the tests as you suggested. I agree we can use these new overrides for Postgres as well. |
…MySQL MySQL's CAST does not accept SMALLINT, TINYINT UNSIGNED, SMALLINT UNSIGNED, INTEGER UNSIGNED or BIGINT UNSIGNED as target types, but arrow_dtype_to_ast_dtype hard-coded them for Int16 and UInt8..UInt64, so MySqlDialect could not override them and the generated SQL failed with ERROR 1064.
hozan23
force-pushed
the
mysql-unparser-cast-targets
branch
from
November 1, 2026 13:04
5ca2650 to
4f3d304
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Which issue does this PR close?
Rationale for this change
MySQL's
CASTdoes not acceptSMALLINTor the... UNSIGNEDinteger types as target types, butarrow_dtype_to_ast_dtypehard-codes them forInt16andUInt8..UInt64. As a result,MySqlDialectcannot override them and the generated SQL fails withERROR 1064.See https://dev.mysql.com/doc/refman/8.0/en/cast-functions.html#function_cast
Checked against MySQL 8.0.46 and 8.4.13 with
SELECT CAST('1' AS <type>): every type in the issue table fails withERROR 1064, whileSIGNEDandUNSIGNEDsucceed.What changes are included in this PR?
Dialecthooksint16_cast_dtypeanduint8/uint16/uint32/uint64_cast_dtype. Their defaults return the previous types.MySqlDialectreturnsSIGNEDforInt16andUNSIGNEDfor the unsigned types.This builds on #26883.
What is the testing strategy for this PR?
New unit tests in
datafusion/sql/src/unparser/expr.rs:mysql_int16_and_unsigned_casts: the new MySQL outputdefault_dialect_int16_and_unsigned_casts: the default output is unchangedcustom_dialect_int16_and_unsigned_casts: the builder settersAre there any user-facing changes?
With
MySqlDialect,Int16casts now unparse asSIGNEDand unsigned integer casts asUNSIGNED.