Github user jodersky commented on a diff in the pull request:

    https://github.com/apache/spark/pull/15398#discussion_r83329826
  
    --- Diff: 
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/util/StringUtils.scala
 ---
    @@ -25,26 +25,25 @@ 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) =>
    -          c match {
    -            case '_' => "."
    -            case '%' => ".*"
    -            case _ => Pattern.quote(Character.toString(c))
    -          }
    -      }.mkString
    -    } else {
    -      v
    +  def escapeLikeRegex(str: String): String = {
    +    val builder = new StringBuilder()
    +    var escaping = false
    +    for (next <- str) {
    +      if (escaping) {
    +        builder ++= Pattern.quote(Character.toString(next))
    --- End diff --
    
    I think we're misunderstanding each other, there are so many different 
contexts in which a backslash is used :)
    
    The prefix `'\\'` that matches the escape char here is the *scala source* 
escape for the literal character `'\`' (If scala had triple quotes for chars as 
it does for strings, I could have written `'''\'''`). So, in the if statement 
`\\` will consume one character, a `\`.
    The subsequent `\` will be quoted in the `escaping` case, and the final `a` 
will also be quoted in the last case, resulting in a `\Q\\E\Qa\E`.


---
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 infrastruct...@apache.org or file a JIRA ticket
with INFRA.
---

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

Reply via email to