Skip to content

Commit 1df3964

Browse files
scwfviper-kun
authored andcommitted
Jdk version leads to different query output for Double, this make HiveQuerySuite failed
1 parent 729952a commit 1df3964

File tree

1 file changed

+11
-4
lines changed

1 file changed

+11
-4
lines changed

sql/hive/src/test/scala/org/apache/spark/sql/hive/execution/HiveQuerySuite.scala

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -135,8 +135,12 @@ class HiveQuerySuite extends HiveComparisonTest {
135135
createQueryTest("div",
136136
"SELECT 1 DIV 2, 1 div 2, 1 dIv 2, 100 DIV 51, 100 DIV 49 FROM src LIMIT 1")
137137

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

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

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

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

0 commit comments

Comments
 (0)