beliefer commented on a change in pull request #32477:
URL: https://github.com/apache/spark/pull/32477#discussion_r632423582



##########
File path: 
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/util/StringUtils.scala
##########
@@ -66,6 +67,52 @@ object StringUtils extends Logging {
     "(?s)" + out.result() // (?s) enables dotall mode, causing "." to match 
new lines
   }
 
+  /**
+   * Validate and convert SQL 'similar to' pattern to a Java regular 
expression.
+   *
+   * This function is similar to escapeLikeRegex, but there are some 
differences as follows:
+   * 1. If the escape character precedes the meta character for SIMILAR TO, 
the meta character
+   *    should convert to quote literal.
+   * 2. If '\' is not escape character, need convert to quote literal.
+   * 3. '.', '^' and '$' is not a meta character for SIMILAR TO,
+   *    so we need convert it to quote literal.
+   * 4. Avoid convert the characters of Java regular expression to quote 
literal.
+   * @param pattern the SQL pattern to convert
+   * @param escapeChar the escape character.
+   * @return the equivalent Java regular expression of the pattern for SIMILAR 
TO
+   */
+  def escapeSimilarRegex(pattern: String, escapeChar: Char): String = {

Review comment:
       escapeLikeRegex produces the_regex
   escapeSimilarRegex produces ^the_regex$




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

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