urosstan-db commented on code in PR #56558:
URL: https://github.com/apache/spark/pull/56558#discussion_r4480088738


##########
sql/core/src/main/scala/org/apache/spark/sql/jdbc/JdbcDialects.scala:
##########
@@ -429,9 +429,48 @@ abstract class JdbcDialect extends Serializable with 
Logging {
               "funcName" -> e.name()))
         }
         inputToSQL(e.children()(0))
+      case e: GeneralScalarExpression if isLikeStringPredicate(e.name()) =>
+        
buildLikeStringPredicate(e).getOrElse(declineLikeStringPredicate(e.name()))
       case _ => super.build(expr)
     }
 
+    protected def likeEscapeChar: Char = '\\'
+
+    override protected def escapeSpecialCharsForLikePattern(str: String): 
String =
+      str.flatMap {
+        case c @ ('_' | '%') => s"$likeEscapeChar$c"
+        case c if c == likeEscapeChar => s"$c$c"
+        case c => c.toString
+      }
+
+    private def isLikeStringPredicate(name: String): Boolean =
+      name == "STARTS_WITH" || name == "ENDS_WITH" || name == "CONTAINS"
+
+    private def declineLikeStringPredicate(name: String): Nothing =

Review Comment:
   Why do we need this method, can we use visitUnexpectedExpr since it usually 
used in dialects already and it does not use legacy error class



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