jiwen624 commented on code in PR #56558:
URL: https://github.com/apache/spark/pull/56558#discussion_r4487916719


##########
sql/core/src/main/scala/org/apache/spark/sql/jdbc/MySQLDialect.scala:
##########
@@ -130,6 +124,13 @@ private case class MySQLDialect() extends JdbcDialect with 
SQLConfHelper with No
     }
   }
 
+  override def compileValue(value: Any): Any = value match {
+    case stringValue: String if stringValue.contains('\\') =>
+      val escaped = escapeSql(stringValue.replace("\\", "\\\\"))
+      raw"""REPLACE('$escaped', '\\', LEFT('\\', 1))"""

Review Comment:
   Good question! This is to make the same SQL work whatever the server's 
`sql_mode` is: `\\` is one backslash in the default mode but two under 
`NO_BACKSLASH_ESCAPES`, and a single `\` doesn't parse in the default mode. 
`LEFT('\\', 1)` is exactly one backslash in both modes. (I first tried hex 
literals, but they don't keep the connection collation.)



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