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

    https://github.com/apache/spark/pull/2908#discussion_r19328446
  
    --- Diff: 
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/expressions/stringOperations.scala
 ---
    @@ -102,31 +102,27 @@ case class Like(left: Expression, right: Expression)
     
       // replace the _ with .{1} exactly match 1 time of any character
       // replace the % with .*, match 0 or more times with any character
    -  override def escape(v: String) = {
    -    val sb = new StringBuilder()
    -    var i = 0;
    -    while (i < v.length) {
    -      // Make a special case for "\\_" and "\\%"
    -      val n = v.charAt(i);
    -      if (n == '\\' && i + 1 < v.length && (v.charAt(i + 1) == '_' || 
v.charAt(i + 1) == '%')) {
    -        sb.append(v.charAt(i + 1))
    -        i += 1
    -      } else {
    -        if (n == '_') {
    -          sb.append(".");
    -        } else if (n == '%') {
    -          sb.append(".*");
    -        } else {
    -          sb.append(Pattern.quote(Character.toString(n)));
    -        }
    -      }
    -
    -      i += 1
    +  override def escape(v: String) =
    +    if (!v.isEmpty) {
    +      "(?s)" + (' ' +: v.init).zip(v).flatMap {
    +        case (prev, '\\') => ""
    +        case ('\\', c) =>
    +          c match {
    +            case '_' => "_"
    +            case '%' => "%"
    +            case _ => Pattern.quote("\\" + c)
    --- End diff --
    
    No problem, thanks for your suggestion.


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