Skip to content

Commit

Permalink
address comments
Browse files Browse the repository at this point in the history
  • Loading branch information
yjshen committed Aug 3, 2015
1 parent 4fa5de0 commit 3dee204
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 40 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ package org.apache.spark.sql.catalyst.expressions

import org.apache.spark.SparkFunSuite
import org.apache.spark.sql.catalyst.dsl.expressions._
import org.apache.spark.sql.types.{LongType, Decimal}
import org.apache.spark.sql.types._

class ArithmeticExpressionSuite extends SparkFunSuite with ExpressionEvalHelper {

Expand Down Expand Up @@ -56,7 +56,10 @@ class ArithmeticExpressionSuite extends SparkFunSuite with ExpressionEvalHelper
checkEvaluation(UnaryMinus(input), convert(-1))
checkEvaluation(UnaryMinus(Literal.create(null, dataType)), null)
}
checkEvaluation(UnaryMinus(Literal.create(Long.MinValue, LongType)), Long.MinValue)
checkEvaluation(UnaryMinus(Literal(Long.MinValue)), Long.MinValue)
checkEvaluation(UnaryMinus(Literal(Int.MinValue)), Int.MinValue)
checkEvaluation(UnaryMinus(Literal(Short.MinValue)), Short.MinValue)
checkEvaluation(UnaryMinus(Literal(Byte.MinValue)), Byte.MinValue)
}

test("- (Minus)") {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -136,60 +136,60 @@ class PredicateSuite extends SparkFunSuite with ExpressionEvalHelper {
checkEvaluation(And(InSet(one, hS), InSet(two, hS)), true)
}

private val smallValues = Seq(1, Decimal(1), Array(1.toByte), "a", 0f, 0d).map(Literal(_))
private val smallValues = Seq(1, Decimal(1), Array(1.toByte), "a", 0f, 0d, false).map(Literal(_))
private val largeValues =
Seq(2, Decimal(2), Array(2.toByte), "b", Float.NaN, Double.NaN).map(Literal(_))
Seq(2, Decimal(2), Array(2.toByte), "b", Float.NaN, Double.NaN, true).map(Literal(_))

private val equalValues1 =
Seq(1, Decimal(1), Array(1.toByte), "a", Float.NaN, Double.NaN).map(Literal(_))
Seq(1, Decimal(1), Array(1.toByte), "a", Float.NaN, Double.NaN, true).map(Literal(_))
private val equalValues2 =
Seq(1, Decimal(1), Array(1.toByte), "a", Float.NaN, Double.NaN).map(Literal(_))
Seq(1, Decimal(1), Array(1.toByte), "a", Float.NaN, Double.NaN, true).map(Literal(_))

test("BinaryComparison: <") {
test("BinaryComparison: lessThan") {
for (i <- 0 until smallValues.length) {
checkEvaluation(smallValues(i) < largeValues(i), true)
checkEvaluation(equalValues1(i) < equalValues2(i), false)
checkEvaluation(largeValues(i) < smallValues(i), false)
checkEvaluation(LessThan(smallValues(i), largeValues(i)), true)
checkEvaluation(LessThan(equalValues1(i), equalValues2(i)), false)
checkEvaluation(LessThan(largeValues(i), smallValues(i)), false)
}
}

test("BinaryComparison: <=") {
test("BinaryComparison: LessThanOrEqual") {
for (i <- 0 until smallValues.length) {
checkEvaluation(smallValues(i) <= largeValues(i), true)
checkEvaluation(equalValues1(i) <= equalValues2(i), true)
checkEvaluation(largeValues(i) <= smallValues(i), false)
checkEvaluation(LessThanOrEqual(smallValues(i), largeValues(i)), true)
checkEvaluation(LessThanOrEqual(equalValues1(i), equalValues2(i)), true)
checkEvaluation(LessThanOrEqual(largeValues(i), smallValues(i)), false)
}
}

test("BinaryComparison: >") {
test("BinaryComparison: GreaterThan") {
for (i <- 0 until smallValues.length) {
checkEvaluation(smallValues(i) > largeValues(i), false)
checkEvaluation(equalValues1(i) > equalValues2(i), false)
checkEvaluation(largeValues(i) > smallValues(i), true)
checkEvaluation(GreaterThan(smallValues(i), largeValues(i)), false)
checkEvaluation(GreaterThan(equalValues1(i), equalValues2(i)), false)
checkEvaluation(GreaterThan(largeValues(i), smallValues(i)), true)
}
}

test("BinaryComparison: >=") {
test("BinaryComparison: GreaterThanOrEqual") {
for (i <- 0 until smallValues.length) {
checkEvaluation(smallValues(i) >= largeValues(i), false)
checkEvaluation(equalValues1(i) >= equalValues2(i), true)
checkEvaluation(largeValues(i) >= smallValues(i), true)
checkEvaluation(GreaterThanOrEqual(smallValues(i), largeValues(i)), false)
checkEvaluation(GreaterThanOrEqual(equalValues1(i), equalValues2(i)), true)
checkEvaluation(GreaterThanOrEqual(largeValues(i), smallValues(i)), true)
}
}

test("BinaryComparison: ===") {
test("BinaryComparison: EqualTo") {
for (i <- 0 until smallValues.length) {
checkEvaluation(smallValues(i) === largeValues(i), false)
checkEvaluation(equalValues1(i) === equalValues2(i), true)
checkEvaluation(largeValues(i) === smallValues(i), false)
checkEvaluation(EqualTo(smallValues(i), largeValues(i)), false)
checkEvaluation(EqualTo(equalValues1(i), equalValues2(i)), true)
checkEvaluation(EqualTo(largeValues(i), smallValues(i)), false)
}
}

test("BinaryComparison: <=>") {
test("BinaryComparison: EqualNullSafe") {
for (i <- 0 until smallValues.length) {
checkEvaluation(smallValues(i) <=> largeValues(i), false)
checkEvaluation(equalValues1(i) <=> equalValues2(i), true)
checkEvaluation(largeValues(i) <=> smallValues(i), false)
checkEvaluation(EqualNullSafe(smallValues(i), largeValues(i)), false)
checkEvaluation(EqualNullSafe(equalValues1(i), equalValues2(i)), true)
checkEvaluation(EqualNullSafe(largeValues(i), smallValues(i)), false)
}
}

Expand All @@ -209,15 +209,8 @@ class PredicateSuite extends SparkFunSuite with ExpressionEvalHelper {
nullTest(GreaterThanOrEqual)
nullTest(EqualTo)

checkEvaluation(normalInt <=> nullInt, false)
checkEvaluation(nullInt <=> normalInt, false)
checkEvaluation(nullInt <=> nullInt, true)
}

test("BinaryComparison: boolean input") {
checkEvaluation(LessThan(Literal(true), Literal(false)), false)
checkEvaluation(LessThanOrEqual(Literal(true), Literal(false)), false)
checkEvaluation(GreaterThan(Literal(true), Literal(false)), true)
checkEvaluation(GreaterThanOrEqual(Literal(true), Literal(false)), true)
checkEvaluation(EqualNullSafe(normalInt, nullInt), false)
checkEvaluation(EqualNullSafe(nullInt, normalInt), false)
checkEvaluation(EqualNullSafe(nullInt, nullInt), true)
}
}

0 comments on commit 3dee204

Please sign in to comment.