aboutsummaryrefslogtreecommitdiff
path: root/sql
diff options
context:
space:
mode:
authorTakuya UESHIN <ueshin@happy-camper.st>2014-05-08 15:31:47 -0700
committerPatrick Wendell <pwendell@gmail.com>2014-05-08 15:31:47 -0700
commit322b1808d21143dc323493203929488d69e8878a (patch)
treec1482ac932215e24654779c4dc1435e70fcbc960 /sql
parent5c5e7d5809d337ce41a7a90eb9201e12803aba48 (diff)
downloadspark-322b1808d21143dc323493203929488d69e8878a.tar.gz
spark-322b1808d21143dc323493203929488d69e8878a.tar.bz2
spark-322b1808d21143dc323493203929488d69e8878a.zip
[SPARK-1754] [SQL] Add missing arithmetic DSL operations.
Add missing arithmetic DSL operations: `unary_-`, `%`. Author: Takuya UESHIN <ueshin@happy-camper.st> Closes #689 from ueshin/issues/SPARK-1754 and squashes the following commits: a09ef69 [Takuya UESHIN] Add also missing ! (not) operation. f73ae2c [Takuya UESHIN] Remove redundant tests. 5b3f087 [Takuya UESHIN] Add tests relating DSL operations. e09c5b8 [Takuya UESHIN] Add missing arithmetic DSL operations.
Diffstat (limited to 'sql')
-rw-r--r--sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/dsl/package.scala4
-rw-r--r--sql/catalyst/src/test/scala/org/apache/spark/sql/catalyst/expressions/ExpressionEvaluationSuite.scala16
2 files changed, 19 insertions, 1 deletions
diff --git a/sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/dsl/package.scala b/sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/dsl/package.scala
index dc83485df1..78d3a1d809 100644
--- a/sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/dsl/package.scala
+++ b/sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/dsl/package.scala
@@ -57,10 +57,14 @@ package object dsl {
trait ImplicitOperators {
def expr: Expression
+ def unary_- = UnaryMinus(expr)
+ def unary_! = Not(expr)
+
def + (other: Expression) = Add(expr, other)
def - (other: Expression) = Subtract(expr, other)
def * (other: Expression) = Multiply(expr, other)
def / (other: Expression) = Divide(expr, other)
+ def % (other: Expression) = Remainder(expr, other)
def && (other: Expression) = And(expr, other)
def || (other: Expression) = Or(expr, other)
diff --git a/sql/catalyst/src/test/scala/org/apache/spark/sql/catalyst/expressions/ExpressionEvaluationSuite.scala b/sql/catalyst/src/test/scala/org/apache/spark/sql/catalyst/expressions/ExpressionEvaluationSuite.scala
index 91605d0a26..344d8a304f 100644
--- a/sql/catalyst/src/test/scala/org/apache/spark/sql/catalyst/expressions/ExpressionEvaluationSuite.scala
+++ b/sql/catalyst/src/test/scala/org/apache/spark/sql/catalyst/expressions/ExpressionEvaluationSuite.scala
@@ -61,7 +61,7 @@ class ExpressionEvaluationSuite extends FunSuite {
test("3VL Not") {
notTrueTable.foreach {
case (v, answer) =>
- val expr = Not(Literal(v, BooleanType))
+ val expr = ! Literal(v, BooleanType)
val result = expr.eval(null)
if (result != answer)
fail(s"$expr should not evaluate to $result, expected: $answer") }
@@ -381,6 +381,13 @@ class ExpressionEvaluationSuite extends FunSuite {
checkEvaluation(Add(c1, Literal(null, IntegerType)), null, row)
checkEvaluation(Add(Literal(null, IntegerType), c2), null, row)
checkEvaluation(Add(Literal(null, IntegerType), Literal(null, IntegerType)), null, row)
+
+ checkEvaluation(-c1, -1, row)
+ checkEvaluation(c1 + c2, 3, row)
+ checkEvaluation(c1 - c2, -1, row)
+ checkEvaluation(c1 * c2, 2, row)
+ checkEvaluation(c1 / c2, 0, row)
+ checkEvaluation(c1 % c2, 1, row)
}
test("BinaryComparison") {
@@ -395,6 +402,13 @@ class ExpressionEvaluationSuite extends FunSuite {
checkEvaluation(LessThan(c1, Literal(null, IntegerType)), null, row)
checkEvaluation(LessThan(Literal(null, IntegerType), c2), null, row)
checkEvaluation(LessThan(Literal(null, IntegerType), Literal(null, IntegerType)), null, row)
+
+ checkEvaluation(c1 < c2, true, row)
+ checkEvaluation(c1 <= c2, true, row)
+ checkEvaluation(c1 > c2, false, row)
+ checkEvaluation(c1 >= c2, false, row)
+ checkEvaluation(c1 === c2, false, row)
+ checkEvaluation(c1 !== c2, true, row)
}
}