Skip to content

Commit

Permalink
Jdk version leads to different query output for Double, this make Hiv…
Browse files Browse the repository at this point in the history
…eQuerySuite failed
  • Loading branch information
scwf authored and viper-kun committed Sep 24, 2014
1 parent 729952a commit 1df3964
Showing 1 changed file with 11 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -135,8 +135,12 @@ class HiveQuerySuite extends HiveComparisonTest {
createQueryTest("div",
"SELECT 1 DIV 2, 1 div 2, 1 dIv 2, 100 DIV 51, 100 DIV 49 FROM src LIMIT 1")

createQueryTest("division",
"SELECT 2 / 1, 1 / 2, 1 / 3, 1 / COUNT(*) FROM src LIMIT 1")
// Jdk version leads to different query output for double, so not use createQueryTest here
test("division") {
val res = sql("SELECT 2 / 1, 1 / 2, 1 / 3, 1 / COUNT(*) FROM src LIMIT 1").collect().head
Seq(2.0, 0.5, 0.3333333333333333, 0.002).zip(res).foreach( x =>
assert(x._1 == x._2.asInstanceOf[Double]))
}

createQueryTest("modulus",
"SELECT 11 % 10, IF((101.1 % 100.0) BETWEEN 1.01 AND 1.11, \"true\", \"false\"), (101 / 2) % 10 FROM src LIMIT 1")
Expand Down Expand Up @@ -306,8 +310,11 @@ class HiveQuerySuite extends HiveComparisonTest {
createQueryTest("case statements WITHOUT key #4",
"SELECT (CASE WHEN key > 2 THEN 3 WHEN 2 > key THEN 2 ELSE 0 END) FROM src WHERE key < 15")

createQueryTest("timestamp cast #1",
"SELECT CAST(CAST(1 AS TIMESTAMP) AS DOUBLE) FROM src LIMIT 1")
// Jdk version leads to different query output for double, so not use createQueryTest here
test("timestamp cast #1") {
val res = sql("SELECT CAST(CAST(1 AS TIMESTAMP) AS DOUBLE) FROM src LIMIT 1").collect().head
assert(0.001 == res.getDouble(0))
}

createQueryTest("timestamp cast #2",
"SELECT CAST(CAST(1.2 AS TIMESTAMP) AS DOUBLE) FROM src LIMIT 1")
Expand Down

0 comments on commit 1df3964

Please sign in to comment.