You are viewing a plain text version of this content. The canonical link for it is here.
Posted to reviews@spark.apache.org by GitBox <gi...@apache.org> on 2021/05/13 17:48:09 UTC
[GitHub] [spark] cloud-fan commented on a change in pull request #32477: [SPARK-35348][SQL] Support the utils for escapse the regex for ANSI SQL: SIMILAR TO … ESCAPE syntax
cloud-fan commented on a change in pull request #32477:
URL: https://github.com/apache/spark/pull/32477#discussion_r631990533
##########
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:
Is it possible to share some code with `escapeLikeRegex`? It seems like the only difference is, let's say `escapeLikeRegex` produces `^the_regex`, and `escapeSimilarRegex` should produce `^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:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org