Repository: spark Updated Branches: refs/heads/master fec7b29f5 -> 3059291e2
[SQL][Minor] make StringComparison extends ExpectsInputTypes make StringComparison extends ExpectsInputTypes and added expectedChildTypes, so do not need override expectedChildTypes in each subclass Author: wangfei <[email protected]> Closes #5905 from scwf/ExpectsInputTypes and squashes the following commits: b374ddf [wangfei] make stringcomparison extends ExpectsInputTypes Project: http://git-wip-us.apache.org/repos/asf/spark/repo Commit: http://git-wip-us.apache.org/repos/asf/spark/commit/3059291e Tree: http://git-wip-us.apache.org/repos/asf/spark/tree/3059291e Diff: http://git-wip-us.apache.org/repos/asf/spark/diff/3059291e Branch: refs/heads/master Commit: 3059291e2027fb3ebbb2d3376610ce450f7c15a3 Parents: fec7b29 Author: wangfei <[email protected]> Authored: Tue May 5 14:24:37 2015 -0700 Committer: Reynold Xin <[email protected]> Committed: Tue May 5 14:24:37 2015 -0700 ---------------------------------------------------------------------- .../sql/catalyst/expressions/stringOperations.scala | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/spark/blob/3059291e/sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/expressions/stringOperations.scala ---------------------------------------------------------------------- diff --git a/sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/expressions/stringOperations.scala b/sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/expressions/stringOperations.scala index d6f23df..7683e09 100644 --- a/sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/expressions/stringOperations.scala +++ b/sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/expressions/stringOperations.scala @@ -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 @@ -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) { @@ -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) } /** --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
