AngersZhuuuu commented on a change in pull request #34848:
URL: https://github.com/apache/spark/pull/34848#discussion_r784600216
##########
File path:
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/expressions/stringExpressions.scala
##########
@@ -450,22 +451,49 @@ case class Lower(child: Expression)
override protected def withNewChildInternal(newChild: Expression): Lower =
copy(child = newChild)
}
-/** A base trait for functions that compare two strings, returning a boolean.
*/
-abstract class StringPredicate extends BinaryExpression
+/** A base trait for functions that compare two strings or binaries, returning
a boolean. */
+abstract class StringBinaryPredicate[T] extends BinaryExpression
with Predicate with ImplicitCastInputTypes with NullIntolerant {
- def compare(l: UTF8String, r: UTF8String): Boolean
-
- override def inputTypes: Seq[DataType] = Seq(StringType, StringType)
+ def compare(l: T, r: T): Boolean
protected override def nullSafeEval(input1: Any, input2: Any): Any =
- compare(input1.asInstanceOf[UTF8String], input2.asInstanceOf[UTF8String])
+ compare(input1.asInstanceOf[T], input2.asInstanceOf[T])
override def toString: String = s"$nodeName($left, $right)"
}
+trait StringBinaryPredicateExpressionBuilderBase extends ExpressionBuilder {
+ override def build(expressions: Seq[Expression]): Expression = {
+ val numArgs = expressions.length
+ if (numArgs == 2) {
+ if (expressions(0).dataType == BinaryType && expressions(1).dataType ==
BinaryType) {
+ createBinaryPredicate(expressions(0), expressions(1))
+ } else {
+ createStringPredicate(expressions(0), expressions(1))
+ }
+ } else {
+ throw QueryCompilationErrors.invalidFunctionArgumentNumberError(Seq(2),
funcName, numArgs)
+ }
+ }
+
+ protected def funcName: String
+ protected def createBinaryPredicate(left: Expression, right: Expression):
Expression
+ protected def createStringPredicate(left: Expression, right: Expression):
Expression
+}
+
+abstract class StringBinaryRuntimeReplaceable(left: Expression, right:
Expression)
+ extends RuntimeReplaceable {
+ def copyChildren(left: Expression, right: Expression):
StringBinaryRuntimeReplaceable
+}
+
+object StringBinaryRuntimeReplaceable {
+ def unapply(e: StringBinaryRuntimeReplaceable): Option[(Expression,
Expression)] =
Review comment:
How about current?
--
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]