cloud-fan commented on a change in pull request #34848:
URL: https://github.com/apache/spark/pull/34848#discussion_r814585390
##########
File path:
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/expressions/stringExpressions.scala
##########
@@ -468,13 +469,63 @@ abstract class StringPredicate extends BinaryExpression
override def toString: String = s"$nodeName($left, $right)"
}
-/**
- * A function that returns true if the string `left` contains the string
`right`.
- */
+trait StringBinaryPredicateExpressionBuilderBase extends ExpressionBuilder {
+ override def build(funcName: String, expressions: Seq[Expression]):
Expression = {
+ val numArgs = expressions.length
+ if (numArgs == 2) {
+ if (expressions(0).dataType == BinaryType && expressions(1).dataType ==
BinaryType) {
+ BinaryPredicate(funcName, expressions(0), expressions(1))
+ } else {
+ createStringPredicate(expressions(0), expressions(1))
+ }
+ } else {
+ throw QueryCompilationErrors.invalidFunctionArgumentNumberError(Seq(2),
funcName, numArgs)
+ }
+ }
+
+ protected def createStringPredicate(left: Expression, right: Expression):
Expression
+}
+
+object StringPredicate {
+ def unapply(expr: Expression): Option[Expression] = expr match {
+ case _: StringPredicate => Some(expr)
+ case s @ StaticInvoke(clz, _, "contains" | "startsWith" | "endsWith",
Seq(_, _), _, _, _, _)
+ if clz == classOf[ByteArrayMethods] => Some(s)
+ case _ => None
+ }
+}
+
+case class BinaryPredicate(override val prettyName: String, left: Expression,
right: Expression)
+ extends RuntimeReplaceable with ImplicitCastInputTypes with
BinaryLike[Expression] {
+
+ private lazy val realFuncName = prettyName match {
+ case "startswith" => "startsWith"
+ case "endswith" => "endsWith"
+ case name => name
+ }
+
+ override lazy val replacement =
+ StaticInvoke(
Review comment:
nit: indentation
##########
File path:
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/expressions/stringExpressions.scala
##########
@@ -468,13 +469,63 @@ abstract class StringPredicate extends BinaryExpression
override def toString: String = s"$nodeName($left, $right)"
}
-/**
- * A function that returns true if the string `left` contains the string
`right`.
- */
+trait StringBinaryPredicateExpressionBuilderBase extends ExpressionBuilder {
+ override def build(funcName: String, expressions: Seq[Expression]):
Expression = {
+ val numArgs = expressions.length
+ if (numArgs == 2) {
+ if (expressions(0).dataType == BinaryType && expressions(1).dataType ==
BinaryType) {
+ BinaryPredicate(funcName, expressions(0), expressions(1))
+ } else {
+ createStringPredicate(expressions(0), expressions(1))
+ }
+ } else {
+ throw QueryCompilationErrors.invalidFunctionArgumentNumberError(Seq(2),
funcName, numArgs)
+ }
+ }
+
+ protected def createStringPredicate(left: Expression, right: Expression):
Expression
+}
+
+object StringPredicate {
+ def unapply(expr: Expression): Option[Expression] = expr match {
+ case _: StringPredicate => Some(expr)
+ case s @ StaticInvoke(clz, _, "contains" | "startsWith" | "endsWith",
Seq(_, _), _, _, _, _)
+ if clz == classOf[ByteArrayMethods] => Some(s)
+ case _ => None
+ }
+}
+
+case class BinaryPredicate(override val prettyName: String, left: Expression,
right: Expression)
+ extends RuntimeReplaceable with ImplicitCastInputTypes with
BinaryLike[Expression] {
+
+ private lazy val realFuncName = prettyName match {
+ case "startswith" => "startsWith"
+ case "endswith" => "endsWith"
+ case name => name
+ }
+
+ override lazy val replacement =
+ StaticInvoke(
+ classOf[ByteArrayMethods],
+ BooleanType,
+ realFuncName,
+ Seq(left, right),
+ Seq(BinaryType, BinaryType))
+
+ override def inputTypes: Seq[AbstractDataType] = Seq(BinaryType, BinaryType)
+
+ override protected def withNewChildrenInternal(
+ newLeft: Expression,
Review comment:
ditto
--
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.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]