spark-reviews mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From gatorsmile <...@git.apache.org>
Subject [GitHub] spark pull request #15398: [SPARK-17647][SQL] Fix backslash escaping in 'LIK...
Date Sat, 22 Oct 2016 14:58:21 GMT
Github user gatorsmile commented on a diff in the pull request:

    https://github.com/apache/spark/pull/15398#discussion_r84578560
  
    --- Diff: sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/util/StringUtils.scala
---
    @@ -19,32 +19,34 @@ package org.apache.spark.sql.catalyst.util
     
     import java.util.regex.{Pattern, PatternSyntaxException}
     
    +import org.apache.spark.sql.AnalysisException
     import org.apache.spark.unsafe.types.UTF8String
     
     object StringUtils {
     
    -  // replace the _ with .{1} exactly match 1 time of any character
    -  // replace the % with .*, match 0 or more times with any character
    -  def escapeLikeRegex(v: String): String = {
    -    if (!v.isEmpty) {
    -      "(?s)" + (' ' +: v.init).zip(v).flatMap {
    -        case (prev, '\\') => ""
    -        case ('\\', c) =>
    -          c match {
    -            case '_' => "_"
    -            case '%' => "%"
    -            case _ => Pattern.quote("\\" + c)
    -          }
    -        case (prev, c) =>
    +  /** Convert 'like' pattern to Java regex. */
    +  def escapeLikeRegex(str: String): String = {
    +    val in = str.toIterator
    +    val out = new StringBuilder()
    +
    +    def fail(message: String) = throw new AnalysisException(
    +      s"the pattern '$str' is invalid, $message")
    --- End diff --
    
    -> 
    ```Scala
    s"The pattern '$str' is invalid. Reason: $message"
    ```


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


Mime
View raw message