Return-Path: X-Original-To: archive-asf-public-internal@cust-asf2.ponee.io Delivered-To: archive-asf-public-internal@cust-asf2.ponee.io Received: from cust-asf.ponee.io (cust-asf.ponee.io [163.172.22.183]) by cust-asf2.ponee.io (Postfix) with ESMTP id C57DB200BAC for ; Wed, 12 Oct 2016 05:35:55 +0200 (CEST) Received: by cust-asf.ponee.io (Postfix) id C3E4C160AF3; Wed, 12 Oct 2016 03:35:55 +0000 (UTC) Delivered-To: archive-asf-public@cust-asf.ponee.io Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by cust-asf.ponee.io (Postfix) with SMTP id 18EC7160AE6 for ; Wed, 12 Oct 2016 05:35:54 +0200 (CEST) Received: (qmail 70639 invoked by uid 500); 12 Oct 2016 03:35:54 -0000 Mailing-List: contact reviews-help@spark.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Delivered-To: mailing list reviews@spark.apache.org Received: (qmail 70624 invoked by uid 99); 12 Oct 2016 03:35:54 -0000 Received: from git1-us-west.apache.org (HELO git1-us-west.apache.org) (140.211.11.23) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 12 Oct 2016 03:35:54 +0000 Received: by git1-us-west.apache.org (ASF Mail Server at git1-us-west.apache.org, from userid 33) id E7540E0061; Wed, 12 Oct 2016 03:35:53 +0000 (UTC) From: viirya To: reviews@spark.apache.org Reply-To: reviews@spark.apache.org References: In-Reply-To: Subject: [GitHub] spark pull request #15398: [SPARK-17647][SQL] Fix backslash escaping in 'LIK... Content-Type: text/plain Message-Id: <20161012033553.E7540E0061@git1-us-west.apache.org> Date: Wed, 12 Oct 2016 03:35:53 +0000 (UTC) archived-at: Wed, 12 Oct 2016 03:35:56 -0000 Github user viirya commented on a diff in the pull request: https://github.com/apache/spark/pull/15398#discussion_r82931395 --- 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 -- `\Q\\E\Qa\E` is correct. But doesn't it become `\Qa\E` in this change? For `\\a`, the prefixing `\\` will go the next branch and enable `escaping`. Then the next char `a` will be quoted here. So it becomes `\Qa\E`. BTW, before this change, it will be `\Q\a\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 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