hozan23 opened a new pull request, #26888:
URL: https://github.com/apache/datafusion/pull/26888

    ## Which issue does this PR close?
   
     - Closes #26887.
   
     ## Rationale for this change
   
     MySQL's `CAST` does not accept `SMALLINT` or the `... UNSIGNED` integer 
types as target types, but `arrow_dtype_to_ast_dtype` hard-codes them for 
`Int16` and `UInt8`..`UInt64`. As a result, `MySqlDialect` cannot override them 
and the generated SQL fails with `ERROR 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 with `ERROR 1064`, while `SIGNED` and 
`UNSIGNED` succeed.
   
     ## What changes are included in this PR?
   
     - New `Dialect` hooks `int16_cast_dtype` and 
`uint8`/`uint16`/`uint32`/`uint64_cast_dtype`. Their defaults return the 
previous types.
     - `MySqlDialect` returns `SIGNED` for `Int16` and `UNSIGNED` for 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 output
     - `default_dialect_int16_and_unsigned_casts`: the default output is 
unchanged
     - `custom_dialect_int16_and_unsigned_casts`: the builder setters
   
     ## Are there any user-facing changes?
   
     With `MySqlDialect`, `Int16` casts now unparse as `SIGNED` and unsigned 
integer casts as `UNSIGNED`.
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to