ulysses-you commented on issue #26860: [SPARK-30230][SQL] Like ESCAPE syntax 
can not use '_' and '%'
URL: https://github.com/apache/spark/pull/26860#issuecomment-565341754
 
 
   If '%' and '_' as escape, how to use the real pattern.
   Like this ?
   ```
   SELECT 'abcd' LIKE 'ab%%' escape '%';
   ```
   
   But actually `StringUtils.escapeLikeRegex` will do this check.
   ```
   while (in.hasNext) {
         in.next match {
           case c1 if c1 == escapeChar && in.hasNext =>
             val c = in.next
             c match {
               case '_' | '%' => out ++= Pattern.quote(Character.toString(c))
               case c if c == escapeChar => out ++= 
Pattern.quote(Character.toString(c))
               case _ => fail(s"the escape character is not allowed to precede 
'$c'")
             }
           case c if c == escapeChar => fail("it is not allowed to end with the 
escape character")
           // we will never run these code path
           case '_' => out ++= "."
           case '%' => out ++= ".*"
           case c => out ++= Pattern.quote(Character.toString(c))
         }
       }
   ```

----------------------------------------------------------------
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:
[email protected]


With regards,
Apache Git Services

---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to