Skip to content

[SQL][Minor] make StringComparison extends ExpectsInputTypes #5905

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ case class Lower(child: Expression) extends UnaryExpression with CaseConversionE
}

/** A base trait for functions that compare two strings, returning a boolean. */
trait StringComparison {
trait StringComparison extends ExpectsInputTypes {
self: BinaryExpression =>

def compare(l: UTF8String, r: UTF8String): Boolean
Expand All @@ -163,6 +163,8 @@ trait StringComparison {

override def nullable: Boolean = left.nullable || right.nullable

override def expectedChildTypes: Seq[DataType] = Seq(StringType, StringType)

override def eval(input: Row): Any = {
val leftEval = left.eval(input)
if(leftEval == null) {
Expand All @@ -183,27 +185,24 @@ trait StringComparison {
* A function that returns true if the string `left` contains the string `right`.
*/
case class Contains(left: Expression, right: Expression)
extends BinaryExpression with Predicate with StringComparison with ExpectsInputTypes {
extends BinaryExpression with Predicate with StringComparison {
override def compare(l: UTF8String, r: UTF8String): Boolean = l.contains(r)
override def expectedChildTypes: Seq[DataType] = Seq(StringType, StringType)
}

/**
* A function that returns true if the string `left` starts with the string `right`.
*/
case class StartsWith(left: Expression, right: Expression)
extends BinaryExpression with Predicate with StringComparison with ExpectsInputTypes {
extends BinaryExpression with Predicate with StringComparison {
override def compare(l: UTF8String, r: UTF8String): Boolean = l.startsWith(r)
override def expectedChildTypes: Seq[DataType] = Seq(StringType, StringType)
}

/**
* A function that returns true if the string `left` ends with the string `right`.
*/
case class EndsWith(left: Expression, right: Expression)
extends BinaryExpression with Predicate with StringComparison with ExpectsInputTypes {
extends BinaryExpression with Predicate with StringComparison {
override def compare(l: UTF8String, r: UTF8String): Boolean = l.endsWith(r)
override def expectedChildTypes: Seq[DataType] = Seq(StringType, StringType)
}

/**
Expand Down