aboutsummaryrefslogtreecommitdiff
path: root/sql/catalyst/src/test
diff options
context:
space:
mode:
authorWenchen Fan <wenchen@databricks.com>2016-08-02 11:08:32 -0700
committerReynold Xin <rxin@databricks.com>2016-08-02 11:08:32 -0700
commita9beeaaaeb52e9c940fe86a3d70801655401623c (patch)
tree4d40d19b603bb5709d8f792c18dad29519856a80 /sql/catalyst/src/test
parentcbdff49357d6ce8d41b76b44628d90ead193eb5f (diff)
downloadspark-a9beeaaaeb52e9c940fe86a3d70801655401623c.tar.gz
spark-a9beeaaaeb52e9c940fe86a3d70801655401623c.tar.bz2
spark-a9beeaaaeb52e9c940fe86a3d70801655401623c.zip
[SPARK-16855][SQL] move Greatest and Least from conditionalExpressions.scala to arithmetic.scala
## What changes were proposed in this pull request? `Greatest` and `Least` are not conditional expressions, but arithmetic expressions. ## How was this patch tested? N/A Author: Wenchen Fan <wenchen@databricks.com> Closes #14460 from cloud-fan/move.
Diffstat (limited to 'sql/catalyst/src/test')
-rw-r--r--sql/catalyst/src/test/scala/org/apache/spark/sql/catalyst/expressions/ArithmeticExpressionSuite.scala107
-rw-r--r--sql/catalyst/src/test/scala/org/apache/spark/sql/catalyst/expressions/ConditionalExpressionSuite.scala107
2 files changed, 107 insertions, 107 deletions
diff --git a/sql/catalyst/src/test/scala/org/apache/spark/sql/catalyst/expressions/ArithmeticExpressionSuite.scala b/sql/catalyst/src/test/scala/org/apache/spark/sql/catalyst/expressions/ArithmeticExpressionSuite.scala
index 321d820b70..687387507e 100644
--- a/sql/catalyst/src/test/scala/org/apache/spark/sql/catalyst/expressions/ArithmeticExpressionSuite.scala
+++ b/sql/catalyst/src/test/scala/org/apache/spark/sql/catalyst/expressions/ArithmeticExpressionSuite.scala
@@ -17,7 +17,11 @@
package org.apache.spark.sql.catalyst.expressions
+import java.sql.{Date, Timestamp}
+
import org.apache.spark.SparkFunSuite
+import org.apache.spark.sql.catalyst.InternalRow
+import org.apache.spark.sql.catalyst.analysis.TypeCheckResult.TypeCheckFailure
import org.apache.spark.sql.catalyst.dsl.expressions._
import org.apache.spark.sql.types._
@@ -211,4 +215,107 @@ class ArithmeticExpressionSuite extends SparkFunSuite with ExpressionEvalHelper
checkEvaluation(Pmod(positiveInt, negativeInt), positiveInt)
checkEvaluation(Pmod(positiveLong, negativeLong), positiveLong)
}
+
+ test("function least") {
+ val row = create_row(1, 2, "a", "b", "c")
+ val c1 = 'a.int.at(0)
+ val c2 = 'a.int.at(1)
+ val c3 = 'a.string.at(2)
+ val c4 = 'a.string.at(3)
+ val c5 = 'a.string.at(4)
+ checkEvaluation(Least(Seq(c4, c3, c5)), "a", row)
+ checkEvaluation(Least(Seq(c1, c2)), 1, row)
+ checkEvaluation(Least(Seq(c1, c2, Literal(-1))), -1, row)
+ checkEvaluation(Least(Seq(c4, c5, c3, c3, Literal("a"))), "a", row)
+
+ val nullLiteral = Literal.create(null, IntegerType)
+ checkEvaluation(Least(Seq(nullLiteral, nullLiteral)), null)
+ checkEvaluation(Least(Seq(Literal(null), Literal(null))), null, InternalRow.empty)
+ checkEvaluation(Least(Seq(Literal(-1.0), Literal(2.5))), -1.0, InternalRow.empty)
+ checkEvaluation(Least(Seq(Literal(-1), Literal(2))), -1, InternalRow.empty)
+ checkEvaluation(
+ Least(Seq(Literal((-1.0).toFloat), Literal(2.5.toFloat))), (-1.0).toFloat, InternalRow.empty)
+ checkEvaluation(
+ Least(Seq(Literal(Long.MaxValue), Literal(Long.MinValue))), Long.MinValue, InternalRow.empty)
+ checkEvaluation(Least(Seq(Literal(1.toByte), Literal(2.toByte))), 1.toByte, InternalRow.empty)
+ checkEvaluation(
+ Least(Seq(Literal(1.toShort), Literal(2.toByte.toShort))), 1.toShort, InternalRow.empty)
+ checkEvaluation(Least(Seq(Literal("abc"), Literal("aaaa"))), "aaaa", InternalRow.empty)
+ checkEvaluation(Least(Seq(Literal(true), Literal(false))), false, InternalRow.empty)
+ checkEvaluation(
+ Least(Seq(
+ Literal(BigDecimal("1234567890987654321123456")),
+ Literal(BigDecimal("1234567890987654321123458")))),
+ BigDecimal("1234567890987654321123456"), InternalRow.empty)
+ checkEvaluation(
+ Least(Seq(Literal(Date.valueOf("2015-01-01")), Literal(Date.valueOf("2015-07-01")))),
+ Date.valueOf("2015-01-01"), InternalRow.empty)
+ checkEvaluation(
+ Least(Seq(
+ Literal(Timestamp.valueOf("2015-07-01 08:00:00")),
+ Literal(Timestamp.valueOf("2015-07-01 10:00:00")))),
+ Timestamp.valueOf("2015-07-01 08:00:00"), InternalRow.empty)
+
+ // Type checking error
+ assert(
+ Least(Seq(Literal(1), Literal("1"))).checkInputDataTypes() ==
+ TypeCheckFailure("The expressions should all have the same type, " +
+ "got LEAST(int, string)."))
+
+ DataTypeTestUtils.ordered.foreach { dt =>
+ checkConsistencyBetweenInterpretedAndCodegen(Least, dt, 2)
+ }
+ }
+
+ test("function greatest") {
+ val row = create_row(1, 2, "a", "b", "c")
+ val c1 = 'a.int.at(0)
+ val c2 = 'a.int.at(1)
+ val c3 = 'a.string.at(2)
+ val c4 = 'a.string.at(3)
+ val c5 = 'a.string.at(4)
+ checkEvaluation(Greatest(Seq(c4, c5, c3)), "c", row)
+ checkEvaluation(Greatest(Seq(c2, c1)), 2, row)
+ checkEvaluation(Greatest(Seq(c1, c2, Literal(2))), 2, row)
+ checkEvaluation(Greatest(Seq(c4, c5, c3, Literal("ccc"))), "ccc", row)
+
+ val nullLiteral = Literal.create(null, IntegerType)
+ checkEvaluation(Greatest(Seq(nullLiteral, nullLiteral)), null)
+ checkEvaluation(Greatest(Seq(Literal(null), Literal(null))), null, InternalRow.empty)
+ checkEvaluation(Greatest(Seq(Literal(-1.0), Literal(2.5))), 2.5, InternalRow.empty)
+ checkEvaluation(Greatest(Seq(Literal(-1), Literal(2))), 2, InternalRow.empty)
+ checkEvaluation(
+ Greatest(Seq(Literal((-1.0).toFloat), Literal(2.5.toFloat))), 2.5.toFloat, InternalRow.empty)
+ checkEvaluation(Greatest(
+ Seq(Literal(Long.MaxValue), Literal(Long.MinValue))), Long.MaxValue, InternalRow.empty)
+ checkEvaluation(
+ Greatest(Seq(Literal(1.toByte), Literal(2.toByte))), 2.toByte, InternalRow.empty)
+ checkEvaluation(
+ Greatest(Seq(Literal(1.toShort), Literal(2.toByte.toShort))), 2.toShort, InternalRow.empty)
+ checkEvaluation(Greatest(Seq(Literal("abc"), Literal("aaaa"))), "abc", InternalRow.empty)
+ checkEvaluation(Greatest(Seq(Literal(true), Literal(false))), true, InternalRow.empty)
+ checkEvaluation(
+ Greatest(Seq(
+ Literal(BigDecimal("1234567890987654321123456")),
+ Literal(BigDecimal("1234567890987654321123458")))),
+ BigDecimal("1234567890987654321123458"), InternalRow.empty)
+ checkEvaluation(Greatest(
+ Seq(Literal(Date.valueOf("2015-01-01")), Literal(Date.valueOf("2015-07-01")))),
+ Date.valueOf("2015-07-01"), InternalRow.empty)
+ checkEvaluation(
+ Greatest(Seq(
+ Literal(Timestamp.valueOf("2015-07-01 08:00:00")),
+ Literal(Timestamp.valueOf("2015-07-01 10:00:00")))),
+ Timestamp.valueOf("2015-07-01 10:00:00"), InternalRow.empty)
+
+ // Type checking error
+ assert(
+ Greatest(Seq(Literal(1), Literal("1"))).checkInputDataTypes() ==
+ TypeCheckFailure("The expressions should all have the same type, " +
+ "got GREATEST(int, string)."))
+
+ DataTypeTestUtils.ordered.foreach { dt =>
+ checkConsistencyBetweenInterpretedAndCodegen(Greatest, dt, 2)
+ }
+ }
}
diff --git a/sql/catalyst/src/test/scala/org/apache/spark/sql/catalyst/expressions/ConditionalExpressionSuite.scala b/sql/catalyst/src/test/scala/org/apache/spark/sql/catalyst/expressions/ConditionalExpressionSuite.scala
index 36185b8c63..b04ea418fb 100644
--- a/sql/catalyst/src/test/scala/org/apache/spark/sql/catalyst/expressions/ConditionalExpressionSuite.scala
+++ b/sql/catalyst/src/test/scala/org/apache/spark/sql/catalyst/expressions/ConditionalExpressionSuite.scala
@@ -17,11 +17,7 @@
package org.apache.spark.sql.catalyst.expressions
-import java.sql.{Date, Timestamp}
-
import org.apache.spark.SparkFunSuite
-import org.apache.spark.sql.catalyst.InternalRow
-import org.apache.spark.sql.catalyst.analysis.TypeCheckResult.TypeCheckFailure
import org.apache.spark.sql.catalyst.dsl.expressions._
import org.apache.spark.sql.types._
@@ -141,107 +137,4 @@ class ConditionalExpressionSuite extends SparkFunSuite with ExpressionEvalHelper
checkEvaluation(CaseKeyWhen(c6, Seq(c5, c2, c4, c3)), null, row)
checkEvaluation(CaseKeyWhen(literalNull, Seq(c2, c5, c1, c6)), null, row)
}
-
- test("function least") {
- val row = create_row(1, 2, "a", "b", "c")
- val c1 = 'a.int.at(0)
- val c2 = 'a.int.at(1)
- val c3 = 'a.string.at(2)
- val c4 = 'a.string.at(3)
- val c5 = 'a.string.at(4)
- checkEvaluation(Least(Seq(c4, c3, c5)), "a", row)
- checkEvaluation(Least(Seq(c1, c2)), 1, row)
- checkEvaluation(Least(Seq(c1, c2, Literal(-1))), -1, row)
- checkEvaluation(Least(Seq(c4, c5, c3, c3, Literal("a"))), "a", row)
-
- val nullLiteral = Literal.create(null, IntegerType)
- checkEvaluation(Least(Seq(nullLiteral, nullLiteral)), null)
- checkEvaluation(Least(Seq(Literal(null), Literal(null))), null, InternalRow.empty)
- checkEvaluation(Least(Seq(Literal(-1.0), Literal(2.5))), -1.0, InternalRow.empty)
- checkEvaluation(Least(Seq(Literal(-1), Literal(2))), -1, InternalRow.empty)
- checkEvaluation(
- Least(Seq(Literal((-1.0).toFloat), Literal(2.5.toFloat))), (-1.0).toFloat, InternalRow.empty)
- checkEvaluation(
- Least(Seq(Literal(Long.MaxValue), Literal(Long.MinValue))), Long.MinValue, InternalRow.empty)
- checkEvaluation(Least(Seq(Literal(1.toByte), Literal(2.toByte))), 1.toByte, InternalRow.empty)
- checkEvaluation(
- Least(Seq(Literal(1.toShort), Literal(2.toByte.toShort))), 1.toShort, InternalRow.empty)
- checkEvaluation(Least(Seq(Literal("abc"), Literal("aaaa"))), "aaaa", InternalRow.empty)
- checkEvaluation(Least(Seq(Literal(true), Literal(false))), false, InternalRow.empty)
- checkEvaluation(
- Least(Seq(
- Literal(BigDecimal("1234567890987654321123456")),
- Literal(BigDecimal("1234567890987654321123458")))),
- BigDecimal("1234567890987654321123456"), InternalRow.empty)
- checkEvaluation(
- Least(Seq(Literal(Date.valueOf("2015-01-01")), Literal(Date.valueOf("2015-07-01")))),
- Date.valueOf("2015-01-01"), InternalRow.empty)
- checkEvaluation(
- Least(Seq(
- Literal(Timestamp.valueOf("2015-07-01 08:00:00")),
- Literal(Timestamp.valueOf("2015-07-01 10:00:00")))),
- Timestamp.valueOf("2015-07-01 08:00:00"), InternalRow.empty)
-
- // Type checking error
- assert(
- Least(Seq(Literal(1), Literal("1"))).checkInputDataTypes() ==
- TypeCheckFailure("The expressions should all have the same type, " +
- "got LEAST(int, string)."))
-
- DataTypeTestUtils.ordered.foreach { dt =>
- checkConsistencyBetweenInterpretedAndCodegen(Least, dt, 2)
- }
- }
-
- test("function greatest") {
- val row = create_row(1, 2, "a", "b", "c")
- val c1 = 'a.int.at(0)
- val c2 = 'a.int.at(1)
- val c3 = 'a.string.at(2)
- val c4 = 'a.string.at(3)
- val c5 = 'a.string.at(4)
- checkEvaluation(Greatest(Seq(c4, c5, c3)), "c", row)
- checkEvaluation(Greatest(Seq(c2, c1)), 2, row)
- checkEvaluation(Greatest(Seq(c1, c2, Literal(2))), 2, row)
- checkEvaluation(Greatest(Seq(c4, c5, c3, Literal("ccc"))), "ccc", row)
-
- val nullLiteral = Literal.create(null, IntegerType)
- checkEvaluation(Greatest(Seq(nullLiteral, nullLiteral)), null)
- checkEvaluation(Greatest(Seq(Literal(null), Literal(null))), null, InternalRow.empty)
- checkEvaluation(Greatest(Seq(Literal(-1.0), Literal(2.5))), 2.5, InternalRow.empty)
- checkEvaluation(Greatest(Seq(Literal(-1), Literal(2))), 2, InternalRow.empty)
- checkEvaluation(
- Greatest(Seq(Literal((-1.0).toFloat), Literal(2.5.toFloat))), 2.5.toFloat, InternalRow.empty)
- checkEvaluation(Greatest(
- Seq(Literal(Long.MaxValue), Literal(Long.MinValue))), Long.MaxValue, InternalRow.empty)
- checkEvaluation(
- Greatest(Seq(Literal(1.toByte), Literal(2.toByte))), 2.toByte, InternalRow.empty)
- checkEvaluation(
- Greatest(Seq(Literal(1.toShort), Literal(2.toByte.toShort))), 2.toShort, InternalRow.empty)
- checkEvaluation(Greatest(Seq(Literal("abc"), Literal("aaaa"))), "abc", InternalRow.empty)
- checkEvaluation(Greatest(Seq(Literal(true), Literal(false))), true, InternalRow.empty)
- checkEvaluation(
- Greatest(Seq(
- Literal(BigDecimal("1234567890987654321123456")),
- Literal(BigDecimal("1234567890987654321123458")))),
- BigDecimal("1234567890987654321123458"), InternalRow.empty)
- checkEvaluation(Greatest(
- Seq(Literal(Date.valueOf("2015-01-01")), Literal(Date.valueOf("2015-07-01")))),
- Date.valueOf("2015-07-01"), InternalRow.empty)
- checkEvaluation(
- Greatest(Seq(
- Literal(Timestamp.valueOf("2015-07-01 08:00:00")),
- Literal(Timestamp.valueOf("2015-07-01 10:00:00")))),
- Timestamp.valueOf("2015-07-01 10:00:00"), InternalRow.empty)
-
- // Type checking error
- assert(
- Greatest(Seq(Literal(1), Literal("1"))).checkInputDataTypes() ==
- TypeCheckFailure("The expressions should all have the same type, " +
- "got GREATEST(int, string)."))
-
- DataTypeTestUtils.ordered.foreach { dt =>
- checkConsistencyBetweenInterpretedAndCodegen(Greatest, dt, 2)
- }
- }
}