Skip to content

Commit 65357f1

Browse files
scwfmarmbrus
authored andcommitted
[SPARK-4975][SQL] Fix HiveInspectorSuite test failure
HiveInspectorSuite test failure: [info] - wrap / unwrap null, constant null and writables *** FAILED *** (21 milliseconds) [info] 1 did not equal 0 (HiveInspectorSuite.scala:136) this is because the origin date(is 3914-10-23) not equals the date returned by ```unwrap```(is 3914-10-22). Setting TimeZone and Locale fix this. Another minor change here is rename ```def checkValues(v1: Any, v2: Any): Unit``` to ```def checkValue(v1: Any, v2: Any): Unit ``` to make the code more clear Author: scwf <[email protected]> Author: Fei Wang <[email protected]> Closes #3814 from scwf/fix-inspectorsuite and squashes the following commits: d8531ef [Fei Wang] Delete test.log 72b19a9 [scwf] fix HiveInspectorSuite test error
1 parent 94d60b7 commit 65357f1

File tree

1 file changed

+17
-11
lines changed

1 file changed

+17
-11
lines changed

sql/hive/src/test/scala/org/apache/spark/sql/hive/HiveInspectorSuite.scala

Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ package org.apache.spark.sql.hive
1919

2020
import java.sql.Date
2121
import java.util
22+
import java.util.{Locale, TimeZone}
2223

2324
import org.apache.hadoop.hive.serde2.io.DoubleWritable
2425
import org.apache.hadoop.hive.serde2.objectinspector.primitive.PrimitiveObjectInspectorFactory
@@ -63,6 +64,11 @@ class HiveInspectorSuite extends FunSuite with HiveInspectors {
6364
.get())
6465
}
6566

67+
// Timezone is fixed to America/Los_Angeles for those timezone sensitive tests (timestamp_*)
68+
TimeZone.setDefault(TimeZone.getTimeZone("America/Los_Angeles"))
69+
// Add Locale setting
70+
Locale.setDefault(Locale.US)
71+
6672
val data =
6773
Literal(true) ::
6874
Literal(0.asInstanceOf[Byte]) ::
@@ -121,11 +127,11 @@ class HiveInspectorSuite extends FunSuite with HiveInspectors {
121127

122128
def checkValues(row1: Seq[Any], row2: Seq[Any]): Unit = {
123129
row1.zip(row2).map {
124-
case (r1, r2) => checkValues(r1, r2)
130+
case (r1, r2) => checkValue(r1, r2)
125131
}
126132
}
127133

128-
def checkValues(v1: Any, v2: Any): Unit = {
134+
def checkValue(v1: Any, v2: Any): Unit = {
129135
(v1, v2) match {
130136
case (r1: Decimal, r2: Decimal) =>
131137
// Ignore the Decimal precision
@@ -195,26 +201,26 @@ class HiveInspectorSuite extends FunSuite with HiveInspectors {
195201
})
196202

197203
checkValues(row, unwrap(wrap(row, toInspector(dt)), toInspector(dt)).asInstanceOf[Row])
198-
checkValues(null, unwrap(wrap(null, toInspector(dt)), toInspector(dt)))
204+
checkValue(null, unwrap(wrap(null, toInspector(dt)), toInspector(dt)))
199205
}
200206

201207
test("wrap / unwrap Array Type") {
202208
val dt = ArrayType(dataTypes(0))
203209

204210
val d = row(0) :: row(0) :: Nil
205-
checkValues(d, unwrap(wrap(d, toInspector(dt)), toInspector(dt)))
206-
checkValues(null, unwrap(wrap(null, toInspector(dt)), toInspector(dt)))
207-
checkValues(d, unwrap(wrap(d, toInspector(Literal(d, dt))), toInspector(Literal(d, dt))))
208-
checkValues(d, unwrap(wrap(null, toInspector(Literal(d, dt))), toInspector(Literal(d, dt))))
211+
checkValue(d, unwrap(wrap(d, toInspector(dt)), toInspector(dt)))
212+
checkValue(null, unwrap(wrap(null, toInspector(dt)), toInspector(dt)))
213+
checkValue(d, unwrap(wrap(d, toInspector(Literal(d, dt))), toInspector(Literal(d, dt))))
214+
checkValue(d, unwrap(wrap(null, toInspector(Literal(d, dt))), toInspector(Literal(d, dt))))
209215
}
210216

211217
test("wrap / unwrap Map Type") {
212218
val dt = MapType(dataTypes(0), dataTypes(1))
213219

214220
val d = Map(row(0) -> row(1))
215-
checkValues(d, unwrap(wrap(d, toInspector(dt)), toInspector(dt)))
216-
checkValues(null, unwrap(wrap(null, toInspector(dt)), toInspector(dt)))
217-
checkValues(d, unwrap(wrap(d, toInspector(Literal(d, dt))), toInspector(Literal(d, dt))))
218-
checkValues(d, unwrap(wrap(null, toInspector(Literal(d, dt))), toInspector(Literal(d, dt))))
221+
checkValue(d, unwrap(wrap(d, toInspector(dt)), toInspector(dt)))
222+
checkValue(null, unwrap(wrap(null, toInspector(dt)), toInspector(dt)))
223+
checkValue(d, unwrap(wrap(d, toInspector(Literal(d, dt))), toInspector(Literal(d, dt))))
224+
checkValue(d, unwrap(wrap(null, toInspector(Literal(d, dt))), toInspector(Literal(d, dt))))
219225
}
220226
}

0 commit comments

Comments
 (0)