[GitHub] [spark] beliefer commented on a change in pull request #25001: [SPARK-28083][SQL] Support LIKE ... ESCAPE syntax

2019-12-05 Thread GitBox
beliefer commented on a change in pull request #25001: [SPARK-28083][SQL] 
Support LIKE ... ESCAPE syntax
URL: https://github.com/apache/spark/pull/25001#discussion_r354649171
 
 

 ##
 File path: 
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/expressions/regexpExpressions.scala
 ##
 @@ -104,19 +103,22 @@ abstract class StringRegexExpression extends 
BinaryExpression
   spark.sql.parser.escapedStringLiterals   false
   > SELECT '%SystemDrive%\\Users\\John' _FUNC_ '\%SystemDrive\%Users%';
   true
+  > SELECT '%SystemDrive%/Users/John' _FUNC_ '/%SystemDrive/%//Users%' 
ESCAPE '/';
+  true
   """,
   note = """
 Use RLIKE to match with standard regular expressions.
   """,
   since = "1.0.0")
 // scalastyle:on line.contains.tab
-case class Like(left: Expression, right: Expression) extends 
StringRegexExpression {
+case class Like(left: Expression, right: Expression, escapeChar: Char = '\\')
+  extends StringRegexExpression {
 
-  override def escape(v: String): String = StringUtils.escapeLikeRegex(v)
+  override def escape(v: String): String = StringUtils.escapeLikeRegex(v, 
escapeChar)
 
   override def matches(regex: Pattern, str: String): Boolean = 
regex.matcher(str).matches()
 
-  override def toString: String = s"$left LIKE $right"
+  override def toString: String = s"$left LIKE $right ESCAPE '$escapeChar'"
 
 Review comment:
   OK


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:
us...@infra.apache.org


With regards,
Apache Git Services

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



[GitHub] [spark] beliefer commented on a change in pull request #25001: [SPARK-28083][SQL] Support LIKE ... ESCAPE syntax

2019-12-05 Thread GitBox
beliefer commented on a change in pull request #25001: [SPARK-28083][SQL] 
Support LIKE ... ESCAPE syntax
URL: https://github.com/apache/spark/pull/25001#discussion_r35465
 
 

 ##
 File path: 
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/expressions/regexpExpressions.scala
 ##
 @@ -83,16 +83,15 @@ abstract class StringRegexExpression extends 
BinaryExpression
   % matches zero or more characters in the input (similar to .* in 
posix regular
   expressions)
 
-  The escape character is '\'. If an escape character precedes a 
special symbol or another
-  escape character, the following character is matched literally. It 
is invalid to escape
-  any other character.
-
   Since Spark 2.0, string literals are unescaped in our SQL parser. 
For example, in order
   to match "\abc", the pattern should be "\\abc".
 
   When SQL config 'spark.sql.parser.escapedStringLiterals' is enabled, 
it fallbacks
   to Spark 1.6 behavior regarding string literal parsing. For example, 
if the config is
   enabled, the pattern to match "\abc" should be "\abc".
+  * escape - an string added since Spark 3.0. The default escape character 
is the '\'.
 
 Review comment:
   OK.


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:
us...@infra.apache.org


With regards,
Apache Git Services

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



[GitHub] [spark] beliefer commented on a change in pull request #25001: [SPARK-28083][SQL] Support LIKE ... ESCAPE syntax

2019-12-04 Thread GitBox
beliefer commented on a change in pull request #25001: [SPARK-28083][SQL] 
Support LIKE ... ESCAPE syntax
URL: https://github.com/apache/spark/pull/25001#discussion_r354126149
 
 

 ##
 File path: 
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/optimizer/expressions.scala
 ##
 @@ -484,7 +484,7 @@ object LikeSimplification extends Rule[LogicalPlan] {
   private val equalTo = "([^_%]*)".r
 
   def apply(plan: LogicalPlan): LogicalPlan = plan transformAllExpressions {
-case Like(input, Literal(pattern, StringType)) =>
+case Like(input, Literal(pattern, StringType), opt) =>
 
 Review comment:
   OK


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:
us...@infra.apache.org


With regards,
Apache Git Services

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



[GitHub] [spark] beliefer commented on a change in pull request #25001: [SPARK-28083][SQL] Support LIKE ... ESCAPE syntax

2019-12-04 Thread GitBox
beliefer commented on a change in pull request #25001: [SPARK-28083][SQL] 
Support LIKE ... ESCAPE syntax
URL: https://github.com/apache/spark/pull/25001#discussion_r354125673
 
 

 ##
 File path: 
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/expressions/regexpExpressions.scala
 ##
 @@ -83,16 +83,15 @@ abstract class StringRegexExpression extends 
BinaryExpression
   % matches zero or more characters in the input (similar to .* in 
posix regular
   expressions)
 
-  The escape character is '\'. If an escape character precedes a 
special symbol or another
-  escape character, the following character is matched literally. It 
is invalid to escape
-  any other character.
-
   Since Spark 2.0, string literals are unescaped in our SQL parser. 
For example, in order
   to match "\abc", the pattern should be "\\abc".
 
   When SQL config 'spark.sql.parser.escapedStringLiterals' is enabled, 
it fallbacks
   to Spark 1.6 behavior regarding string literal parsing. For example, 
if the config is
   enabled, the pattern to match "\abc" should be "\abc".
+  * escape - an optional string added since Spark 3.0. The default escape 
character is the '\'.
 
 Review comment:
   OK


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:
us...@infra.apache.org


With regards,
Apache Git Services

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



[GitHub] [spark] beliefer commented on a change in pull request #25001: [SPARK-28083][SQL] Support LIKE ... ESCAPE syntax

2019-12-04 Thread GitBox
beliefer commented on a change in pull request #25001: [SPARK-28083][SQL] 
Support LIKE ... ESCAPE syntax
URL: https://github.com/apache/spark/pull/25001#discussion_r354122754
 
 

 ##
 File path: 
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/dsl/package.scala
 ##
 @@ -98,7 +98,8 @@ package object dsl {
   case _ => In(expr, list)
 }
 
-def like(other: Expression): Expression = Like(expr, other)
+def like(other: Expression, escapeCharOpt: Option[Char] = None): 
Expression =
 
 Review comment:
   OK


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:
us...@infra.apache.org


With regards,
Apache Git Services

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



[GitHub] [spark] beliefer commented on a change in pull request #25001: [SPARK-28083][SQL] Support LIKE ... ESCAPE syntax

2019-12-04 Thread GitBox
beliefer commented on a change in pull request #25001: [SPARK-28083][SQL] 
Support LIKE ... ESCAPE syntax
URL: https://github.com/apache/spark/pull/25001#discussion_r354122790
 
 

 ##
 File path: 
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/expressions/regexpExpressions.scala
 ##
 @@ -104,19 +103,24 @@ abstract class StringRegexExpression extends 
BinaryExpression
   spark.sql.parser.escapedStringLiterals   false
   > SELECT '%SystemDrive%\\Users\\John' _FUNC_ '\%SystemDrive\%Users%';
   true
+  > SELECT '%SystemDrive%/Users/John' _FUNC_ '/%SystemDrive/%//Users%' 
ESCAPE '/';
+  true
   """,
   note = """
 Use RLIKE to match with standard regular expressions.
   """,
   since = "1.0.0")
 // scalastyle:on line.contains.tab
-case class Like(left: Expression, right: Expression) extends 
StringRegexExpression {
+case class Like(left: Expression, right: Expression, escapeCharOpt: 
Option[Char] = None)
 
 Review comment:
   OK.


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:
us...@infra.apache.org


With regards,
Apache Git Services

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



[GitHub] [spark] beliefer commented on a change in pull request #25001: [SPARK-28083][SQL] Support LIKE ... ESCAPE syntax

2019-12-04 Thread GitBox
beliefer commented on a change in pull request #25001: [SPARK-28083][SQL] 
Support LIKE ... ESCAPE syntax
URL: https://github.com/apache/spark/pull/25001#discussion_r353688003
 
 

 ##
 File path: 
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/expressions/regexpExpressions.scala
 ##
 @@ -104,19 +103,24 @@ abstract class StringRegexExpression extends 
BinaryExpression
   spark.sql.parser.escapedStringLiterals   false
   > SELECT '%SystemDrive%\\Users\\John' _FUNC_ '\%SystemDrive\%Users%';
   true
+  > SELECT '%SystemDrive%/Users/John' _FUNC_ '/%SystemDrive/%//Users%' 
ESCAPE '/';
+  true
   """,
   note = """
 Use RLIKE to match with standard regular expressions.
   """,
   since = "1.0.0")
 // scalastyle:on line.contains.tab
-case class Like(left: Expression, right: Expression) extends 
StringRegexExpression {
+case class Like(left: Expression, right: Expression, escapeCharOpt: 
Option[Char] = None)
 
 Review comment:
   If user uses `SELECT ... LIKE ... ESCAPE ''`, I think `toString` display 
`SELECT ... LIKE ... ESCAPE ` is better than `SELECT ... LIKE ...` .
   Or we should display as `SELECT ... LIKE ... ESCAPE ''`


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:
us...@infra.apache.org


With regards,
Apache Git Services

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



[GitHub] [spark] beliefer commented on a change in pull request #25001: [SPARK-28083][SQL] Support LIKE ... ESCAPE syntax

2019-12-04 Thread GitBox
beliefer commented on a change in pull request #25001: [SPARK-28083][SQL] 
Support LIKE ... ESCAPE syntax
URL: https://github.com/apache/spark/pull/25001#discussion_r353688003
 
 

 ##
 File path: 
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/expressions/regexpExpressions.scala
 ##
 @@ -104,19 +103,24 @@ abstract class StringRegexExpression extends 
BinaryExpression
   spark.sql.parser.escapedStringLiterals   false
   > SELECT '%SystemDrive%\\Users\\John' _FUNC_ '\%SystemDrive\%Users%';
   true
+  > SELECT '%SystemDrive%/Users/John' _FUNC_ '/%SystemDrive/%//Users%' 
ESCAPE '/';
+  true
   """,
   note = """
 Use RLIKE to match with standard regular expressions.
   """,
   since = "1.0.0")
 // scalastyle:on line.contains.tab
-case class Like(left: Expression, right: Expression) extends 
StringRegexExpression {
+case class Like(left: Expression, right: Expression, escapeCharOpt: 
Option[Char] = None)
 
 Review comment:
   If user uses `SELECT ... LIKE ... ESCAPE ''`, I think `toString` display 
`SELECT ... LIKE ... ESCAPE ` is better than `SELECT ... LIKE ...` .


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:
us...@infra.apache.org


With regards,
Apache Git Services

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



[GitHub] [spark] beliefer commented on a change in pull request #25001: [SPARK-28083][SQL] Support LIKE ... ESCAPE syntax

2019-12-04 Thread GitBox
beliefer commented on a change in pull request #25001: [SPARK-28083][SQL] 
Support LIKE ... ESCAPE syntax
URL: https://github.com/apache/spark/pull/25001#discussion_r353616172
 
 

 ##
 File path: 
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/expressions/regexpExpressions.scala
 ##
 @@ -104,19 +103,24 @@ abstract class StringRegexExpression extends 
BinaryExpression
   spark.sql.parser.escapedStringLiterals   false
   > SELECT '%SystemDrive%\\Users\\John' _FUNC_ '\%SystemDrive\%Users%';
   true
+  > SELECT '%SystemDrive%/Users/John' _FUNC_ '/%SystemDrive/%//Users%' 
ESCAPE '/';
+  true
   """,
   note = """
 Use RLIKE to match with standard regular expressions.
   """,
   since = "1.0.0")
 // scalastyle:on line.contains.tab
-case class Like(left: Expression, right: Expression) extends 
StringRegexExpression {
+case class Like(left: Expression, right: Expression, escapeCharOpt: 
Option[Char] = None)
 
 Review comment:
   If user uses `SELECT ... LIKE ...`, I think `toString` display `SELECT ... 
LIKE ...` is better than `SELECT ... LIKE ... ESCAPE \`.


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:
us...@infra.apache.org


With regards,
Apache Git Services

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



[GitHub] [spark] beliefer commented on a change in pull request #25001: [SPARK-28083][SQL] Support LIKE ... ESCAPE syntax

2019-12-04 Thread GitBox
beliefer commented on a change in pull request #25001: [SPARK-28083][SQL] 
Support LIKE ... ESCAPE syntax
URL: https://github.com/apache/spark/pull/25001#discussion_r353616172
 
 

 ##
 File path: 
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/expressions/regexpExpressions.scala
 ##
 @@ -104,19 +103,24 @@ abstract class StringRegexExpression extends 
BinaryExpression
   spark.sql.parser.escapedStringLiterals   false
   > SELECT '%SystemDrive%\\Users\\John' _FUNC_ '\%SystemDrive\%Users%';
   true
+  > SELECT '%SystemDrive%/Users/John' _FUNC_ '/%SystemDrive/%//Users%' 
ESCAPE '/';
+  true
   """,
   note = """
 Use RLIKE to match with standard regular expressions.
   """,
   since = "1.0.0")
 // scalastyle:on line.contains.tab
-case class Like(left: Expression, right: Expression) extends 
StringRegexExpression {
+case class Like(left: Expression, right: Expression, escapeCharOpt: 
Option[Char] = None)
 
 Review comment:
   If user uses `SELECT ... LIKE ...`, I think toString display `SELECT ... 
LIKE ...` is better than `SELECT ... LIKE ... ESCAPE \`.


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:
us...@infra.apache.org


With regards,
Apache Git Services

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



[GitHub] [spark] beliefer commented on a change in pull request #25001: [SPARK-28083][SQL] Support LIKE ... ESCAPE syntax

2019-12-04 Thread GitBox
beliefer commented on a change in pull request #25001: [SPARK-28083][SQL] 
Support LIKE ... ESCAPE syntax
URL: https://github.com/apache/spark/pull/25001#discussion_r353616172
 
 

 ##
 File path: 
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/expressions/regexpExpressions.scala
 ##
 @@ -104,19 +103,24 @@ abstract class StringRegexExpression extends 
BinaryExpression
   spark.sql.parser.escapedStringLiterals   false
   > SELECT '%SystemDrive%\\Users\\John' _FUNC_ '\%SystemDrive\%Users%';
   true
+  > SELECT '%SystemDrive%/Users/John' _FUNC_ '/%SystemDrive/%//Users%' 
ESCAPE '/';
+  true
   """,
   note = """
 Use RLIKE to match with standard regular expressions.
   """,
   since = "1.0.0")
 // scalastyle:on line.contains.tab
-case class Like(left: Expression, right: Expression) extends 
StringRegexExpression {
+case class Like(left: Expression, right: Expression, escapeCharOpt: 
Option[Char] = None)
 
 Review comment:
   If user uses SELECT ... LIKE ..., I think toString display `SELECT ... LIKE 
...` is better than `SELECT ... LIKE ... ESCAPE \`.


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:
us...@infra.apache.org


With regards,
Apache Git Services

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



[GitHub] [spark] beliefer commented on a change in pull request #25001: [SPARK-28083][SQL] Support LIKE ... ESCAPE syntax

2019-12-04 Thread GitBox
beliefer commented on a change in pull request #25001: [SPARK-28083][SQL] 
Support LIKE ... ESCAPE syntax
URL: https://github.com/apache/spark/pull/25001#discussion_r353599336
 
 

 ##
 File path: 
sql/catalyst/src/main/antlr4/org/apache/spark/sql/catalyst/parser/SqlBase.g4
 ##
 @@ -1202,6 +1203,7 @@ nonReserved
 | DROP
 | ELSE
 | END
+| ESCAPE
 
 Review comment:
   OK. I restored it.


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:
us...@infra.apache.org


With regards,
Apache Git Services

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



[GitHub] [spark] beliefer commented on a change in pull request #25001: [SPARK-28083][SQL] Support LIKE ... ESCAPE syntax

2019-12-03 Thread GitBox
beliefer commented on a change in pull request #25001: [SPARK-28083][SQL] 
Support LIKE ... ESCAPE syntax
URL: https://github.com/apache/spark/pull/25001#discussion_r353575369
 
 

 ##
 File path: 
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/expressions/regexpExpressions.scala
 ##
 @@ -104,19 +103,24 @@ abstract class StringRegexExpression extends 
BinaryExpression
   spark.sql.parser.escapedStringLiterals   false
   > SELECT '%SystemDrive%\\Users\\John' _FUNC_ '\%SystemDrive\%Users%';
   true
+  > SELECT '%SystemDrive%/Users/John' _FUNC_ '/%SystemDrive/%//Users%' 
ESCAPE '/';
+  true
   """,
   note = """
 Use RLIKE to match with standard regular expressions.
   """,
   since = "1.0.0")
 // scalastyle:on line.contains.tab
-case class Like(left: Expression, right: Expression) extends 
StringRegexExpression {
+case class Like(left: Expression, right: Expression, escapeCharOpt: 
Option[Char] = None)
 
 Review comment:
   It's OK too.


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:
us...@infra.apache.org


With regards,
Apache Git Services

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



[GitHub] [spark] beliefer commented on a change in pull request #25001: [SPARK-28083][SQL] Support LIKE ... ESCAPE syntax

2019-12-03 Thread GitBox
beliefer commented on a change in pull request #25001: [SPARK-28083][SQL] 
Support LIKE ... ESCAPE syntax
URL: https://github.com/apache/spark/pull/25001#discussion_r353575345
 
 

 ##
 File path: 
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/expressions/regexpExpressions.scala
 ##
 @@ -83,16 +83,15 @@ abstract class StringRegexExpression extends 
BinaryExpression
   % matches zero or more characters in the input (similar to .* in 
posix regular
   expressions)
 
-  The escape character is '\'. If an escape character precedes a 
special symbol or another
-  escape character, the following character is matched literally. It 
is invalid to escape
-  any other character.
-
   Since Spark 2.0, string literals are unescaped in our SQL parser. 
For example, in order
   to match "\abc", the pattern should be "\\abc".
 
   When SQL config 'spark.sql.parser.escapedStringLiterals' is enabled, 
it fallbacks
   to Spark 1.6 behavior regarding string literal parsing. For example, 
if the config is
   enabled, the pattern to match "\abc" should be "\abc".
+  * escape - a optional string added since Spark 3.0. The default escape 
character is the '\'.
 
 Review comment:
   Thanks for you remind.


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:
us...@infra.apache.org


With regards,
Apache Git Services

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



[GitHub] [spark] beliefer commented on a change in pull request #25001: [SPARK-28083][SQL] Support LIKE ... ESCAPE syntax

2019-12-03 Thread GitBox
beliefer commented on a change in pull request #25001: [SPARK-28083][SQL] 
Support LIKE ... ESCAPE syntax
URL: https://github.com/apache/spark/pull/25001#discussion_r353575285
 
 

 ##
 File path: 
sql/catalyst/src/main/antlr4/org/apache/spark/sql/catalyst/parser/SqlBase.g4
 ##
 @@ -1202,6 +1203,7 @@ nonReserved
 | DROP
 | ELSE
 | END
+| ESCAPE
 
 Review comment:
   OK.


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:
us...@infra.apache.org


With regards,
Apache Git Services

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



[GitHub] [spark] beliefer commented on a change in pull request #25001: [SPARK-28083][SQL] Support LIKE ... ESCAPE syntax

2019-12-03 Thread GitBox
beliefer commented on a change in pull request #25001: [SPARK-28083][SQL] 
Support LIKE ... ESCAPE syntax
URL: https://github.com/apache/spark/pull/25001#discussion_r353535409
 
 

 ##
 File path: 
sql/catalyst/src/main/antlr4/org/apache/spark/sql/catalyst/parser/SqlBase.g4
 ##
 @@ -684,7 +684,8 @@ predicate
 : NOT? kind=BETWEEN lower=valueExpression AND upper=valueExpression
 | NOT? kind=IN '(' expression (',' expression)* ')'
 | NOT? kind=IN '(' query ')'
-| NOT? kind=(RLIKE | LIKE) pattern=valueExpression
+| NOT? kind=RLIKE pattern=valueExpression
+| NOT? kind=LIKE pattern=valueExpression (ESCAPE escapeChar=STRING)?
 
 Review comment:
   Yes.


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:
us...@infra.apache.org


With regards,
Apache Git Services

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



[GitHub] [spark] beliefer commented on a change in pull request #25001: [SPARK-28083][SQL] Support LIKE ... ESCAPE syntax

2019-10-24 Thread GitBox
beliefer commented on a change in pull request #25001: [SPARK-28083][SQL] 
Support LIKE ... ESCAPE syntax
URL: https://github.com/apache/spark/pull/25001#discussion_r338423500
 
 

 ##
 File path: 
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/expressions/regexpExpressions.scala
 ##
 @@ -149,10 +153,17 @@ case class Like(left: Expression, right: Expression) 
extends StringRegexExpressi
 } else {
   val pattern = ctx.freshName("pattern")
   val rightStr = ctx.freshName("rightStr")
+  val escapeChar = escapeCharOpt.map { str =>
+if (str.equals("\"") || str.equals("\\")) {
 
 Review comment:
   @HyukjinKwon @maropu I added the comments for explain the double escape.


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:
us...@infra.apache.org


With regards,
Apache Git Services

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



[GitHub] [spark] beliefer commented on a change in pull request #25001: [SPARK-28083][SQL] Support LIKE ... ESCAPE syntax

2019-08-23 Thread GitBox
beliefer commented on a change in pull request #25001: [SPARK-28083][SQL] 
Support LIKE ... ESCAPE syntax
URL: https://github.com/apache/spark/pull/25001#discussion_r316994509
 
 

 ##
 File path: sql/core/src/main/scala/org/apache/spark/sql/Column.scala
 ##
 @@ -822,6 +822,16 @@ class Column(val expr: Expression) extends Logging {
*/
   def like(literal: String): Column = withExpr { Like(expr, lit(literal).expr) 
}
 
+  /**
+   * SQL like expression. Returns a boolean column based on a SQL LIKE ESCAPE 
match.
+   *
+   * @group expr_ops
+   * @since 3.0.0
+   */
+  def like(literal: String, escapeStr: String): Column = withExpr {
+Like(expr, lit(literal).expr, Option(escapeStr))
+  }
+
 
 Review comment:
   OK.I will remove it.


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:
us...@infra.apache.org


With regards,
Apache Git Services

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



[GitHub] [spark] beliefer commented on a change in pull request #25001: [SPARK-28083][SQL] Support LIKE ... ESCAPE syntax

2019-08-22 Thread GitBox
beliefer commented on a change in pull request #25001: [SPARK-28083][SQL] 
Support LIKE ... ESCAPE syntax
URL: https://github.com/apache/spark/pull/25001#discussion_r316971787
 
 

 ##
 File path: 
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/expressions/regexpExpressions.scala
 ##
 @@ -83,33 +83,37 @@ abstract class StringRegexExpression extends 
BinaryExpression
   % matches zero or more characters in the input (similar to .* in 
posix regular
   expressions)
 
-  The escape character is '\'. If an escape character precedes a 
special symbol or another
-  escape character, the following character is matched literally. It 
is invalid to escape
-  any other character.
-
   Since Spark 2.0, string literals are unescaped in our SQL parser. 
For example, in order
   to match "\abc", the pattern should be "\\abc".
 
   When SQL config 'spark.sql.parser.escapedStringLiterals' is enabled, 
it fallbacks
   to Spark 1.6 behavior regarding string literal parsing. For example, 
if the config is
   enabled, the pattern to match "\abc" should be "\abc".
+  * escape - a optional string. The default escape character is the '\' . 
If an escape character
+  precedes a special symbol or another escape character, the following 
character is matched
+  literally. It is invalid to escape any other character.
 
 Review comment:
   Of course, I will add it.


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:
us...@infra.apache.org


With regards,
Apache Git Services

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



[GitHub] [spark] beliefer commented on a change in pull request #25001: [SPARK-28083][SQL] Support LIKE ... ESCAPE syntax

2019-08-02 Thread GitBox
beliefer commented on a change in pull request #25001: [SPARK-28083][SQL] 
Support LIKE ... ESCAPE syntax
URL: https://github.com/apache/spark/pull/25001#discussion_r30411
 
 

 ##
 File path: 
sql/catalyst/src/test/scala/org/apache/spark/sql/catalyst/util/StringUtilsSuite.scala
 ##
 @@ -23,13 +23,30 @@ import org.apache.spark.sql.catalyst.util.StringUtils._
 class StringUtilsSuite extends SparkFunSuite {
 
   test("escapeLikeRegex") {
-assert(escapeLikeRegex("abdef") === 
"(?s)\\Qa\\E\\Qb\\E\\Qd\\E\\Qe\\E\\Qf\\E")
-assert(escapeLikeRegex("a\\__b") === "(?s)\\Qa\\E\\Q_\\E.\\Qb\\E")
-assert(escapeLikeRegex("a_%b") === "(?s)\\Qa\\E..*\\Qb\\E")
-assert(escapeLikeRegex("a%\\%b") === "(?s)\\Qa\\E.*\\Q%\\E\\Qb\\E")
-assert(escapeLikeRegex("a%") === "(?s)\\Qa\\E.*")
-assert(escapeLikeRegex("**") === "(?s)\\Q*\\E\\Q*\\E")
-assert(escapeLikeRegex("a_b") === "(?s)\\Qa\\E.\\Qb\\E")
+val expectedEscapedStrArr = 
Array("(?s)\\Qa\\E\\Qb\\E\\Qd\\E\\Qe\\E\\Qf\\E",
 
 Review comment:
   OK. no problem


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:
us...@infra.apache.org


With regards,
Apache Git Services

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



[GitHub] [spark] beliefer commented on a change in pull request #25001: [SPARK-28083][SQL] Support LIKE ... ESCAPE syntax

2019-08-01 Thread GitBox
beliefer commented on a change in pull request #25001: [SPARK-28083][SQL] 
Support LIKE ... ESCAPE syntax
URL: https://github.com/apache/spark/pull/25001#discussion_r309976096
 
 

 ##
 File path: 
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/expressions/regexpExpressions.scala
 ##
 @@ -83,33 +83,39 @@ abstract class StringRegexExpression extends 
BinaryExpression
   % matches zero or more characters in the input (similar to .* in 
posix regular
   expressions)
 
-  The escape character is '\'. If an escape character precedes a 
special symbol or another
-  escape character, the following character is matched literally. It 
is invalid to escape
-  any other character.
-
   Since Spark 2.0, string literals are unescaped in our SQL parser. 
For example, in order
   to match "\abc", the pattern should be "\\abc".
 
   When SQL config 'spark.sql.parser.escapedStringLiterals' is enabled, 
it fallbacks
   to Spark 1.6 behavior regarding string literal parsing. For example, 
if the config is
   enabled, the pattern to match "\abc" should be "\abc".
+  * escape - a optional string. The default escape character is the '\' . 
If an escape character
+  precedes a special symbol or another escape character, the following 
character is matched
+  literally. It is invalid to escape any other character. You can 
specify '' as escape
+  character so that disables the escape mechanism, which makes it 
impossible to turn off
+  the special meaning of underscore and percent signs in the pattern.
 
 Review comment:
   > For now, can you fix code to throw an exception for the case?
   
   OK. we make a decision follow the ANSI behavior.


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:
us...@infra.apache.org


With regards,
Apache Git Services

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



[GitHub] [spark] beliefer commented on a change in pull request #25001: [SPARK-28083][SQL] Support LIKE ... ESCAPE syntax

2019-08-01 Thread GitBox
beliefer commented on a change in pull request #25001: [SPARK-28083][SQL] 
Support LIKE ... ESCAPE syntax
URL: https://github.com/apache/spark/pull/25001#discussion_r309965819
 
 

 ##
 File path: 
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/expressions/regexpExpressions.scala
 ##
 @@ -83,33 +83,39 @@ abstract class StringRegexExpression extends 
BinaryExpression
   % matches zero or more characters in the input (similar to .* in 
posix regular
   expressions)
 
-  The escape character is '\'. If an escape character precedes a 
special symbol or another
-  escape character, the following character is matched literally. It 
is invalid to escape
-  any other character.
-
   Since Spark 2.0, string literals are unescaped in our SQL parser. 
For example, in order
   to match "\abc", the pattern should be "\\abc".
 
   When SQL config 'spark.sql.parser.escapedStringLiterals' is enabled, 
it fallbacks
   to Spark 1.6 behavior regarding string literal parsing. For example, 
if the config is
   enabled, the pattern to match "\abc" should be "\abc".
+  * escape - a optional string. The default escape character is the '\' . 
If an escape character
+  precedes a special symbol or another escape character, the following 
character is matched
+  literally. It is invalid to escape any other character. You can 
specify '' as escape
+  character so that disables the escape mechanism, which makes it 
impossible to turn off
+  the special meaning of underscore and percent signs in the pattern.
 
 Review comment:
   @maropu Shall we continue to wait other review's comment?


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:
us...@infra.apache.org


With regards,
Apache Git Services

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



[GitHub] [spark] beliefer commented on a change in pull request #25001: [SPARK-28083][SQL] Support LIKE ... ESCAPE syntax

2019-07-31 Thread GitBox
beliefer commented on a change in pull request #25001: [SPARK-28083][SQL] 
Support LIKE ... ESCAPE syntax
URL: https://github.com/apache/spark/pull/25001#discussion_r309072805
 
 

 ##
 File path: 
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/expressions/regexpExpressions.scala
 ##
 @@ -83,33 +83,39 @@ abstract class StringRegexExpression extends 
BinaryExpression
   % matches zero or more characters in the input (similar to .* in 
posix regular
   expressions)
 
-  The escape character is '\'. If an escape character precedes a 
special symbol or another
-  escape character, the following character is matched literally. It 
is invalid to escape
-  any other character.
-
   Since Spark 2.0, string literals are unescaped in our SQL parser. 
For example, in order
   to match "\abc", the pattern should be "\\abc".
 
   When SQL config 'spark.sql.parser.escapedStringLiterals' is enabled, 
it fallbacks
   to Spark 1.6 behavior regarding string literal parsing. For example, 
if the config is
   enabled, the pattern to match "\abc" should be "\abc".
+  * escape - a optional string. The default escape character is the '\' . 
If an escape character
+  precedes a special symbol or another escape character, the following 
character is matched
+  literally. It is invalid to escape any other character. You can 
specify '' as escape
+  character so that disables the escape mechanism, which makes it 
impossible to turn off
+  the special meaning of underscore and percent signs in the pattern.
 
 Review comment:
   @dongjoon-hyun @gatorsmile Could you take a look at this discussion @maropu 
made a suggestion.


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:
us...@infra.apache.org


With regards,
Apache Git Services

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



[GitHub] [spark] beliefer commented on a change in pull request #25001: [SPARK-28083][SQL] Support LIKE ... ESCAPE syntax

2019-07-29 Thread GitBox
beliefer commented on a change in pull request #25001: [SPARK-28083][SQL] 
Support LIKE ... ESCAPE syntax
URL: https://github.com/apache/spark/pull/25001#discussion_r308523594
 
 

 ##
 File path: 
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/expressions/regexpExpressions.scala
 ##
 @@ -83,33 +83,39 @@ abstract class StringRegexExpression extends 
BinaryExpression
   % matches zero or more characters in the input (similar to .* in 
posix regular
   expressions)
 
-  The escape character is '\'. If an escape character precedes a 
special symbol or another
-  escape character, the following character is matched literally. It 
is invalid to escape
-  any other character.
-
   Since Spark 2.0, string literals are unescaped in our SQL parser. 
For example, in order
   to match "\abc", the pattern should be "\\abc".
 
   When SQL config 'spark.sql.parser.escapedStringLiterals' is enabled, 
it fallbacks
   to Spark 1.6 behavior regarding string literal parsing. For example, 
if the config is
   enabled, the pattern to match "\abc" should be "\abc".
+  * escape - a optional string. The default escape character is the '\' . 
If an escape character
+  precedes a special symbol or another escape character, the following 
character is matched
+  literally. It is invalid to escape any other character. You can 
specify '' as escape
+  character so that disables the escape mechanism, which makes it 
impossible to turn off
+  the special meaning of underscore and percent signs in the pattern.
 
 Review comment:
   > If we follow `1)`, we should throw an exception for the empty case?
   
   Yes. Should we follow which behavior? Oracle is follow the behavior of ANSI, 
PostGresql will disables the escape with '', MySQL will ignore the '' and use 
default escape char.


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:
us...@infra.apache.org


With regards,
Apache Git Services

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



[GitHub] [spark] beliefer commented on a change in pull request #25001: [SPARK-28083][SQL] Support LIKE ... ESCAPE syntax

2019-07-29 Thread GitBox
beliefer commented on a change in pull request #25001: [SPARK-28083][SQL] 
Support LIKE ... ESCAPE syntax
URL: https://github.com/apache/spark/pull/25001#discussion_r308084147
 
 

 ##
 File path: 
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/expressions/regexpExpressions.scala
 ##
 @@ -83,33 +83,39 @@ abstract class StringRegexExpression extends 
BinaryExpression
   % matches zero or more characters in the input (similar to .* in 
posix regular
   expressions)
 
-  The escape character is '\'. If an escape character precedes a 
special symbol or another
-  escape character, the following character is matched literally. It 
is invalid to escape
-  any other character.
-
   Since Spark 2.0, string literals are unescaped in our SQL parser. 
For example, in order
   to match "\abc", the pattern should be "\\abc".
 
   When SQL config 'spark.sql.parser.escapedStringLiterals' is enabled, 
it fallbacks
   to Spark 1.6 behavior regarding string literal parsing. For example, 
if the config is
   enabled, the pattern to match "\abc" should be "\abc".
+  * escape - a optional string. The default escape character is the '\' . 
If an escape character
+  precedes a special symbol or another escape character, the following 
character is matched
+  literally. It is invalid to escape any other character. You can 
specify '' as escape
+  character so that disables the escape mechanism, which makes it 
impossible to turn off
+  the special meaning of underscore and percent signs in the pattern.
 
 Review comment:
   ```
   SELECT 'a_%b' LIKE 'a\__b', 'a_%b' LIKE 'a\__b' ESCAPE '', 'addb' LIKE 
'a_%b', 'addb' LIKE 'a_%b' ESCAPE '';
   
   //PostGresql result is:
   tf   t   t
   // MySQL result is:
   1 1   1  1
   ```
   I execute SQL in Oracle:
   ```
   SELECT * FROM DUAL WHERE DUMMY LIKE 'a\__b' ESCAPE ''
   报错:> ORA-01425: escape character must be character string of length 1
   ```


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:
us...@infra.apache.org


With regards,
Apache Git Services

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



[GitHub] [spark] beliefer commented on a change in pull request #25001: [SPARK-28083][SQL] Support LIKE ... ESCAPE syntax

2019-07-29 Thread GitBox
beliefer commented on a change in pull request #25001: [SPARK-28083][SQL] 
Support LIKE ... ESCAPE syntax
URL: https://github.com/apache/spark/pull/25001#discussion_r308523594
 
 

 ##
 File path: 
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/expressions/regexpExpressions.scala
 ##
 @@ -83,33 +83,39 @@ abstract class StringRegexExpression extends 
BinaryExpression
   % matches zero or more characters in the input (similar to .* in 
posix regular
   expressions)
 
-  The escape character is '\'. If an escape character precedes a 
special symbol or another
-  escape character, the following character is matched literally. It 
is invalid to escape
-  any other character.
-
   Since Spark 2.0, string literals are unescaped in our SQL parser. 
For example, in order
   to match "\abc", the pattern should be "\\abc".
 
   When SQL config 'spark.sql.parser.escapedStringLiterals' is enabled, 
it fallbacks
   to Spark 1.6 behavior regarding string literal parsing. For example, 
if the config is
   enabled, the pattern to match "\abc" should be "\abc".
+  * escape - a optional string. The default escape character is the '\' . 
If an escape character
+  precedes a special symbol or another escape character, the following 
character is matched
+  literally. It is invalid to escape any other character. You can 
specify '' as escape
+  character so that disables the escape mechanism, which makes it 
impossible to turn off
+  the special meaning of underscore and percent signs in the pattern.
 
 Review comment:
   > If we follow `1)`, we should throw an exception for the empty case?
   
   Yes. Should we follow which behavior?


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:
us...@infra.apache.org


With regards,
Apache Git Services

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



[GitHub] [spark] beliefer commented on a change in pull request #25001: [SPARK-28083][SQL] Support LIKE ... ESCAPE syntax

2019-07-29 Thread GitBox
beliefer commented on a change in pull request #25001: [SPARK-28083][SQL] 
Support LIKE ... ESCAPE syntax
URL: https://github.com/apache/spark/pull/25001#discussion_r308520964
 
 

 ##
 File path: 
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/expressions/regexpExpressions.scala
 ##
 @@ -83,33 +83,39 @@ abstract class StringRegexExpression extends 
BinaryExpression
   % matches zero or more characters in the input (similar to .* in 
posix regular
   expressions)
 
-  The escape character is '\'. If an escape character precedes a 
special symbol or another
-  escape character, the following character is matched literally. It 
is invalid to escape
-  any other character.
-
   Since Spark 2.0, string literals are unescaped in our SQL parser. 
For example, in order
   to match "\abc", the pattern should be "\\abc".
 
   When SQL config 'spark.sql.parser.escapedStringLiterals' is enabled, 
it fallbacks
   to Spark 1.6 behavior regarding string literal parsing. For example, 
if the config is
   enabled, the pattern to match "\abc" should be "\abc".
+  * escape - a optional string. The default escape character is the '\' . 
If an escape character
+  precedes a special symbol or another escape character, the following 
character is matched
+  literally. It is invalid to escape any other character. You can 
specify '' as escape
+  character so that disables the escape mechanism, which makes it 
impossible to turn off
+  the special meaning of underscore and percent signs in the pattern.
 
 Review comment:
   ANSI description is:
   ```
::=

::=
   [ NOT ] LIKE  [ ESCAPE  ]
::=
   
::=
   
   ```
   There are also a lot note: 
   ```
   If an  is specified, then:
   1) If the length in characters of ECV is not equal to 1, then an exception 
condition is raised:
   data exception — invalid escape character.
   ```


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:
us...@infra.apache.org


With regards,
Apache Git Services

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



[GitHub] [spark] beliefer commented on a change in pull request #25001: [SPARK-28083][SQL] Support LIKE ... ESCAPE syntax

2019-07-29 Thread GitBox
beliefer commented on a change in pull request #25001: [SPARK-28083][SQL] 
Support LIKE ... ESCAPE syntax
URL: https://github.com/apache/spark/pull/25001#discussion_r308520964
 
 

 ##
 File path: 
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/expressions/regexpExpressions.scala
 ##
 @@ -83,33 +83,39 @@ abstract class StringRegexExpression extends 
BinaryExpression
   % matches zero or more characters in the input (similar to .* in 
posix regular
   expressions)
 
-  The escape character is '\'. If an escape character precedes a 
special symbol or another
-  escape character, the following character is matched literally. It 
is invalid to escape
-  any other character.
-
   Since Spark 2.0, string literals are unescaped in our SQL parser. 
For example, in order
   to match "\abc", the pattern should be "\\abc".
 
   When SQL config 'spark.sql.parser.escapedStringLiterals' is enabled, 
it fallbacks
   to Spark 1.6 behavior regarding string literal parsing. For example, 
if the config is
   enabled, the pattern to match "\abc" should be "\abc".
+  * escape - a optional string. The default escape character is the '\' . 
If an escape character
+  precedes a special symbol or another escape character, the following 
character is matched
+  literally. It is invalid to escape any other character. You can 
specify '' as escape
+  character so that disables the escape mechanism, which makes it 
impossible to turn off
+  the special meaning of underscore and percent signs in the pattern.
 
 Review comment:
   ANSI description is:
   ```
::=

::=
   [ NOT ] LIKE  [ ESCAPE  ]
::=
   
::=
   
   ```
   There are also a lot note: ```
   If an  is specified, then:
   1) If the length in characters of ECV is not equal to 1, then an exception 
condition is raised:
   data exception — invalid escape character.
   ```


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:
us...@infra.apache.org


With regards,
Apache Git Services

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



[GitHub] [spark] beliefer commented on a change in pull request #25001: [SPARK-28083][SQL] Support LIKE ... ESCAPE syntax

2019-07-29 Thread GitBox
beliefer commented on a change in pull request #25001: [SPARK-28083][SQL] 
Support LIKE ... ESCAPE syntax
URL: https://github.com/apache/spark/pull/25001#discussion_r308100510
 
 

 ##
 File path: 
sql/catalyst/src/test/scala/org/apache/spark/sql/catalyst/parser/ExpressionParserSuite.scala
 ##
 @@ -175,7 +175,13 @@ class ExpressionParserSuite extends AnalysisTest {
 
   test("like expressions") {
 assertEqual("a like 'pattern%'", 'a like "pattern%")
+assertEqual("a like 'pattern%' escape '#'", 'a.like("pattern%", "#"))
+assertEqual("a like 'pattern%' escape '\"'", 'a.like("pattern%", "\""))
+intercept("a like 'pattern%' escape '##'", "Escape string must be empty or 
one character.")
 assertEqual("a not like 'pattern%'", !('a like "pattern%"))
+assertEqual("a not like 'pattern%' escape '#'", !('a.like("pattern%", 
"#")))
+assertEqual("a not like 'pattern%' escape '\"'", !('a.like("pattern%", 
"\"")))
+intercept("a not like 'pattern%' escape '\"/'", "Escape string must be 
empty or one character.")
 assertEqual("a rlike 'pattern%'", 'a rlike "pattern%")
 
 Review comment:
   OK. I will create new test unit.


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:
us...@infra.apache.org


With regards,
Apache Git Services

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



[GitHub] [spark] beliefer commented on a change in pull request #25001: [SPARK-28083][SQL] Support LIKE ... ESCAPE syntax

2019-07-29 Thread GitBox
beliefer commented on a change in pull request #25001: [SPARK-28083][SQL] 
Support LIKE ... ESCAPE syntax
URL: https://github.com/apache/spark/pull/25001#discussion_r308088825
 
 

 ##
 File path: 
sql/catalyst/src/test/scala/org/apache/spark/sql/catalyst/expressions/RegexpExpressionsSuite.scala
 ##
 @@ -118,6 +118,295 @@ class RegexpExpressionsSuite extends SparkFunSuite with 
ExpressionEvalHelper {
 checkLiteralRow("""%SystemDrive%\Users\John""" like _, 
"""\%SystemDrive\%\\Users%""", true)
   }
 
+  test("LIKE Pattern ESCAPE '/'") {
+
 
 Review comment:
   OK. Thanks for your reminder. It is more simpler.


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:
us...@infra.apache.org


With regards,
Apache Git Services

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



[GitHub] [spark] beliefer commented on a change in pull request #25001: [SPARK-28083][SQL] Support LIKE ... ESCAPE syntax

2019-07-29 Thread GitBox
beliefer commented on a change in pull request #25001: [SPARK-28083][SQL] 
Support LIKE ... ESCAPE syntax
URL: https://github.com/apache/spark/pull/25001#discussion_r308080428
 
 

 ##
 File path: 
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/expressions/regexpExpressions.scala
 ##
 @@ -83,33 +83,39 @@ abstract class StringRegexExpression extends 
BinaryExpression
   % matches zero or more characters in the input (similar to .* in 
posix regular
   expressions)
 
-  The escape character is '\'. If an escape character precedes a 
special symbol or another
-  escape character, the following character is matched literally. It 
is invalid to escape
-  any other character.
-
   Since Spark 2.0, string literals are unescaped in our SQL parser. 
For example, in order
   to match "\abc", the pattern should be "\\abc".
 
   When SQL config 'spark.sql.parser.escapedStringLiterals' is enabled, 
it fallbacks
   to Spark 1.6 behavior regarding string literal parsing. For example, 
if the config is
   enabled, the pattern to match "\abc" should be "\abc".
+  * escape - a optional string. The default escape character is the '\' . 
If an escape character
+  precedes a special symbol or another escape character, the following 
character is matched
+  literally. It is invalid to escape any other character. You can 
specify '' as escape
+  character so that disables the escape mechanism, which makes it 
impossible to turn off
+  the special meaning of underscore and percent signs in the pattern.
 
 Review comment:
   The docs https://www.postgresql.org/docs/11/functions-matching.html exists 
the description contains the content `It's also possible to select no escape 
character by writing ESCAPE ''. This effectively disables the escape mechanism`.


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:
us...@infra.apache.org


With regards,
Apache Git Services

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



[GitHub] [spark] beliefer commented on a change in pull request #25001: [SPARK-28083][SQL] Support LIKE ... ESCAPE syntax

2019-07-29 Thread GitBox
beliefer commented on a change in pull request #25001: [SPARK-28083][SQL] 
Support LIKE ... ESCAPE syntax
URL: https://github.com/apache/spark/pull/25001#discussion_r308084147
 
 

 ##
 File path: 
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/expressions/regexpExpressions.scala
 ##
 @@ -83,33 +83,39 @@ abstract class StringRegexExpression extends 
BinaryExpression
   % matches zero or more characters in the input (similar to .* in 
posix regular
   expressions)
 
-  The escape character is '\'. If an escape character precedes a 
special symbol or another
-  escape character, the following character is matched literally. It 
is invalid to escape
-  any other character.
-
   Since Spark 2.0, string literals are unescaped in our SQL parser. 
For example, in order
   to match "\abc", the pattern should be "\\abc".
 
   When SQL config 'spark.sql.parser.escapedStringLiterals' is enabled, 
it fallbacks
   to Spark 1.6 behavior regarding string literal parsing. For example, 
if the config is
   enabled, the pattern to match "\abc" should be "\abc".
+  * escape - a optional string. The default escape character is the '\' . 
If an escape character
+  precedes a special symbol or another escape character, the following 
character is matched
+  literally. It is invalid to escape any other character. You can 
specify '' as escape
+  character so that disables the escape mechanism, which makes it 
impossible to turn off
+  the special meaning of underscore and percent signs in the pattern.
 
 Review comment:
   ```
   SELECT 'a_%b' LIKE 'a\__b', 'a_%b' LIKE 'a\__b' ESCAPE '', 'addb' LIKE 
'a_%b', 'addb' LIKE 'a_%b' ESCAPE '';
   
   //PostGresql result is:
   tf   t   t
   // MySQL result is:
   1 1   1  1
   ```


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:
us...@infra.apache.org


With regards,
Apache Git Services

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



[GitHub] [spark] beliefer commented on a change in pull request #25001: [SPARK-28083][SQL] Support LIKE ... ESCAPE syntax

2019-07-29 Thread GitBox
beliefer commented on a change in pull request #25001: [SPARK-28083][SQL] 
Support LIKE ... ESCAPE syntax
URL: https://github.com/apache/spark/pull/25001#discussion_r308080428
 
 

 ##
 File path: 
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/expressions/regexpExpressions.scala
 ##
 @@ -83,33 +83,39 @@ abstract class StringRegexExpression extends 
BinaryExpression
   % matches zero or more characters in the input (similar to .* in 
posix regular
   expressions)
 
-  The escape character is '\'. If an escape character precedes a 
special symbol or another
-  escape character, the following character is matched literally. It 
is invalid to escape
-  any other character.
-
   Since Spark 2.0, string literals are unescaped in our SQL parser. 
For example, in order
   to match "\abc", the pattern should be "\\abc".
 
   When SQL config 'spark.sql.parser.escapedStringLiterals' is enabled, 
it fallbacks
   to Spark 1.6 behavior regarding string literal parsing. For example, 
if the config is
   enabled, the pattern to match "\abc" should be "\abc".
+  * escape - a optional string. The default escape character is the '\' . 
If an escape character
+  precedes a special symbol or another escape character, the following 
character is matched
+  literally. It is invalid to escape any other character. You can 
specify '' as escape
+  character so that disables the escape mechanism, which makes it 
impossible to turn off
+  the special meaning of underscore and percent signs in the pattern.
 
 Review comment:
   The docs https://www.postgresql.org/docs/11/functions-matching.html exists 
the description contains the content `It's also possible to select no escape 
character by writing ESCAPE ''. This effectively disables the escape mechanism`.
   ```
   SELECT 'a_%b' LIKE 'a\__b', 'a_%b' LIKE 'a\__b' ESCAPE '', 'addb' LIKE 
'a_%b', 'addb' LIKE 'a_%b' ESCAPE '';
   
   // result is:
   tf   t   t
   ```


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:
us...@infra.apache.org


With regards,
Apache Git Services

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



[GitHub] [spark] beliefer commented on a change in pull request #25001: [SPARK-28083][SQL] Support LIKE ... ESCAPE syntax

2019-07-29 Thread GitBox
beliefer commented on a change in pull request #25001: [SPARK-28083][SQL] 
Support LIKE ... ESCAPE syntax
URL: https://github.com/apache/spark/pull/25001#discussion_r308080428
 
 

 ##
 File path: 
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/expressions/regexpExpressions.scala
 ##
 @@ -83,33 +83,39 @@ abstract class StringRegexExpression extends 
BinaryExpression
   % matches zero or more characters in the input (similar to .* in 
posix regular
   expressions)
 
-  The escape character is '\'. If an escape character precedes a 
special symbol or another
-  escape character, the following character is matched literally. It 
is invalid to escape
-  any other character.
-
   Since Spark 2.0, string literals are unescaped in our SQL parser. 
For example, in order
   to match "\abc", the pattern should be "\\abc".
 
   When SQL config 'spark.sql.parser.escapedStringLiterals' is enabled, 
it fallbacks
   to Spark 1.6 behavior regarding string literal parsing. For example, 
if the config is
   enabled, the pattern to match "\abc" should be "\abc".
+  * escape - a optional string. The default escape character is the '\' . 
If an escape character
+  precedes a special symbol or another escape character, the following 
character is matched
+  literally. It is invalid to escape any other character. You can 
specify '' as escape
+  character so that disables the escape mechanism, which makes it 
impossible to turn off
+  the special meaning of underscore and percent signs in the pattern.
 
 Review comment:
   The docs https://www.postgresql.org/docs/11/functions-matching.html exists 
the description contains the content `It's also possible to select no escape 
character by writing ESCAPE ''. This effectively disables the escape mechanism`.
   ```
   SELECT 'a_%b' LIKE 'a\\__b' ESCAPE '', 'addb' LIKE 'a_%b' ESCAPE '', 'addb' 
LIKE 'a\\__b' ESCAPE '', 'addb' LIKE 'a%\\%b' ESCAPE '', 
  'a_%b' LIKE 'a%\\%b' ESCAPE '', 'addb' LIKE 'a%' ESCAPE '', 'addb' 
LIKE '**' ESCAPE '', 'abc' LIKE 'a%' ESCAPE '',
  'abc' LIKE 'b%' ESCAPE '', 'abc' LIKE 'bc%' ESCAPE '', 'a\nb' LIKE 
'a_b' ESCAPE '', 'ab' LIKE 'a%b' ESCAPE '',
  'a\nb' LIKE 'a%b' ESCAPE '';
   
   // result is:
   ft   f   f   f   t   f   t   f   f   
f   t   t
   ```


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:
us...@infra.apache.org


With regards,
Apache Git Services

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



[GitHub] [spark] beliefer commented on a change in pull request #25001: [SPARK-28083][SQL] Support LIKE ... ESCAPE syntax

2019-07-28 Thread GitBox
beliefer commented on a change in pull request #25001: [SPARK-28083][SQL] 
Support LIKE ... ESCAPE syntax
URL: https://github.com/apache/spark/pull/25001#discussion_r308057469
 
 

 ##
 File path: 
sql/catalyst/src/test/scala/org/apache/spark/sql/catalyst/util/StringUtilsSuite.scala
 ##
 @@ -23,13 +23,27 @@ import org.apache.spark.sql.catalyst.util.StringUtils._
 class StringUtilsSuite extends SparkFunSuite {
 
   test("escapeLikeRegex") {
-assert(escapeLikeRegex("abdef") === 
"(?s)\\Qa\\E\\Qb\\E\\Qd\\E\\Qe\\E\\Qf\\E")
-assert(escapeLikeRegex("a\\__b") === "(?s)\\Qa\\E\\Q_\\E.\\Qb\\E")
-assert(escapeLikeRegex("a_%b") === "(?s)\\Qa\\E..*\\Qb\\E")
-assert(escapeLikeRegex("a%\\%b") === "(?s)\\Qa\\E.*\\Q%\\E\\Qb\\E")
-assert(escapeLikeRegex("a%") === "(?s)\\Qa\\E.*")
-assert(escapeLikeRegex("**") === "(?s)\\Q*\\E\\Q*\\E")
-assert(escapeLikeRegex("a_b") === "(?s)\\Qa\\E.\\Qb\\E")
+assert(escapeLikeRegex("abdef", "\\") === 
"(?s)\\Qa\\E\\Qb\\E\\Qd\\E\\Qe\\E\\Qf\\E")
+assert(escapeLikeRegex("abdef", "/") === 
"(?s)\\Qa\\E\\Qb\\E\\Qd\\E\\Qe\\E\\Qf\\E")
+assert(escapeLikeRegex("abdef", "\"") === 
"(?s)\\Qa\\E\\Qb\\E\\Qd\\E\\Qe\\E\\Qf\\E")
+assert(escapeLikeRegex("a\\__b", "\\") === "(?s)\\Qa\\E\\Q_\\E.\\Qb\\E")
+assert(escapeLikeRegex("a/__b", "/") === "(?s)\\Qa\\E\\Q_\\E.\\Qb\\E")
+assert(escapeLikeRegex("a\"__b", "\"") === "(?s)\\Qa\\E\\Q_\\E.\\Qb\\E")
 
 Review comment:
   OK. good suggestion.


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:
us...@infra.apache.org


With regards,
Apache Git Services

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



[GitHub] [spark] beliefer commented on a change in pull request #25001: [SPARK-28083][SQL] Support LIKE ... ESCAPE syntax

2019-07-28 Thread GitBox
beliefer commented on a change in pull request #25001: [SPARK-28083][SQL] 
Support LIKE ... ESCAPE syntax
URL: https://github.com/apache/spark/pull/25001#discussion_r308057191
 
 

 ##
 File path: 
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/expressions/regexpExpressions.scala
 ##
 @@ -83,33 +83,39 @@ abstract class StringRegexExpression extends 
BinaryExpression
   % matches zero or more characters in the input (similar to .* in 
posix regular
   expressions)
 
-  The escape character is '\'. If an escape character precedes a 
special symbol or another
-  escape character, the following character is matched literally. It 
is invalid to escape
-  any other character.
-
   Since Spark 2.0, string literals are unescaped in our SQL parser. 
For example, in order
   to match "\abc", the pattern should be "\\abc".
 
   When SQL config 'spark.sql.parser.escapedStringLiterals' is enabled, 
it fallbacks
   to Spark 1.6 behavior regarding string literal parsing. For example, 
if the config is
   enabled, the pattern to match "\abc" should be "\abc".
+  * escape - a optional string. The default escape character is the '\' . 
If an escape character
+  precedes a special symbol or another escape character, the following 
character is matched
+  literally. It is invalid to escape any other character. You can 
specify '' as escape
+  character so that disables the escape mechanism, which makes it 
impossible to turn off
+  the special meaning of underscore and percent signs in the pattern.
 
 Review comment:
   The behavior references the `PostgreSQL` only. 
   `MySQL`, `Oracle`, `Vertica` and `PostgreSQL` haven't unify behavior.
   The corner tests have added in `RegexpExpressionsSuite`.


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:
us...@infra.apache.org


With regards,
Apache Git Services

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



[GitHub] [spark] beliefer commented on a change in pull request #25001: [SPARK-28083][SQL] Support LIKE ... ESCAPE syntax

2019-07-28 Thread GitBox
beliefer commented on a change in pull request #25001: [SPARK-28083][SQL] 
Support LIKE ... ESCAPE syntax
URL: https://github.com/apache/spark/pull/25001#discussion_r308057191
 
 

 ##
 File path: 
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/expressions/regexpExpressions.scala
 ##
 @@ -83,33 +83,39 @@ abstract class StringRegexExpression extends 
BinaryExpression
   % matches zero or more characters in the input (similar to .* in 
posix regular
   expressions)
 
-  The escape character is '\'. If an escape character precedes a 
special symbol or another
-  escape character, the following character is matched literally. It 
is invalid to escape
-  any other character.
-
   Since Spark 2.0, string literals are unescaped in our SQL parser. 
For example, in order
   to match "\abc", the pattern should be "\\abc".
 
   When SQL config 'spark.sql.parser.escapedStringLiterals' is enabled, 
it fallbacks
   to Spark 1.6 behavior regarding string literal parsing. For example, 
if the config is
   enabled, the pattern to match "\abc" should be "\abc".
+  * escape - a optional string. The default escape character is the '\' . 
If an escape character
+  precedes a special symbol or another escape character, the following 
character is matched
+  literally. It is invalid to escape any other character. You can 
specify '' as escape
+  character so that disables the escape mechanism, which makes it 
impossible to turn off
+  the special meaning of underscore and percent signs in the pattern.
 
 Review comment:
   The behavior references the `PostgreSQL` only. 
   `MySQL`, `Oracle`, `Vertica` and `PostgreSQL` haven't unify behavior.


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:
us...@infra.apache.org


With regards,
Apache Git Services

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



[GitHub] [spark] beliefer commented on a change in pull request #25001: [SPARK-28083][SQL] Support LIKE ... ESCAPE syntax

2019-07-28 Thread GitBox
beliefer commented on a change in pull request #25001: [SPARK-28083][SQL] 
Support LIKE ... ESCAPE syntax
URL: https://github.com/apache/spark/pull/25001#discussion_r308055588
 
 

 ##
 File path: 
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/dsl/package.scala
 ##
 @@ -97,7 +97,9 @@ package object dsl {
   case _ => In(expr, list)
 }
 
-def like(other: Expression): Expression = Like(expr, other)
+def like(other: Expression): Expression = Like(expr, other, None)
+def like(other: Expression, escapeChar: String): Expression =
+  Like(expr, other, Some(escapeChar))
 
 Review comment:
   OK. A good suggestion.


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:
us...@infra.apache.org


With regards,
Apache Git Services

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



[GitHub] [spark] beliefer commented on a change in pull request #25001: [SPARK-28083][SQL] Support LIKE ... ESCAPE syntax

2019-07-28 Thread GitBox
beliefer commented on a change in pull request #25001: [SPARK-28083][SQL] 
Support LIKE ... ESCAPE syntax
URL: https://github.com/apache/spark/pull/25001#discussion_r308053414
 
 

 ##
 File path: 
sql/catalyst/src/test/scala/org/apache/spark/sql/catalyst/expressions/RegexpExpressionsSuite.scala
 ##
 @@ -118,6 +118,295 @@ class RegexpExpressionsSuite extends SparkFunSuite with 
ExpressionEvalHelper {
 checkLiteralRow("""%SystemDrive%\Users\John""" like _, 
"""\%SystemDrive\%\\Users%""", true)
   }
 
+  test("LIKE Pattern ESCAPE '/'") {
+
+// null handling
+checkLiteralRow(Literal.create(null, StringType).like(_, "/"), "a", null)
+checkEvaluation(
+  Literal.create("a", StringType).like(Literal.create(null, StringType), 
"/"), null)
+checkEvaluation(
+  Literal.create(null, StringType).like(Literal.create(null, StringType), 
"/"), null)
+checkEvaluation(
+  Literal.create("a", StringType).like(NonFoldableLiteral.create("a", 
StringType), "/"), true)
+checkEvaluation(
+  Literal.create("a", StringType).like(NonFoldableLiteral.create(null, 
StringType), "/"), null)
+checkEvaluation(
+  Literal.create(null, StringType).like(NonFoldableLiteral.create("a", 
StringType), "/"), null)
+checkEvaluation(
+  Literal.create(null, StringType).like(NonFoldableLiteral.create(null, 
StringType), "/"), null)
+
+// simple patterns
+checkLiteralRow("abdef" like(_, "/"), "abdef", true)
+checkLiteralRow("a_%b" like(_, "/"), "a/__b", true)
+checkLiteralRow("addb" like(_, "/"), "a_%b", true)
+checkLiteralRow("addb" like(_, "/"), "a/__b", false)
+checkLiteralRow("addb" like(_, "/"), "a%/%b", false)
+checkLiteralRow("a_%b" like(_, "/"), "a%/%b", true)
+checkLiteralRow("addb" like(_, "/"), "a%", true)
+checkLiteralRow("addb" like(_, "/"), "**", false)
+checkLiteralRow("abc" like(_, "/"), "a%", true)
+checkLiteralRow("abc"  like(_, "/"), "b%", false)
+checkLiteralRow("abc"  like(_, "/"), "bc%", false)
+checkLiteralRow("a\nb" like(_, "/"), "a_b", true)
+checkLiteralRow("ab" like(_, "/"), "a%b", true)
+checkLiteralRow("a\nb" like(_, "/"), "a%b", true)
+
+// empty input
+checkLiteralRow("" like(_, "/"), "", true)
+checkLiteralRow("a" like(_, "/"), "", false)
+checkLiteralRow("" like(_, "/"), "a", false)
+
+// SI-17647 double-escaping backslash
+checkLiteralRow("""""" like(_, "/"), """%//%""", true)
+checkLiteralRow("""%%""" like(_, "/"), """%%""", true)
+checkLiteralRow("""/__""" like(_, "/"), """///__""", true)
+checkLiteralRow("""///__""" like(_, "/"), """%//%/%""", false)
+checkLiteralRow("""_///%""" like(_, "/"), """%//""", false)
+
+// unicode
+// scalastyle:off nonascii
+checkLiteralRow("a\u20ACa" like(_, "/"), "_\u20AC_", true)
+checkLiteralRow("a€a" like(_, "/"), "_€_", true)
+checkLiteralRow("a€a" like(_, "/"), "_\u20AC_", true)
+checkLiteralRow("a\u20ACa" like(_, "/"), "_€_", true)
+// scalastyle:on nonascii
+
+// invalid escaping
+val invalidEscape = intercept[AnalysisException] {
+  evaluateWithoutCodegen("""a""" like("""/a""", "/"))
+}
+assert(invalidEscape.getMessage.contains("pattern"))
+
+val endEscape = intercept[AnalysisException] {
+  evaluateWithoutCodegen("""a""" like("""a/""", "/"))
+}
+assert(endEscape.getMessage.contains("pattern"))
+
+// case
+checkLiteralRow("A" like(_, "/"), "a%", false)
+checkLiteralRow("a" like(_, "/"), "A%", false)
+checkLiteralRow("AaA" like(_, "/"), "_a_", true)
+
+// example
+checkLiteralRow(
+  """%SystemDrive%/Users/John""" like(_, "/"), 
"""/%SystemDrive/%//Users%""", true)
+  }
+
+  test("LIKE Pattern ESCAPE '#'") {
+
+// null handling
+checkLiteralRow(Literal.create(null, StringType).like(_, "#"), "a", null)
+checkEvaluation(
+  Literal.create("a", StringType).like(Literal.create(null, StringType), 
"#"), null)
+checkEvaluation(
+  Literal.create(null, StringType).like(Literal.create(null, StringType), 
"#"), null)
+checkEvaluation(
+  Literal.create("a", StringType).like(NonFoldableLiteral.create("a", 
StringType), "#"), true)
+checkEvaluation(
+  Literal.create("a", StringType).like(NonFoldableLiteral.create(null, 
StringType), "#"), null)
+checkEvaluation(
+  Literal.create(null, StringType).like(NonFoldableLiteral.create("a", 
StringType), "#"), null)
+checkEvaluation(
+  Literal.create(null, StringType).like(NonFoldableLiteral.create(null, 
StringType), "#"), null)
+
+// simple patterns
+checkLiteralRow("abdef" like(_, "#"), "abdef", true)
+checkLiteralRow("a_%b" like(_, "#"), "a#__b", true)
+checkLiteralRow("addb" like(_, "#"), "a_%b", true)
+checkLiteralRow("addb" like(_, "#"), "a#__b", false)
+checkLiteralRow("addb" like(_, "#"), "a%#%b", false)
+checkLiteralRow("a_%b" like(_, "#"), "a%#%b", true)
+checkLiteralRow("addb" 

[GitHub] [spark] beliefer commented on a change in pull request #25001: [SPARK-28083][SQL] Support LIKE ... ESCAPE syntax

2019-07-28 Thread GitBox
beliefer commented on a change in pull request #25001: [SPARK-28083][SQL] 
Support LIKE ... ESCAPE syntax
URL: https://github.com/apache/spark/pull/25001#discussion_r308053389
 
 

 ##
 File path: 
sql/catalyst/src/test/scala/org/apache/spark/sql/catalyst/expressions/RegexpExpressionsSuite.scala
 ##
 @@ -118,6 +118,295 @@ class RegexpExpressionsSuite extends SparkFunSuite with 
ExpressionEvalHelper {
 checkLiteralRow("""%SystemDrive%\Users\John""" like _, 
"""\%SystemDrive\%\\Users%""", true)
   }
 
+  test("LIKE Pattern ESCAPE '/'") {
+
 
 Review comment:
   OK.


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:
us...@infra.apache.org


With regards,
Apache Git Services

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



[GitHub] [spark] beliefer commented on a change in pull request #25001: [SPARK-28083][SQL] Support LIKE ... ESCAPE syntax

2019-07-28 Thread GitBox
beliefer commented on a change in pull request #25001: [SPARK-28083][SQL] 
Support LIKE ... ESCAPE syntax
URL: https://github.com/apache/spark/pull/25001#discussion_r308053409
 
 

 ##
 File path: 
sql/catalyst/src/test/scala/org/apache/spark/sql/catalyst/expressions/RegexpExpressionsSuite.scala
 ##
 @@ -118,6 +118,295 @@ class RegexpExpressionsSuite extends SparkFunSuite with 
ExpressionEvalHelper {
 checkLiteralRow("""%SystemDrive%\Users\John""" like _, 
"""\%SystemDrive\%\\Users%""", true)
   }
 
+  test("LIKE Pattern ESCAPE '/'") {
+
+// null handling
+checkLiteralRow(Literal.create(null, StringType).like(_, "/"), "a", null)
+checkEvaluation(
+  Literal.create("a", StringType).like(Literal.create(null, StringType), 
"/"), null)
+checkEvaluation(
+  Literal.create(null, StringType).like(Literal.create(null, StringType), 
"/"), null)
+checkEvaluation(
+  Literal.create("a", StringType).like(NonFoldableLiteral.create("a", 
StringType), "/"), true)
+checkEvaluation(
+  Literal.create("a", StringType).like(NonFoldableLiteral.create(null, 
StringType), "/"), null)
+checkEvaluation(
+  Literal.create(null, StringType).like(NonFoldableLiteral.create("a", 
StringType), "/"), null)
+checkEvaluation(
+  Literal.create(null, StringType).like(NonFoldableLiteral.create(null, 
StringType), "/"), null)
+
+// simple patterns
+checkLiteralRow("abdef" like(_, "/"), "abdef", true)
+checkLiteralRow("a_%b" like(_, "/"), "a/__b", true)
+checkLiteralRow("addb" like(_, "/"), "a_%b", true)
+checkLiteralRow("addb" like(_, "/"), "a/__b", false)
+checkLiteralRow("addb" like(_, "/"), "a%/%b", false)
+checkLiteralRow("a_%b" like(_, "/"), "a%/%b", true)
+checkLiteralRow("addb" like(_, "/"), "a%", true)
+checkLiteralRow("addb" like(_, "/"), "**", false)
+checkLiteralRow("abc" like(_, "/"), "a%", true)
+checkLiteralRow("abc"  like(_, "/"), "b%", false)
+checkLiteralRow("abc"  like(_, "/"), "bc%", false)
+checkLiteralRow("a\nb" like(_, "/"), "a_b", true)
+checkLiteralRow("ab" like(_, "/"), "a%b", true)
+checkLiteralRow("a\nb" like(_, "/"), "a%b", true)
+
+// empty input
+checkLiteralRow("" like(_, "/"), "", true)
+checkLiteralRow("a" like(_, "/"), "", false)
+checkLiteralRow("" like(_, "/"), "a", false)
+
+// SI-17647 double-escaping backslash
+checkLiteralRow("""""" like(_, "/"), """%//%""", true)
+checkLiteralRow("""%%""" like(_, "/"), """%%""", true)
+checkLiteralRow("""/__""" like(_, "/"), """///__""", true)
+checkLiteralRow("""///__""" like(_, "/"), """%//%/%""", false)
+checkLiteralRow("""_///%""" like(_, "/"), """%//""", false)
+
+// unicode
+// scalastyle:off nonascii
+checkLiteralRow("a\u20ACa" like(_, "/"), "_\u20AC_", true)
+checkLiteralRow("a€a" like(_, "/"), "_€_", true)
+checkLiteralRow("a€a" like(_, "/"), "_\u20AC_", true)
+checkLiteralRow("a\u20ACa" like(_, "/"), "_€_", true)
+// scalastyle:on nonascii
+
+// invalid escaping
+val invalidEscape = intercept[AnalysisException] {
+  evaluateWithoutCodegen("""a""" like("""/a""", "/"))
+}
+assert(invalidEscape.getMessage.contains("pattern"))
+
+val endEscape = intercept[AnalysisException] {
+  evaluateWithoutCodegen("""a""" like("""a/""", "/"))
+}
+assert(endEscape.getMessage.contains("pattern"))
+
+// case
+checkLiteralRow("A" like(_, "/"), "a%", false)
+checkLiteralRow("a" like(_, "/"), "A%", false)
+checkLiteralRow("AaA" like(_, "/"), "_a_", true)
+
+// example
+checkLiteralRow(
+  """%SystemDrive%/Users/John""" like(_, "/"), 
"""/%SystemDrive/%//Users%""", true)
+  }
+
+  test("LIKE Pattern ESCAPE '#'") {
+
 
 Review comment:
   OK.


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:
us...@infra.apache.org


With regards,
Apache Git Services

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



[GitHub] [spark] beliefer commented on a change in pull request #25001: [SPARK-28083][SQL] Support LIKE ... ESCAPE syntax

2019-07-28 Thread GitBox
beliefer commented on a change in pull request #25001: [SPARK-28083][SQL] 
Support LIKE ... ESCAPE syntax
URL: https://github.com/apache/spark/pull/25001#discussion_r308053357
 
 

 ##
 File path: 
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/util/StringUtils.scala
 ##
 @@ -39,9 +39,16 @@ object StringUtils extends Logging {
* throw an [[AnalysisException]].
*
* @param pattern the SQL pattern to convert
+   * @param escapeStr the escape string contains one character.
* @return the equivalent Java regular expression of the pattern
*/
-  def escapeLikeRegex(pattern: String): String = {
+  def escapeLikeRegex(pattern: String, escapeStr: String): String = {
+assert(escapeStr.length <= 1)
+val escapeChar = if (escapeStr.length == 0) {
+  ""
+} else {
+  escapeStr.charAt(0)
+}
 
 Review comment:
   @maropu OK. I will move it.


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:
us...@infra.apache.org


With regards,
Apache Git Services

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



[GitHub] [spark] beliefer commented on a change in pull request #25001: [SPARK-28083][SQL] Support LIKE ... ESCAPE syntax

2019-07-28 Thread GitBox
beliefer commented on a change in pull request #25001: [SPARK-28083][SQL] 
Support LIKE ... ESCAPE syntax
URL: https://github.com/apache/spark/pull/25001#discussion_r308053160
 
 

 ##
 File path: 
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/expressions/regexpExpressions.scala
 ##
 @@ -83,33 +83,39 @@ abstract class StringRegexExpression extends 
BinaryExpression
   % matches zero or more characters in the input (similar to .* in 
posix regular
   expressions)
 
-  The escape character is '\'. If an escape character precedes a 
special symbol or another
-  escape character, the following character is matched literally. It 
is invalid to escape
-  any other character.
-
   Since Spark 2.0, string literals are unescaped in our SQL parser. 
For example, in order
   to match "\abc", the pattern should be "\\abc".
 
   When SQL config 'spark.sql.parser.escapedStringLiterals' is enabled, 
it fallbacks
   to Spark 1.6 behavior regarding string literal parsing. For example, 
if the config is
   enabled, the pattern to match "\abc" should be "\abc".
+  * escape - a optional string. The default escape character is the '\' . 
If an escape character
+  precedes a special symbol or another escape character, the following 
character is matched
+  literally. It is invalid to escape any other character. You can 
specify '' as escape
+  character so that disables the escape mechanism, which makes it 
impossible to turn off
+  the special meaning of underscore and percent signs in the pattern.
 
 Review comment:
   @maropu I'm very glad see your reply. You means this comment should stays at 
previous? I adds some description of `''` specified as escape character, we 
don't need it?


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:
us...@infra.apache.org


With regards,
Apache Git Services

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



[GitHub] [spark] beliefer commented on a change in pull request #25001: [SPARK-28083][SQL] Support LIKE ... ESCAPE syntax

2019-07-28 Thread GitBox
beliefer commented on a change in pull request #25001: [SPARK-28083][SQL] 
Support LIKE ... ESCAPE syntax
URL: https://github.com/apache/spark/pull/25001#discussion_r308053160
 
 

 ##
 File path: 
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/expressions/regexpExpressions.scala
 ##
 @@ -83,33 +83,39 @@ abstract class StringRegexExpression extends 
BinaryExpression
   % matches zero or more characters in the input (similar to .* in 
posix regular
   expressions)
 
-  The escape character is '\'. If an escape character precedes a 
special symbol or another
-  escape character, the following character is matched literally. It 
is invalid to escape
-  any other character.
-
   Since Spark 2.0, string literals are unescaped in our SQL parser. 
For example, in order
   to match "\abc", the pattern should be "\\abc".
 
   When SQL config 'spark.sql.parser.escapedStringLiterals' is enabled, 
it fallbacks
   to Spark 1.6 behavior regarding string literal parsing. For example, 
if the config is
   enabled, the pattern to match "\abc" should be "\abc".
+  * escape - a optional string. The default escape character is the '\' . 
If an escape character
+  precedes a special symbol or another escape character, the following 
character is matched
+  literally. It is invalid to escape any other character. You can 
specify '' as escape
+  character so that disables the escape mechanism, which makes it 
impossible to turn off
+  the special meaning of underscore and percent signs in the pattern.
 
 Review comment:
   @maropu I'm very glad see your reply. You means this comment should reverse 
to previous? I adds some description of `''` specified as escape character, we 
don't need it?


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:
us...@infra.apache.org


With regards,
Apache Git Services

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



[GitHub] [spark] beliefer commented on a change in pull request #25001: [SPARK-28083][SQL] Support LIKE ... ESCAPE syntax

2019-07-23 Thread GitBox
beliefer commented on a change in pull request #25001: [SPARK-28083][SQL] 
Support LIKE ... ESCAPE syntax
URL: https://github.com/apache/spark/pull/25001#discussion_r306147894
 
 

 ##
 File path: 
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/util/StringUtils.scala
 ##
 @@ -39,27 +39,36 @@ object StringUtils extends Logging {
* throw an [[AnalysisException]].
*
* @param pattern the SQL pattern to convert
+   * @param escapeStr the escape string contains one character.
* @return the equivalent Java regular expression of the pattern
*/
-  def escapeLikeRegex(pattern: String): String = {
+  def escapeLikeRegex(pattern: String, escapeStr: String): String = {
+val escapeChar = escapeStr.charAt(0)
 val in = pattern.toIterator
 val out = new StringBuilder()
 
 def fail(message: String) = throw new AnalysisException(
   s"the pattern '$pattern' is invalid, $message")
 
 while (in.hasNext) {
-  in.next match {
-case '\\' if in.hasNext =>
+  val cur = in.next
+  if (cur == escapeChar) {
 
 Review comment:
   OK. I think your suggestion is better. I learned it and to have a try!


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:
us...@infra.apache.org


With regards,
Apache Git Services

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



[GitHub] [spark] beliefer commented on a change in pull request #25001: [SPARK-28083][SQL] Support LIKE ... ESCAPE syntax

2019-07-22 Thread GitBox
beliefer commented on a change in pull request #25001: [SPARK-28083][SQL] 
Support LIKE ... ESCAPE syntax
URL: https://github.com/apache/spark/pull/25001#discussion_r305697618
 
 

 ##
 File path: 
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/parser/AstBuilder.scala
 ##
 @@ -1240,7 +1240,14 @@ class AstBuilder(conf: SQLConf) extends 
SqlBaseBaseVisitor[AnyRef] with Logging
   case SqlBaseParser.IN =>
 invertIfNotDefined(In(e, ctx.expression.asScala.map(expression)))
   case SqlBaseParser.LIKE =>
-invertIfNotDefined(Like(e, expression(ctx.pattern)))
+val escapeOpt = Option(ctx.escapeChar).map(string).map { str =>
+  if (str.length > 1) {
+throw new ParseException("Invalid escape string." +
+  "Escape string must be empty or one character.", ctx)
 
 Review comment:
   OK. I will add tests in `ExpressionParserSuite`.


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:
us...@infra.apache.org


With regards,
Apache Git Services

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



[GitHub] [spark] beliefer commented on a change in pull request #25001: [SPARK-28083][SQL] Support LIKE ... ESCAPE syntax

2019-07-22 Thread GitBox
beliefer commented on a change in pull request #25001: [SPARK-28083][SQL] 
Support LIKE ... ESCAPE syntax
URL: https://github.com/apache/spark/pull/25001#discussion_r305695663
 
 

 ##
 File path: sql/core/src/test/scala/org/apache/spark/sql/SQLQueryTestSuite.scala
 ##
 @@ -484,6 +484,8 @@ class SQLQueryTestSuite extends QueryTest with 
SharedSQLContext {
 """.stripMargin)
   .load(testFile("test-data/postgresql/tenk.data"))
   .createOrReplaceTempView("tenk1")
+
+  session.sql("select * from tenk1 where stringu1 like stringu2 escape 
'\"'")
 
 Review comment:
   OK. I will remove this and add some tests in `ExpressionParserSuite`.


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:
us...@infra.apache.org


With regards,
Apache Git Services

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



[GitHub] [spark] beliefer commented on a change in pull request #25001: [SPARK-28083][SQL] Support LIKE ... ESCAPE syntax

2019-07-22 Thread GitBox
beliefer commented on a change in pull request #25001: [SPARK-28083][SQL] 
Support LIKE ... ESCAPE syntax
URL: https://github.com/apache/spark/pull/25001#discussion_r305691039
 
 

 ##
 File path: 
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/util/StringUtils.scala
 ##
 @@ -39,27 +39,36 @@ object StringUtils extends Logging {
* throw an [[AnalysisException]].
*
* @param pattern the SQL pattern to convert
+   * @param escapeStr the escape string contains one character.
* @return the equivalent Java regular expression of the pattern
*/
-  def escapeLikeRegex(pattern: String): String = {
+  def escapeLikeRegex(pattern: String, escapeStr: String): String = {
+val escapeChar = escapeStr.charAt(0)
 val in = pattern.toIterator
 val out = new StringBuilder()
 
 def fail(message: String) = throw new AnalysisException(
   s"the pattern '$pattern' is invalid, $message")
 
 while (in.hasNext) {
-  in.next match {
-case '\\' if in.hasNext =>
+  val cur = in.next
+  if (cur == escapeChar) {
 
 Review comment:
   Because only constant could after case, not variable. This will lead a 
compile error, when the code as follows:
   ```
   in.next match {
 case escapeChar if in.hasNext =>
   ```


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:
us...@infra.apache.org


With regards,
Apache Git Services

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



[GitHub] [spark] beliefer commented on a change in pull request #25001: [SPARK-28083][SQL] Support LIKE ... ESCAPE syntax

2019-07-22 Thread GitBox
beliefer commented on a change in pull request #25001: [SPARK-28083][SQL] 
Support LIKE ... ESCAPE syntax
URL: https://github.com/apache/spark/pull/25001#discussion_r305690128
 
 

 ##
 File path: 
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/util/StringUtils.scala
 ##
 @@ -39,27 +39,36 @@ object StringUtils extends Logging {
* throw an [[AnalysisException]].
*
* @param pattern the SQL pattern to convert
+   * @param escapeStr the escape string contains one character.
* @return the equivalent Java regular expression of the pattern
*/
-  def escapeLikeRegex(pattern: String): String = {
+  def escapeLikeRegex(pattern: String, escapeStr: String): String = {
+val escapeChar = escapeStr.charAt(0)
 
 Review comment:
   OK. Thanks! A good idea.


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:
us...@infra.apache.org


With regards,
Apache Git Services

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



[GitHub] [spark] beliefer commented on a change in pull request #25001: [SPARK-28083][SQL] Support LIKE ... ESCAPE syntax

2019-07-22 Thread GitBox
beliefer commented on a change in pull request #25001: [SPARK-28083][SQL] 
Support LIKE ... ESCAPE syntax
URL: https://github.com/apache/spark/pull/25001#discussion_r305689845
 
 

 ##
 File path: 
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/expressions/regexpExpressions.scala
 ##
 @@ -83,33 +83,38 @@ abstract class StringRegexExpression extends 
BinaryExpression
   % matches zero or more characters in the input (similar to .* in 
posix regular
   expressions)
 
-  The escape character is '\'. If an escape character precedes a 
special symbol or another
-  escape character, the following character is matched literally. It 
is invalid to escape
-  any other character.
-
   Since Spark 2.0, string literals are unescaped in our SQL parser. 
For example, in order
   to match "\abc", the pattern should be "\\abc".
 
   When SQL config 'spark.sql.parser.escapedStringLiterals' is enabled, 
it fallbacks
   to Spark 1.6 behavior regarding string literal parsing. For example, 
if the config is
   enabled, the pattern to match "\abc" should be "\abc".
+  * escape - a optional string. The default escape character is the '\' . 
If an escape character
+  precedes a special symbol or another escape character, the following 
character is matched
+  literally. It is invalid to escape any other character.
   """,
   examples = """
 Examples:
   > SELECT '%SystemDrive%\Users\John' _FUNC_ '\%SystemDrive\%\\Users%'
   true
+  > SELECT '%SystemDrive%/Users/John' _FUNC_ '/%SystemDrive/%//Users%' 
ESCAPE '/'
+  true
   """,
   note = """
 Use RLIKE to match with standard regular expressions.
   """,
   since = "1.0.0")
-case class Like(left: Expression, right: Expression) extends 
StringRegexExpression {
+case class Like(left: Expression, right: Expression, escapeCharOpt: 
Option[String] = None)
+  extends StringRegexExpression {
+
+  private lazy val escapeStr = escapeCharOpt.getOrElse("\\")
 
-  override def escape(v: String): String = StringUtils.escapeLikeRegex(v)
+  override def escape(v: String): String = StringUtils.escapeLikeRegex(v, 
escapeStr)
 
   override def matches(regex: Pattern, str: String): Boolean = 
regex.matcher(str).matches()
 
-  override def toString: String = s"$left LIKE $right"
+  override def toString: String = s"$left LIKE $right" +
+escapeCharOpt.map(str => s" ESCAPE $str").getOrElse("")
 
 Review comment:
   They are different. There is used to display, but line 150-156.


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:
us...@infra.apache.org


With regards,
Apache Git Services

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



[GitHub] [spark] beliefer commented on a change in pull request #25001: [SPARK-28083][SQL] Support LIKE ... ESCAPE syntax

2019-07-22 Thread GitBox
beliefer commented on a change in pull request #25001: [SPARK-28083][SQL] 
Support LIKE ... ESCAPE syntax
URL: https://github.com/apache/spark/pull/25001#discussion_r305688779
 
 

 ##
 File path: 
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/expressions/regexpExpressions.scala
 ##
 @@ -83,33 +83,38 @@ abstract class StringRegexExpression extends 
BinaryExpression
   % matches zero or more characters in the input (similar to .* in 
posix regular
   expressions)
 
-  The escape character is '\'. If an escape character precedes a 
special symbol or another
-  escape character, the following character is matched literally. It 
is invalid to escape
-  any other character.
-
   Since Spark 2.0, string literals are unescaped in our SQL parser. 
For example, in order
   to match "\abc", the pattern should be "\\abc".
 
   When SQL config 'spark.sql.parser.escapedStringLiterals' is enabled, 
it fallbacks
   to Spark 1.6 behavior regarding string literal parsing. For example, 
if the config is
   enabled, the pattern to match "\abc" should be "\abc".
+  * escape - a optional string. The default escape character is the '\' . 
If an escape character
+  precedes a special symbol or another escape character, the following 
character is matched
+  literally. It is invalid to escape any other character.
   """,
   examples = """
 Examples:
   > SELECT '%SystemDrive%\Users\John' _FUNC_ '\%SystemDrive\%\\Users%'
   true
+  > SELECT '%SystemDrive%/Users/John' _FUNC_ '/%SystemDrive/%//Users%' 
ESCAPE '/'
+  true
   """,
   note = """
 Use RLIKE to match with standard regular expressions.
   """,
   since = "1.0.0")
-case class Like(left: Expression, right: Expression) extends 
StringRegexExpression {
+case class Like(left: Expression, right: Expression, escapeCharOpt: 
Option[String] = None)
+  extends StringRegexExpression {
+
+  private lazy val escapeStr = escapeCharOpt.getOrElse("\\")
 
-  override def escape(v: String): String = StringUtils.escapeLikeRegex(v)
+  override def escape(v: String): String = StringUtils.escapeLikeRegex(v, 
escapeStr)
 
 Review comment:
   Yes. `escapeStr` variable could be removed indeed.


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:
us...@infra.apache.org


With regards,
Apache Git Services

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



[GitHub] [spark] beliefer commented on a change in pull request #25001: [SPARK-28083][SQL] Support LIKE ... ESCAPE syntax

2019-07-16 Thread GitBox
beliefer commented on a change in pull request #25001: [SPARK-28083][SQL] 
Support LIKE ... ESCAPE syntax
URL: https://github.com/apache/spark/pull/25001#discussion_r304203014
 
 

 ##
 File path: 
sql/catalyst/src/test/scala/org/apache/spark/sql/catalyst/expressions/RegexpExpressionsSuite.scala
 ##
 @@ -118,6 +118,154 @@ class RegexpExpressionsSuite extends SparkFunSuite with 
ExpressionEvalHelper {
 checkLiteralRow("""%SystemDrive%\Users\John""" like _, 
"""\%SystemDrive\%\\Users%""", true)
   }
 
+  test("LIKE Pattern ESCAPE '/'") {
+
+// null handling
+checkLiteralRow(Literal.create(null, StringType).like(_, "/"), "a", null)
+checkEvaluation(
+  Literal.create("a", StringType).like(Literal.create(null, StringType), 
"/"), null)
+checkEvaluation(
+  Literal.create(null, StringType).like(Literal.create(null, StringType), 
"/"), null)
+checkEvaluation(
+  Literal.create("a", StringType).like(NonFoldableLiteral.create("a", 
StringType), "/"), true)
+checkEvaluation(
+  Literal.create("a", StringType).like(NonFoldableLiteral.create(null, 
StringType), "/"), null)
+checkEvaluation(
+  Literal.create(null, StringType).like(NonFoldableLiteral.create("a", 
StringType), "/"), null)
+checkEvaluation(
+  Literal.create(null, StringType).like(NonFoldableLiteral.create(null, 
StringType), "/"), null)
+
+// simple patterns
+checkLiteralRow("abdef" like(_, "/"), "abdef", true)
+checkLiteralRow("a_%b" like(_, "/"), "a/__b", true)
+checkLiteralRow("addb" like(_, "/"), "a_%b", true)
+checkLiteralRow("addb" like(_, "/"), "a/__b", false)
+checkLiteralRow("addb" like(_, "/"), "a%/%b", false)
+checkLiteralRow("a_%b" like(_, "/"), "a%/%b", true)
+checkLiteralRow("addb" like(_, "/"), "a%", true)
+checkLiteralRow("addb" like(_, "/"), "**", false)
+checkLiteralRow("abc" like(_, "/"), "a%", true)
+checkLiteralRow("abc"  like(_, "/"), "b%", false)
+checkLiteralRow("abc"  like(_, "/"), "bc%", false)
+checkLiteralRow("a\nb" like(_, "/"), "a_b", true)
+checkLiteralRow("ab" like(_, "/"), "a%b", true)
+checkLiteralRow("a\nb" like(_, "/"), "a%b", true)
+
+// empty input
+checkLiteralRow("" like(_, "/"), "", true)
+checkLiteralRow("a" like(_, "/"), "", false)
+checkLiteralRow("" like(_, "/"), "a", false)
+
+// SI-17647 double-escaping backslash
+checkLiteralRow("""""" like(_, "/"), """%//%""", true)
+checkLiteralRow("""%%""" like(_, "/"), """%%""", true)
+checkLiteralRow("""/__""" like(_, "/"), """///__""", true)
+checkLiteralRow("""///__""" like(_, "/"), """%//%/%""", false)
+checkLiteralRow("""_///%""" like(_, "/"), """%//""", false)
+
+// unicode
+// scalastyle:off nonascii
+checkLiteralRow("a\u20ACa" like(_, "/"), "_\u20AC_", true)
+checkLiteralRow("a€a" like(_, "/"), "_€_", true)
+checkLiteralRow("a€a" like(_, "/"), "_\u20AC_", true)
+checkLiteralRow("a\u20ACa" like(_, "/"), "_€_", true)
+// scalastyle:on nonascii
+
+// invalid escaping
+val invalidEscape = intercept[AnalysisException] {
+  evaluateWithoutCodegen("""a""" like("""/a""", "/"))
+}
+assert(invalidEscape.getMessage.contains("pattern"))
 
 Review comment:
   This is correct. I reference the former UT.


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:
us...@infra.apache.org


With regards,
Apache Git Services

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



[GitHub] [spark] beliefer commented on a change in pull request #25001: [SPARK-28083][SQL] Support LIKE ... ESCAPE syntax

2019-07-16 Thread GitBox
beliefer commented on a change in pull request #25001: [SPARK-28083][SQL] 
Support LIKE ... ESCAPE syntax
URL: https://github.com/apache/spark/pull/25001#discussion_r304199203
 
 

 ##
 File path: 
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/expressions/regexpExpressions.scala
 ##
 @@ -142,10 +148,11 @@ case class Like(left: Expression, right: Expression) 
extends StringRegexExpressi
 } else {
   val pattern = ctx.freshName("pattern")
   val rightStr = ctx.freshName("rightStr")
+  val escapeChar = escapeCharOpt.getOrElse("""""")
 
 Review comment:
   Yes. I try to use ", it not works fine.


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:
us...@infra.apache.org


With regards,
Apache Git Services

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



[GitHub] [spark] beliefer commented on a change in pull request #25001: [SPARK-28083][SQL] Support LIKE ... ESCAPE syntax

2019-07-16 Thread GitBox
beliefer commented on a change in pull request #25001: [SPARK-28083][SQL] 
Support LIKE ... ESCAPE syntax
URL: https://github.com/apache/spark/pull/25001#discussion_r304199203
 
 

 ##
 File path: 
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/expressions/regexpExpressions.scala
 ##
 @@ -142,10 +148,11 @@ case class Like(left: Expression, right: Expression) 
extends StringRegexExpressi
 } else {
   val pattern = ctx.freshName("pattern")
   val rightStr = ctx.freshName("rightStr")
+  val escapeChar = escapeCharOpt.getOrElse("""""")
 
 Review comment:
   Yes. I try to use ", it not works fine.


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:
us...@infra.apache.org


With regards,
Apache Git Services

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



[GitHub] [spark] beliefer commented on a change in pull request #25001: [SPARK-28083][SQL] Support LIKE ... ESCAPE syntax

2019-07-16 Thread GitBox
beliefer commented on a change in pull request #25001: [SPARK-28083][SQL] 
Support LIKE ... ESCAPE syntax
URL: https://github.com/apache/spark/pull/25001#discussion_r304199040
 
 

 ##
 File path: 
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/expressions/regexpExpressions.scala
 ##
 @@ -83,33 +83,39 @@ abstract class StringRegexExpression extends 
BinaryExpression
   % matches zero or more characters in the input (similar to .* in 
posix regular
   expressions)
 
-  The escape character is '\'. If an escape character precedes a 
special symbol or another
-  escape character, the following character is matched literally. It 
is invalid to escape
-  any other character.
-
   Since Spark 2.0, string literals are unescaped in our SQL parser. 
For example, in order
   to match "\abc", the pattern should be "\\abc".
 
   When SQL config 'spark.sql.parser.escapedStringLiterals' is enabled, 
it fallbacks
   to Spark 1.6 behavior regarding string literal parsing. For example, 
if the config is
   enabled, the pattern to match "\abc" should be "\abc".
+  * escape - a optional string. The default escape character is the '\' 
but a different one
+  can be selected by using the ESCAPE clause. If an escape character 
precedes a special
+  symbol or another escape character, the following character is 
matched literally. It is
+  invalid to escape any other character.
   """,
   examples = """
 Examples:
   > SELECT '%SystemDrive%\Users\John' _FUNC_ '\%SystemDrive\%\\Users%'
   true
+  > SELECT '%SystemDrive%/Users/John' _FUNC_ '/%SystemDrive/%//Users%' 
ESCAPE '/'
+  true
   """,
   note = """
 Use RLIKE to match with standard regular expressions.
   """,
   since = "1.0.0")
-case class Like(left: Expression, right: Expression) extends 
StringRegexExpression {
+case class Like(left: Expression, right: Expression, escapeCharOpt: 
Option[String] = None)
+  extends StringRegexExpression {
+
+  private lazy val escapeStr = escapeCharOpt.getOrElse("\\")
 
-  override def escape(v: String): String = StringUtils.escapeLikeRegex(v)
+  override def escape(v: String): String = StringUtils.escapeLikeRegex(v, 
escapeStr)
 
   override def matches(regex: Pattern, str: String): Boolean = 
regex.matcher(str).matches()
 
-  override def toString: String = s"$left LIKE $right"
+  override def toString: String = s"$left LIKE $right" +
+escapeCharOpt.map(str => s" ESCAPE $str")
 
 Review comment:
   OK. not exceeds 100 char.


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:
us...@infra.apache.org


With regards,
Apache Git Services

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



[GitHub] [spark] beliefer commented on a change in pull request #25001: [SPARK-28083][SQL] Support LIKE ... ESCAPE syntax

2019-07-16 Thread GitBox
beliefer commented on a change in pull request #25001: [SPARK-28083][SQL] 
Support LIKE ... ESCAPE syntax
URL: https://github.com/apache/spark/pull/25001#discussion_r304196449
 
 

 ##
 File path: 
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/expressions/regexpExpressions.scala
 ##
 @@ -83,33 +83,39 @@ abstract class StringRegexExpression extends 
BinaryExpression
   % matches zero or more characters in the input (similar to .* in 
posix regular
   expressions)
 
-  The escape character is '\'. If an escape character precedes a 
special symbol or another
-  escape character, the following character is matched literally. It 
is invalid to escape
-  any other character.
-
   Since Spark 2.0, string literals are unescaped in our SQL parser. 
For example, in order
   to match "\abc", the pattern should be "\\abc".
 
   When SQL config 'spark.sql.parser.escapedStringLiterals' is enabled, 
it fallbacks
   to Spark 1.6 behavior regarding string literal parsing. For example, 
if the config is
   enabled, the pattern to match "\abc" should be "\abc".
+  * escape - a optional string. The default escape character is the '\' 
but a different one
+  can be selected by using the ESCAPE clause. If an escape character 
precedes a special
+  symbol or another escape character, the following character is 
matched literally. It is
+  invalid to escape any other character.
 
 Review comment:
   OK. Looks like some redundancy.


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:
us...@infra.apache.org


With regards,
Apache Git Services

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



[GitHub] [spark] beliefer commented on a change in pull request #25001: [SPARK-28083][SQL] Support LIKE ... ESCAPE syntax

2019-07-16 Thread GitBox
beliefer commented on a change in pull request #25001: [SPARK-28083][SQL] 
Support LIKE ... ESCAPE syntax
URL: https://github.com/apache/spark/pull/25001#discussion_r304195297
 
 

 ##
 File path: 
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/expressions/regexpExpressions.scala
 ##
 @@ -70,8 +70,8 @@ abstract class StringRegexExpression extends BinaryExpression
  * Simple RegEx pattern matching function
  */
 @ExpressionDescription(
-  usage = "str _FUNC_ pattern - Returns true if str matches pattern, " +
-"null if any arguments are null, false otherwise.",
+  usage = "str _FUNC_ pattern[ escape] - Returns true if str matches `pattern` 
with `escape`" +
 
 Review comment:
   OK. I have thought about whether or not to do this. Under your suggestion, I 
feel more clear.


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:
us...@infra.apache.org


With regards,
Apache Git Services

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



[GitHub] [spark] beliefer commented on a change in pull request #25001: [SPARK-28083][SQL] Support LIKE ... ESCAPE syntax

2019-07-11 Thread GitBox
beliefer commented on a change in pull request #25001: [SPARK-28083][SQL] 
Support LIKE ... ESCAPE syntax
URL: https://github.com/apache/spark/pull/25001#discussion_r302411781
 
 

 ##
 File path: 
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/expressions/regexpExpressions.scala
 ##
 @@ -103,13 +103,16 @@ abstract class StringRegexExpression extends 
BinaryExpression
 Use RLIKE to match with standard regular expressions.
   """,
   since = "1.0.0")
-case class Like(left: Expression, right: Expression) extends 
StringRegexExpression {
+case class Like(left: Expression, right: Expression, escapeCharOpt: 
Option[String] = None)
+  extends StringRegexExpression {
+
+  private lazy val escapeStr = escapeCharOpt.getOrElse("\\")
 
-  override def escape(v: String): String = StringUtils.escapeLikeRegex(v)
+  override def escape(v: String): String = StringUtils.escapeLikeRegex(v, 
escapeStr)
 
   override def matches(regex: Pattern, str: String): Boolean = 
regex.matcher(str).matches()
 
-  override def toString: String = s"$left LIKE $right"
+  override def toString: String = s"$left LIKE $right ESCAPE $escapeStr"
 
 Review comment:
   OK. I think you opinion are more reasonable.


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:
us...@infra.apache.org


With regards,
Apache Git Services

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



[GitHub] [spark] beliefer commented on a change in pull request #25001: [SPARK-28083][SQL] Support LIKE ... ESCAPE syntax

2019-07-11 Thread GitBox
beliefer commented on a change in pull request #25001: [SPARK-28083][SQL] 
Support LIKE ... ESCAPE syntax
URL: https://github.com/apache/spark/pull/25001#discussion_r302386285
 
 

 ##
 File path: 
sql/catalyst/src/test/scala/org/apache/spark/sql/catalyst/expressions/RegexpExpressionsSuite.scala
 ##
 @@ -51,71 +51,123 @@ class RegexpExpressionsSuite extends SparkFunSuite with 
ExpressionEvalHelper {
 
 // null handling
 checkLiteralRow(Literal.create(null, StringType).like(_), "a", null)
+checkLiteralRow(Literal.create(null, StringType).like(_, "/"), "a", null)
 
 Review comment:
   OK. I add a new test case.


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:
us...@infra.apache.org


With regards,
Apache Git Services

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



[GitHub] [spark] beliefer commented on a change in pull request #25001: [SPARK-28083][SQL] Support LIKE ... ESCAPE syntax

2019-07-11 Thread GitBox
beliefer commented on a change in pull request #25001: [SPARK-28083][SQL] 
Support LIKE ... ESCAPE syntax
URL: https://github.com/apache/spark/pull/25001#discussion_r302342786
 
 

 ##
 File path: 
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/expressions/regexpExpressions.scala
 ##
 @@ -142,10 +145,11 @@ case class Like(left: Expression, right: Expression) 
extends StringRegexExpressi
 } else {
   val pattern = ctx.freshName("pattern")
   val rightStr = ctx.freshName("rightStr")
+  val escapeChar = escapeCharOpt.getOrElse("")
 
 Review comment:
   I change `""` to `""""""`,it's OK.


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:
us...@infra.apache.org


With regards,
Apache Git Services

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



[GitHub] [spark] beliefer commented on a change in pull request #25001: [SPARK-28083][SQL] Support LIKE ... ESCAPE syntax

2019-07-10 Thread GitBox
beliefer commented on a change in pull request #25001: [SPARK-28083][SQL] 
Support LIKE ... ESCAPE syntax
URL: https://github.com/apache/spark/pull/25001#discussion_r302342786
 
 

 ##
 File path: 
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/expressions/regexpExpressions.scala
 ##
 @@ -142,10 +145,11 @@ case class Like(left: Expression, right: Expression) 
extends StringRegexExpressi
 } else {
   val pattern = ctx.freshName("pattern")
   val rightStr = ctx.freshName("rightStr")
+  val escapeChar = escapeCharOpt.getOrElse("")
 
 Review comment:
   I change `""`
   to `""""""` or `"""\\"""` or `"""\"""`, all the change can't works.


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:
us...@infra.apache.org


With regards,
Apache Git Services

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



[GitHub] [spark] beliefer commented on a change in pull request #25001: [SPARK-28083][SQL] Support LIKE ... ESCAPE syntax

2019-07-10 Thread GitBox
beliefer commented on a change in pull request #25001: [SPARK-28083][SQL] 
Support LIKE ... ESCAPE syntax
URL: https://github.com/apache/spark/pull/25001#discussion_r302354873
 
 

 ##
 File path: 
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/expressions/regexpExpressions.scala
 ##
 @@ -103,13 +106,16 @@ abstract class StringRegexExpression extends 
BinaryExpression
 Use RLIKE to match with standard regular expressions.
   """,
   since = "1.0.0")
-case class Like(left: Expression, right: Expression) extends 
StringRegexExpression {
+case class Like(left: Expression, right: Expression, escapeCharOpt: 
Option[String] = None)
+  extends StringRegexExpression {
 
-  override def escape(v: String): String = StringUtils.escapeLikeRegex(v)
+  private lazy val escapeStr = escapeCharOpt.getOrElse("\\")
 
 Review comment:
   `escapeStr` works fine in line 111, but not normal in line 149. 
   If I change to:
   `private lazy val escapeStr = escapeCharOpt.getOrElse("""\\""")`
   `escapeStr` works fine in line 149, but not normal in line 111. 


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:
us...@infra.apache.org


With regards,
Apache Git Services

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



[GitHub] [spark] beliefer commented on a change in pull request #25001: [SPARK-28083][SQL] Support LIKE ... ESCAPE syntax

2019-07-10 Thread GitBox
beliefer commented on a change in pull request #25001: [SPARK-28083][SQL] 
Support LIKE ... ESCAPE syntax
URL: https://github.com/apache/spark/pull/25001#discussion_r302342786
 
 

 ##
 File path: 
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/expressions/regexpExpressions.scala
 ##
 @@ -142,10 +145,11 @@ case class Like(left: Expression, right: Expression) 
extends StringRegexExpressi
 } else {
   val pattern = ctx.freshName("pattern")
   val rightStr = ctx.freshName("rightStr")
+  val escapeChar = escapeCharOpt.getOrElse("")
 
 Review comment:
   OK. a good idea.


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:
us...@infra.apache.org


With regards,
Apache Git Services

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



[GitHub] [spark] beliefer commented on a change in pull request #25001: [SPARK-28083][SQL] Support LIKE ... ESCAPE syntax

2019-07-10 Thread GitBox
beliefer commented on a change in pull request #25001: [SPARK-28083][SQL] 
Support LIKE ... ESCAPE syntax
URL: https://github.com/apache/spark/pull/25001#discussion_r302342678
 
 

 ##
 File path: 
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/expressions/regexpExpressions.scala
 ##
 @@ -103,13 +103,16 @@ abstract class StringRegexExpression extends 
BinaryExpression
 Use RLIKE to match with standard regular expressions.
   """,
   since = "1.0.0")
-case class Like(left: Expression, right: Expression) extends 
StringRegexExpression {
+case class Like(left: Expression, right: Expression, escapeCharOpt: 
Option[String] = None)
+  extends StringRegexExpression {
+
+  private lazy val escapeStr = escapeCharOpt.getOrElse("\\")
 
-  override def escape(v: String): String = StringUtils.escapeLikeRegex(v)
+  override def escape(v: String): String = StringUtils.escapeLikeRegex(v, 
escapeStr)
 
   override def matches(regex: Pattern, str: String): Boolean = 
regex.matcher(str).matches()
 
-  override def toString: String = s"$left LIKE $right"
+  override def toString: String = s"$left LIKE $right ESCAPE $escapeStr"
 
 Review comment:
   Yes, `escapeStr` is `/` if the `escapeCharOpt == None`, so I want always 
print it.


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:
us...@infra.apache.org


With regards,
Apache Git Services

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



[GitHub] [spark] beliefer commented on a change in pull request #25001: [SPARK-28083][SQL] Support LIKE ... ESCAPE syntax

2019-07-10 Thread GitBox
beliefer commented on a change in pull request #25001: [SPARK-28083][SQL] 
Support LIKE ... ESCAPE syntax
URL: https://github.com/apache/spark/pull/25001#discussion_r302342327
 
 

 ##
 File path: 
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/expressions/regexpExpressions.scala
 ##
 @@ -70,7 +70,7 @@ abstract class StringRegexExpression extends BinaryExpression
  * Simple RegEx pattern matching function
  */
 @ExpressionDescription(
-  usage = "str _FUNC_ pattern - Returns true if str matches pattern, " +
+  usage = "str _FUNC_ pattern escape - Returns true if str matches pattern 
with escape, " +
 
 Review comment:
   OK. I will add brackets to denote optional and the example.


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:
us...@infra.apache.org


With regards,
Apache Git Services

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



[GitHub] [spark] beliefer commented on a change in pull request #25001: [SPARK-28083][SQL] Support LIKE ... ESCAPE syntax

2019-07-07 Thread GitBox
beliefer commented on a change in pull request #25001: [SPARK-28083][SQL] 
Support LIKE ... ESCAPE syntax
URL: https://github.com/apache/spark/pull/25001#discussion_r300859316
 
 

 ##
 File path: docs/sql-keywords.md
 ##
 @@ -103,6 +103,7 @@ Below is a list of all the keywords in Spark SQL.
   
DROPnon-reservednon-reservedreserved
   ELSEreservednon-reservedreserved
   ENDreservednon-reservedreserved
+  
ESCAPEnon-reservednon-reservedreserved
 
 Review comment:
   OK. I put escape as reserved in spark.


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:
us...@infra.apache.org


With regards,
Apache Git Services

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



[GitHub] [spark] beliefer commented on a change in pull request #25001: [SPARK-28083][SQL] Support LIKE ... ESCAPE syntax

2019-07-07 Thread GitBox
beliefer commented on a change in pull request #25001: [SPARK-28083][SQL] 
Support LIKE ... ESCAPE syntax
URL: https://github.com/apache/spark/pull/25001#discussion_r300859189
 
 

 ##
 File path: 
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/expressions/regexpExpressions.scala
 ##
 @@ -83,16 +83,19 @@ abstract class StringRegexExpression extends 
BinaryExpression
   % matches zero or more characters in the input (similar to .* in 
posix regular
   expressions)
 
-  The escape character is '\'. If an escape character precedes a 
special symbol or another
-  escape character, the following character is matched literally. It 
is invalid to escape
-  any other character.
+  The default escape character is '\'. If an escape character precedes 
a special symbol
+  or another escape character, the following character is matched 
literally. It is
+  invalid to escape any other character.
 
 Review comment:
   OK. I changed it.


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:
us...@infra.apache.org


With regards,
Apache Git Services

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



[GitHub] [spark] beliefer commented on a change in pull request #25001: [SPARK-28083][SQL] Support LIKE ... ESCAPE syntax

2019-07-07 Thread GitBox
beliefer commented on a change in pull request #25001: [SPARK-28083][SQL] 
Support LIKE ... ESCAPE syntax
URL: https://github.com/apache/spark/pull/25001#discussion_r300858693
 
 

 ##
 File path: 
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/dsl/package.scala
 ##
 @@ -97,7 +97,9 @@ package object dsl {
   case _ => In(expr, list)
 }
 
-def like(other: Expression): Expression = Like(expr, other)
+def like(other: Expression): Expression = Like(expr, other, None)
+def like(other: Expression, escapeChar: String): Expression =
+  Like(expr, other, Option(escapeChar))
 
 Review comment:
   OK. I will change it


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:
us...@infra.apache.org


With regards,
Apache Git Services

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



[GitHub] [spark] beliefer commented on a change in pull request #25001: [SPARK-28083][SQL] Support LIKE ... ESCAPE syntax

2019-07-07 Thread GitBox
beliefer commented on a change in pull request #25001: [SPARK-28083][SQL] 
Support LIKE ... ESCAPE syntax
URL: https://github.com/apache/spark/pull/25001#discussion_r300858662
 
 

 ##
 File path: 
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/expressions/regexpExpressions.scala
 ##
 @@ -103,13 +106,16 @@ abstract class StringRegexExpression extends 
BinaryExpression
 Use RLIKE to match with standard regular expressions.
   """,
   since = "1.0.0")
-case class Like(left: Expression, right: Expression) extends 
StringRegexExpression {
+case class Like(left: Expression, right: Expression, escapeCharOpt: 
Option[String] = None)
+  extends StringRegexExpression {
 
-  override def escape(v: String): String = StringUtils.escapeLikeRegex(v)
+  private lazy val escapeStr = escapeCharOpt.getOrElse("\\")
 
 Review comment:
   The `doGenCode` exists two code execution path. when `right.foldable` is 
false, escapeStr will be not used.


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:
us...@infra.apache.org


With regards,
Apache Git Services

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



[GitHub] [spark] beliefer commented on a change in pull request #25001: [SPARK-28083][SQL] Support LIKE ... ESCAPE syntax

2019-07-07 Thread GitBox
beliefer commented on a change in pull request #25001: [SPARK-28083][SQL] 
Support LIKE ... ESCAPE syntax
URL: https://github.com/apache/spark/pull/25001#discussion_r300858514
 
 

 ##
 File path: 
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/parser/AstBuilder.scala
 ##
 @@ -1240,7 +1240,15 @@ class AstBuilder(conf: SQLConf) extends 
SqlBaseBaseVisitor[AnyRef] with Logging
   case SqlBaseParser.IN =>
 invertIfNotDefined(In(e, ctx.expression.asScala.map(expression)))
   case SqlBaseParser.LIKE =>
-invertIfNotDefined(Like(e, expression(ctx.pattern)))
+val escapeOpt = Option(ctx.escapeChar).map{ str =>
+  if (str.getText.length() > 1) {
 
 Review comment:
   OK.


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:
us...@infra.apache.org


With regards,
Apache Git Services

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



[GitHub] [spark] beliefer commented on a change in pull request #25001: [SPARK-28083][SQL] Support LIKE ... ESCAPE syntax

2019-07-07 Thread GitBox
beliefer commented on a change in pull request #25001: [SPARK-28083][SQL] 
Support LIKE ... ESCAPE syntax
URL: https://github.com/apache/spark/pull/25001#discussion_r300858502
 
 

 ##
 File path: 
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/parser/AstBuilder.scala
 ##
 @@ -1240,7 +1240,15 @@ class AstBuilder(conf: SQLConf) extends 
SqlBaseBaseVisitor[AnyRef] with Logging
   case SqlBaseParser.IN =>
 invertIfNotDefined(In(e, ctx.expression.asScala.map(expression)))
   case SqlBaseParser.LIKE =>
-invertIfNotDefined(Like(e, expression(ctx.pattern)))
+val escapeOpt = Option(ctx.escapeChar).map{ str =>
 
 Review comment:
   OK. I get it.


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:
us...@infra.apache.org


With regards,
Apache Git Services

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



[GitHub] [spark] beliefer commented on a change in pull request #25001: [SPARK-28083][SQL] Support LIKE ... ESCAPE syntax

2019-07-07 Thread GitBox
beliefer commented on a change in pull request #25001: [SPARK-28083][SQL] 
Support LIKE ... ESCAPE syntax
URL: https://github.com/apache/spark/pull/25001#discussion_r300858486
 
 

 ##
 File path: 
sql/catalyst/src/test/scala/org/apache/spark/sql/catalyst/expressions/RegexpExpressionsSuite.scala
 ##
 @@ -51,71 +51,123 @@ class RegexpExpressionsSuite extends SparkFunSuite with 
ExpressionEvalHelper {
 
 // null handling
 checkLiteralRow(Literal.create(null, StringType).like(_), "a", null)
+checkLiteralRow(Literal.create(null, StringType).like(_, "/"), "a", null)
 
 Review comment:
   I think these tests could prove that the behavior is correct after support 
escape char.


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:
us...@infra.apache.org


With regards,
Apache Git Services

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



[GitHub] [spark] beliefer commented on a change in pull request #25001: [SPARK-28083][SQL] Support LIKE ... ESCAPE syntax

2019-07-07 Thread GitBox
beliefer commented on a change in pull request #25001: [SPARK-28083][SQL] 
Support LIKE ... ESCAPE syntax
URL: https://github.com/apache/spark/pull/25001#discussion_r300858454
 
 

 ##
 File path: 
sql/catalyst/src/test/scala/org/apache/spark/sql/catalyst/util/StringUtilsSuite.scala
 ##
 @@ -23,13 +23,20 @@ import org.apache.spark.sql.catalyst.util.StringUtils._
 class StringUtilsSuite extends SparkFunSuite {
 
   test("escapeLikeRegex") {
-assert(escapeLikeRegex("abdef") === 
"(?s)\\Qa\\E\\Qb\\E\\Qd\\E\\Qe\\E\\Qf\\E")
-assert(escapeLikeRegex("a\\__b") === "(?s)\\Qa\\E\\Q_\\E.\\Qb\\E")
-assert(escapeLikeRegex("a_%b") === "(?s)\\Qa\\E..*\\Qb\\E")
-assert(escapeLikeRegex("a%\\%b") === "(?s)\\Qa\\E.*\\Q%\\E\\Qb\\E")
-assert(escapeLikeRegex("a%") === "(?s)\\Qa\\E.*")
-assert(escapeLikeRegex("**") === "(?s)\\Q*\\E\\Q*\\E")
-assert(escapeLikeRegex("a_b") === "(?s)\\Qa\\E.\\Qb\\E")
+assert(escapeLikeRegex("abdef", "\\") === 
"(?s)\\Qa\\E\\Qb\\E\\Qd\\E\\Qe\\E\\Qf\\E")
 
 Review comment:
   The behavior of `escapeLikeRegex` has added a new parameter,  so I think 
should override it.


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:
us...@infra.apache.org


With regards,
Apache Git Services

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



[GitHub] [spark] beliefer commented on a change in pull request #25001: [SPARK-28083][SQL] Support LIKE ... ESCAPE syntax

2019-07-05 Thread GitBox
beliefer commented on a change in pull request #25001: [SPARK-28083][SQL] 
Support LIKE ... ESCAPE syntax
URL: https://github.com/apache/spark/pull/25001#discussion_r300519991
 
 

 ##
 File path: 
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/parser/AstBuilder.scala
 ##
 @@ -1240,7 +1240,9 @@ class AstBuilder(conf: SQLConf) extends 
SqlBaseBaseVisitor[AnyRef] with Logging
   case SqlBaseParser.IN =>
 invertIfNotDefined(In(e, ctx.expression.asScala.map(expression)))
   case SqlBaseParser.LIKE =>
-invertIfNotDefined(Like(e, expression(ctx.pattern)))
+val escapeOpt = Option(ctx.escapeChar).map(_.getText)
+val like = Like(e, expression(ctx.pattern), escapeOpt)
+invertIfNotDefined(like)
 
 Review comment:
   A good idea. I will treat it.


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:
us...@infra.apache.org


With regards,
Apache Git Services

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



[GitHub] [spark] beliefer commented on a change in pull request #25001: [SPARK-28083][SQL] Support LIKE ... ESCAPE syntax

2019-07-04 Thread GitBox
beliefer commented on a change in pull request #25001: [SPARK-28083][SQL] 
Support LIKE ... ESCAPE syntax
URL: https://github.com/apache/spark/pull/25001#discussion_r300521870
 
 

 ##
 File path: 
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/expressions/regexpExpressions.scala
 ##
 @@ -83,16 +83,19 @@ abstract class StringRegexExpression extends 
BinaryExpression
   % matches zero or more characters in the input (similar to .* in 
posix regular
   expressions)
 
-  The escape character is '\'. If an escape character precedes a 
special symbol or another
-  escape character, the following character is matched literally. It 
is invalid to escape
-  any other character.
+  The default escape character is '\'. If an escape character precedes 
a special symbol
+  or another escape character, the following character is matched 
literally. It is
+  invalid to escape any other character.
 
   Since Spark 2.0, string literals are unescaped in our SQL parser. 
For example, in order
   to match "\abc", the pattern should be "\\abc".
 
   When SQL config 'spark.sql.parser.escapedStringLiterals' is enabled, 
it fallbacks
   to Spark 1.6 behavior regarding string literal parsing. For example, 
if the config is
   enabled, the pattern to match "\abc" should be "\abc".
+  * escape - a string expression. The default escape character is the '\' 
but a different one
 
 Review comment:
   OK. I changed it.


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:
us...@infra.apache.org


With regards,
Apache Git Services

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



[GitHub] [spark] beliefer commented on a change in pull request #25001: [SPARK-28083][SQL] Support LIKE ... ESCAPE syntax

2019-07-04 Thread GitBox
beliefer commented on a change in pull request #25001: [SPARK-28083][SQL] 
Support LIKE ... ESCAPE syntax
URL: https://github.com/apache/spark/pull/25001#discussion_r300521827
 
 

 ##
 File path: sql/core/src/main/scala/org/apache/spark/sql/Column.scala
 ##
 @@ -822,6 +822,16 @@ class Column(val expr: Expression) extends Logging {
*/
   def like(literal: String): Column = withExpr { Like(expr, lit(literal).expr) 
}
 
+  /**
+   * SQL like expression. Returns a boolean column based on a SQL LIKE ESCAPE 
match.
+   *
+   * @group expr_ops
+   * @since 3.0.0
+   */
+  def like(literal: String, escapeStr: String): Column = withExpr {
+Like(expr, lit(literal).expr, Option(escapeStr))
+  }
+
 
 Review comment:
   I think it's OK. If this is not needed, I will remove it.


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:
us...@infra.apache.org


With regards,
Apache Git Services

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



[GitHub] [spark] beliefer commented on a change in pull request #25001: [SPARK-28083][SQL] Support LIKE ... ESCAPE syntax

2019-07-04 Thread GitBox
beliefer commented on a change in pull request #25001: [SPARK-28083][SQL] 
Support LIKE ... ESCAPE syntax
URL: https://github.com/apache/spark/pull/25001#discussion_r300520965
 
 

 ##
 File path: 
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/util/StringUtils.scala
 ##
 @@ -65,6 +65,38 @@ object StringUtils extends Logging {
 "(?s)" + out.result() // (?s) enables dotall mode, causing "." to match 
new lines
   }
 
+  def escapeLikeRegex(pattern: String, escapeStr: String): String = {
 
 Review comment:
   Yes, the old `escapeLikeRegex` will not be used. I will remove it.


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:
us...@infra.apache.org


With regards,
Apache Git Services

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



[GitHub] [spark] beliefer commented on a change in pull request #25001: [SPARK-28083][SQL] Support LIKE ... ESCAPE syntax

2019-07-04 Thread GitBox
beliefer commented on a change in pull request #25001: [SPARK-28083][SQL] 
Support LIKE ... ESCAPE syntax
URL: https://github.com/apache/spark/pull/25001#discussion_r300520695
 
 

 ##
 File path: 
sql/core/src/test/resources/sql-tests/results/typeCoercion/native/implicitTypeCasts.sql.out
 ##
 @@ -317,38 +317,38 @@ struct
 -- !query 39
 select 1 like '%' FROM t
 -- !query 39 schema
-struct
+struct
 
 Review comment:
   Yes, I can discard overriding the function `sql`.


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:
us...@infra.apache.org


With regards,
Apache Git Services

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



[GitHub] [spark] beliefer commented on a change in pull request #25001: [SPARK-28083][SQL] Support LIKE ... ESCAPE syntax

2019-07-04 Thread GitBox
beliefer commented on a change in pull request #25001: [SPARK-28083][SQL] 
Support LIKE ... ESCAPE syntax
URL: https://github.com/apache/spark/pull/25001#discussion_r300520591
 
 

 ##
 File path: 
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/expressions/regexpExpressions.scala
 ##
 @@ -103,13 +106,20 @@ abstract class StringRegexExpression extends 
BinaryExpression
 Use RLIKE to match with standard regular expressions.
   """,
   since = "1.0.0")
-case class Like(left: Expression, right: Expression) extends 
StringRegexExpression {
+case class Like(
+  left: Expression,
+  right: Expression,
+  escapeCharOpt: Option[String] = None) extends StringRegexExpression {
 
 Review comment:
   OK. I will change it.


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:
us...@infra.apache.org


With regards,
Apache Git Services

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



[GitHub] [spark] beliefer commented on a change in pull request #25001: [SPARK-28083][SQL] Support LIKE ... ESCAPE syntax

2019-07-04 Thread GitBox
beliefer commented on a change in pull request #25001: [SPARK-28083][SQL] 
Support LIKE ... ESCAPE syntax
URL: https://github.com/apache/spark/pull/25001#discussion_r300519991
 
 

 ##
 File path: 
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/parser/AstBuilder.scala
 ##
 @@ -1240,7 +1240,9 @@ class AstBuilder(conf: SQLConf) extends 
SqlBaseBaseVisitor[AnyRef] with Logging
   case SqlBaseParser.IN =>
 invertIfNotDefined(In(e, ctx.expression.asScala.map(expression)))
   case SqlBaseParser.LIKE =>
-invertIfNotDefined(Like(e, expression(ctx.pattern)))
+val escapeOpt = Option(ctx.escapeChar).map(_.getText)
+val like = Like(e, expression(ctx.pattern), escapeOpt)
+invertIfNotDefined(like)
 
 Review comment:
   A good idea. I will treat it in `escapeLikeRegex`.


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:
us...@infra.apache.org


With regards,
Apache Git Services

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



[GitHub] [spark] beliefer commented on a change in pull request #25001: [SPARK-28083][SQL] Support LIKE ... ESCAPE syntax

2019-07-04 Thread GitBox
beliefer commented on a change in pull request #25001: [SPARK-28083][SQL] 
Support LIKE ... ESCAPE syntax
URL: https://github.com/apache/spark/pull/25001#discussion_r300519991
 
 

 ##
 File path: 
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/parser/AstBuilder.scala
 ##
 @@ -1240,7 +1240,9 @@ class AstBuilder(conf: SQLConf) extends 
SqlBaseBaseVisitor[AnyRef] with Logging
   case SqlBaseParser.IN =>
 invertIfNotDefined(In(e, ctx.expression.asScala.map(expression)))
   case SqlBaseParser.LIKE =>
-invertIfNotDefined(Like(e, expression(ctx.pattern)))
+val escapeOpt = Option(ctx.escapeChar).map(_.getText)
+val like = Like(e, expression(ctx.pattern), escapeOpt)
+invertIfNotDefined(like)
 
 Review comment:
   A good idea. I will treat it in escapeLikeRegex.


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:
us...@infra.apache.org


With regards,
Apache Git Services

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



[GitHub] [spark] beliefer commented on a change in pull request #25001: [SPARK-28083][SQL] Support LIKE ... ESCAPE syntax

2019-07-04 Thread GitBox
beliefer commented on a change in pull request #25001: [SPARK-28083][SQL] 
Support LIKE ... ESCAPE syntax
URL: https://github.com/apache/spark/pull/25001#discussion_r300519867
 
 

 ##
 File path: 
sql/catalyst/src/main/antlr4/org/apache/spark/sql/catalyst/parser/SqlBase.g4
 ##
 @@ -662,7 +662,8 @@ predicate
 : NOT? kind=BETWEEN lower=valueExpression AND upper=valueExpression
 | NOT? kind=IN '(' expression (',' expression)* ')'
 | NOT? kind=IN '(' query ')'
-| NOT? kind=(RLIKE | LIKE) pattern=valueExpression
+| NOT? kind=RLIKE pattern=valueExpression
+| NOT? kind=LIKE pattern=valueExpression (ESCAPE 
escapeChar=valueExpression)?
 
 Review comment:
   OK. I forgot it.


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:
us...@infra.apache.org


With regards,
Apache Git Services

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



[GitHub] [spark] beliefer commented on a change in pull request #25001: [SPARK-28083][SQL] Support LIKE ... ESCAPE syntax

2019-07-04 Thread GitBox
beliefer commented on a change in pull request #25001: [SPARK-28083][SQL] 
Support LIKE ... ESCAPE syntax
URL: https://github.com/apache/spark/pull/25001#discussion_r300344388
 
 

 ##
 File path: 
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/expressions/regexpExpressions.scala
 ##
 @@ -65,6 +65,59 @@ abstract class StringRegexExpression extends 
BinaryExpression
   override def sql: String = s"${left.sql} 
${prettyName.toUpperCase(Locale.ROOT)} ${right.sql}"
 }
 
+abstract class StringRegexV2Expression extends TernaryExpression
 
 Review comment:
   I changed 
   `val escapeChar = escapeCharOpt.getOrElse("")`
   to
   `val escapeChar = escapeCharOpt.getOrElse("")`
   The latter is OK.


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:
us...@infra.apache.org


With regards,
Apache Git Services

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



[GitHub] [spark] beliefer commented on a change in pull request #25001: [SPARK-28083][SQL] Support LIKE ... ESCAPE syntax

2019-07-04 Thread GitBox
beliefer commented on a change in pull request #25001: [SPARK-28083][SQL] 
Support LIKE ... ESCAPE syntax
URL: https://github.com/apache/spark/pull/25001#discussion_r300294229
 
 

 ##
 File path: 
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/expressions/regexpExpressions.scala
 ##
 @@ -65,6 +65,59 @@ abstract class StringRegexExpression extends 
BinaryExpression
   override def sql: String = s"${left.sql} 
${prettyName.toUpperCase(Locale.ROOT)} ${right.sql}"
 }
 
+abstract class StringRegexV2Expression extends TernaryExpression
 
 Review comment:
   
   ```
 val pattern = ctx.freshName("pattern")
 val rightStr = ctx.freshName("rightStr")
 val escapeChar = escapeCharOpt.getOrElse("")
 nullSafeCodeGen(ctx, ev, (eval1, eval2) => {
   s"""
 String $rightStr = $eval2.toString();
 $patternClass $pattern = 
$patternClass.compile($escapeFunc($rightStr, "$escapeChar"));
 ${ev.value} = $pattern.matcher($eval1.toString()).matches();
   """
 })
   ```
   


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:
us...@infra.apache.org


With regards,
Apache Git Services

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



[GitHub] [spark] beliefer commented on a change in pull request #25001: [SPARK-28083][SQL] Support LIKE ... ESCAPE syntax

2019-07-04 Thread GitBox
beliefer commented on a change in pull request #25001: [SPARK-28083][SQL] 
Support LIKE ... ESCAPE syntax
URL: https://github.com/apache/spark/pull/25001#discussion_r300294229
 
 

 ##
 File path: 
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/expressions/regexpExpressions.scala
 ##
 @@ -65,6 +65,59 @@ abstract class StringRegexExpression extends 
BinaryExpression
   override def sql: String = s"${left.sql} 
${prettyName.toUpperCase(Locale.ROOT)} ${right.sql}"
 }
 
+abstract class StringRegexV2Expression extends TernaryExpression
 
 Review comment:
   
   ```
val pattern = ctx.freshName("pattern")
 val rightStr = ctx.freshName("rightStr")
 val escapeChar = escapeCharOpt.getOrElse("")
 nullSafeCodeGen(ctx, ev, (eval1, eval2) => {
   s"""
 String $rightStr = $eval2.toString();
 $patternClass $pattern = 
$patternClass.compile($escapeFunc($rightStr, "$escapeChar"));
 ${ev.value} = $pattern.matcher($eval1.toString()).matches();
   """
 })
   ```
   


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:
us...@infra.apache.org


With regards,
Apache Git Services

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



[GitHub] [spark] beliefer commented on a change in pull request #25001: [SPARK-28083][SQL] Support LIKE ... ESCAPE syntax

2019-07-04 Thread GitBox
beliefer commented on a change in pull request #25001: [SPARK-28083][SQL] 
Support LIKE ... ESCAPE syntax
URL: https://github.com/apache/spark/pull/25001#discussion_r300294229
 
 

 ##
 File path: 
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/expressions/regexpExpressions.scala
 ##
 @@ -65,6 +65,59 @@ abstract class StringRegexExpression extends 
BinaryExpression
   override def sql: String = s"${left.sql} 
${prettyName.toUpperCase(Locale.ROOT)} ${right.sql}"
 }
 
+abstract class StringRegexV2Expression extends TernaryExpression
 
 Review comment:
```
val pattern = ctx.freshName("pattern")
 val rightStr = ctx.freshName("rightStr")
 val escapeChar = escapeCharOpt.getOrElse("")
 nullSafeCodeGen(ctx, ev, (eval1, eval2) => {
   s"""
 String $rightStr = $eval2.toString();
 $patternClass $pattern = 
$patternClass.compile($escapeFunc($rightStr, "$escapeChar"));
 ${ev.value} = $pattern.matcher($eval1.toString()).matches();
   """
 })
   ```


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:
us...@infra.apache.org


With regards,
Apache Git Services

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



[GitHub] [spark] beliefer commented on a change in pull request #25001: [SPARK-28083][SQL] Support LIKE ... ESCAPE syntax

2019-07-04 Thread GitBox
beliefer commented on a change in pull request #25001: [SPARK-28083][SQL] 
Support LIKE ... ESCAPE syntax
URL: https://github.com/apache/spark/pull/25001#discussion_r300293513
 
 

 ##
 File path: 
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/expressions/regexpExpressions.scala
 ##
 @@ -65,6 +65,59 @@ abstract class StringRegexExpression extends 
BinaryExpression
   override def sql: String = s"${left.sql} 
${prettyName.toUpperCase(Locale.ROOT)} ${right.sql}"
 }
 
+abstract class StringRegexV2Expression extends TernaryExpression
 
 Review comment:
   @maropu I have made this try. It was not pass the tests of 
`RegexpExpressionsSuite`.
   The failure info:
   ```
   - LIKE Pattern *** FAILED ***
 Code generation of null LIKE input[0, string, true] ESCAPE \ failed:
   
 java.util.concurrent.ExecutionException: 
org.codehaus.commons.compiler.CompileException: File 'generated.java', Line 50, 
Column 0: failed to compile: org.codehaus.commons.compiler.CompileException: 
File 'generated.java', Line 50, Column 0: Line break in literal not allowed
   
 java.util.concurrent.ExecutionException: 
org.codehaus.commons.compiler.CompileException: File 'generated.java', Line 50, 
Column 0: failed to compile: org.codehaus.commons.compiler.CompileException: 
File 'generated.java', Line 50, Column 0: Line break in literal not allowed
   ```
   
   The code generated:
   ```
   /* 033 */   public java.lang.Object apply(java.lang.Object _i) {
   /* 034 */ InternalRow i = (InternalRow) _i;
   /* 035 */
   /* 036 */
   /* 037 */ boolean isNull_0 = true;
   /* 038 */ boolean value_0 = false;
   /* 039 */
   /* 040 */ if (!true) {
   /* 041 */   boolean isNull_2 = i.isNullAt(0);
   /* 042 */   UTF8String value_2 = isNull_2 ?
   /* 043 */   null : (i.getUTF8String(0));
   /* 044 */   if (!isNull_2) {
   /* 045 */
   /* 046 */ isNull_0 = false; // resultCode could change nullability.
   /* 047 */
   /* 048 */ String rightStr_0 = value_2.toString();
   /* 049 */ java.util.regex.Pattern pattern_0 = 
java.util.regex.Pattern.compile(org.apache.spark.sql.catalyst.util.StringUtils.escapeLikeRegex(rightStr_0,
 "\"));
   /* 050 */ value_0 = 
pattern_0.matcher(((UTF8String)null).toString()).matches();
   /* 051 */
   /* 052 */
   /* 053 */   }
   /* 054 */
   /* 055 */ }
   /* 056 */ isNull_3 = isNull_0;
   /* 057 */ value_3 = value_0;
   /* 058 */
   /* 059 */ // copy all the results into MutableRow
   /* 060 */
   /* 061 */ if (!isNull_3) {
   /* 062 */   mutableRow.setBoolean(0, value_3);
   /* 063 */ } else {
   /* 064 */   mutableRow.setNullAt(0);
   /* 065 */ }
   /* 066 */
   /* 067 */ return mutableRow;
   /* 068 */   }
   /* 069 */
   /* 070 */
   ```


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:
us...@infra.apache.org


With regards,
Apache Git Services

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



[GitHub] [spark] beliefer commented on a change in pull request #25001: [SPARK-28083][SQL] Support LIKE ... ESCAPE syntax

2019-07-03 Thread GitBox
beliefer commented on a change in pull request #25001: [SPARK-28083][SQL] 
Support LIKE ... ESCAPE syntax
URL: https://github.com/apache/spark/pull/25001#discussion_r300205231
 
 

 ##
 File path: docs/sql-keywords.md
 ##
 @@ -103,6 +103,7 @@ Below is a list of all the keywords in Spark SQL.
   
DROPnon-reservednon-reservedreserved
   ELSEreservednon-reservedreserved
   ENDreservednon-reservedreserved
+  
ESCAPEnon-reservednon-reservedreserved
 
 Review comment:
   Thanks for your reminder. @maropu 


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:
us...@infra.apache.org


With regards,
Apache Git Services

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



[GitHub] [spark] beliefer commented on a change in pull request #25001: [SPARK-28083][SQL] Support LIKE ... ESCAPE syntax

2019-07-03 Thread GitBox
beliefer commented on a change in pull request #25001: [SPARK-28083][SQL] 
Support LIKE ... ESCAPE syntax
URL: https://github.com/apache/spark/pull/25001#discussion_r300205125
 
 

 ##
 File path: 
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/expressions/regexpExpressions.scala
 ##
 @@ -65,6 +65,59 @@ abstract class StringRegexExpression extends 
BinaryExpression
   override def sql: String = s"${left.sql} 
${prettyName.toUpperCase(Locale.ROOT)} ${right.sql}"
 }
 
+abstract class StringRegexV2Expression extends TernaryExpression
 
 Review comment:
   OK, let me have a try!


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:
us...@infra.apache.org


With regards,
Apache Git Services

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