aleksandar-trajkovic-db commented on code in PR #60455:
URL: https://github.com/apache/spark/pull/60455#discussion_r4587504109


##########
sql/catalyst/src/main/scala/org/apache/spark/sql/internal/SQLConf.scala:
##########
@@ -7627,6 +7627,18 @@ object SQLConf {
       .booleanConf
       .createWithDefault(false)
 
+  val LEGACY_JDBC_ROUND_INTEGRAL_CAST_PUSHDOWN =
+    buildConf("spark.sql.legacy.jdbc.roundIntegralCastPushdown.enabled")

Review Comment:
   Fixed in a543d8fca32: added an entry to "Upgrading from Spark SQL 4.3 to 
4.4" that names the affected databases, the newly pushed and no longer pushed 
casts, and the conf.
   



##########
sql/core/src/main/scala/org/apache/spark/sql/jdbc/MySQLDialect.scala:
##########
@@ -126,6 +130,11 @@ 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.

Review Comment:
   Fixed in a543d8fca32: the comment now says MySQL's only integral CAST target 
is 64-bit SIGNED and which casts are pushed.
   



##########
sql/core/src/main/scala/org/apache/spark/sql/jdbc/MySQLDialect.scala:
##########
@@ -126,6 +130,11 @@ 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)"

Review Comment:
   Fixed in a543d8fca32: MySQL now pushes integral casts only from FLOAT, 
DOUBLE and DECIMAL to BIGINT, and string, boolean, TIMESTAMP, TIME and integral 
sources stay in Spark. Integral casts of datetime values also stay in Spark on 
every dialect, since SQL Server, for example, returns a day count.
   



##########
sql/core/src/main/scala/org/apache/spark/sql/jdbc/MySQLDialect.scala:
##########
@@ -126,6 +130,11 @@ 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)"

Review Comment:
   Fixed in a543d8fca32: DECIMALs with more than 18 integer digits, including 
BIGINT UNSIGNED as DECIMAL(20, 0), are no longer pushed to MySQL. INT, SMALLINT 
and TINYINT targets stay in Spark too, since SIGNED has no range check for 
them. FLOAT and DOUBLE values past the 64-bit range raise ERROR 1690 on MySQL 
9.6, where Spark raises CAST_OVERFLOW.
   



-- 
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