beliefer commented on a change in pull request #29999:
URL: https://github.com/apache/spark/pull/29999#discussion_r505203318
##########
File path:
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/expressions/regexpExpressions.scala
##########
@@ -176,6 +177,125 @@ case class Like(left: Expression, right: Expression,
escapeChar: Char)
}
}
+abstract class LikeAllBase extends Expression with ImplicitCastInputTypes with
NullIntolerant {
+ def value: Expression = children.head
+ def list: Seq[Expression] = children.tail
+ def isNot: Boolean
+
+ override def inputTypes: Seq[AbstractDataType] = {
+ StringType +: Seq.fill(children.size - 1)(StringType)
+ }
+
+ override def dataType: DataType = BooleanType
+
+ override def foldable: Boolean = children.forall(_.foldable)
+
+ override def nullable: Boolean = true
+
+ def matches(regex: Pattern, str: String): Boolean =
regex.matcher(str).matches()
+
+ override def eval(input: InternalRow): Any = {
+ val evaluatedValue = value.eval(input)
+ if (evaluatedValue == null) {
+ null
+ } else {
+ var hasNull = false
+ var match = true
Review comment:
OK
##########
File path:
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/expressions/regexpExpressions.scala
##########
@@ -176,6 +177,125 @@ case class Like(left: Expression, right: Expression,
escapeChar: Char)
}
}
+abstract class LikeAllBase extends Expression with ImplicitCastInputTypes with
NullIntolerant {
+ def value: Expression = children.head
+ def list: Seq[Expression] = children.tail
+ def isNot: Boolean
+
+ override def inputTypes: Seq[AbstractDataType] = {
+ StringType +: Seq.fill(children.size - 1)(StringType)
+ }
+
+ override def dataType: DataType = BooleanType
+
+ override def foldable: Boolean = children.forall(_.foldable)
+
+ override def nullable: Boolean = true
+
+ def matches(regex: Pattern, str: String): Boolean =
regex.matcher(str).matches()
+
+ override def eval(input: InternalRow): Any = {
+ val evaluatedValue = value.eval(input)
+ if (evaluatedValue == null) {
+ null
+ } else {
+ var hasNull = false
+ var match = true
+ list.foreach { e =>
+ val str = e.eval(input)
+ if (str == null) {
+ hasNull = true
+ } else {
+ val regex =
+
Pattern.compile(StringUtils.escapeLikeRegex(str.asInstanceOf[UTF8String].toString,
'\\'))
+ if ((isNot && matches(regex,
evaluatedValue.asInstanceOf[UTF8String].toString)) ||
+ !(isNot || matches(regex,
evaluatedValue.asInstanceOf[UTF8String].toString)) {
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:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]