marko-sisovic-db commented on code in PR #60455:
URL: https://github.com/apache/spark/pull/60455#discussion_r4598282034
##########
sql/core/src/main/scala/org/apache/spark/sql/jdbc/MySQLDialect.scala:
##########
@@ -130,11 +130,19 @@ private case class MySQLDialect() extends JdbcDialect
with SQLConfHelper with No
// The common JDBC mapping is DOUBLE PRECISION, which is not a
portable CAST target for
// MySQL-compatible databases. In particular, MariaDB rejects it
with a syntax error.
throw new UnsupportedOperationException("Cannot cast to double type")
- // MySQL does not support casting to SHORT, INT or BIGINT, it uses
SIGNED instead.
- case _: IntegralType if exprDataType.isInstanceOf[FractionalType] &&
- !conf.legacyJdbcRoundIntegralCastPushdown =>
- s"CAST(${truncateFractionalValue(expr)} AS SIGNED)"
- case _: IntegralType => s"CAST($expr AS SIGNED)"
+ // MySQL's only integral CAST target is 64-bit SIGNED, which matches
Spark only for BIGINT
+ // casts from FLOAT, DOUBLE, or a DECIMAL that fits 64 bits. Spark
evaluates other casts.
+ case LongType if !conf.legacyJdbcRoundIntegralCastPushdown &&
(exprDataType match {
+ case FloatType | DoubleType => true
Review Comment:
review found an existing correctness issue, not caused by this PR: if the
casted value overflows, behavior between pushdown and no pushdown is different.
No pushdown throws an error, pusdown silently overflows. It's a good
opportunity to fix this now. This is only scoped to MySQL
--
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]