Skip to content
Snippets Groups Projects
Commit 65357f11 authored by scwf's avatar scwf Committed by Michael Armbrust
Browse files

[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 <wangfei1@huawei.com>
Author: Fei Wang <wangfei1@huawei.com>

Closes #3814 from scwf/fix-inspectorsuite and squashes the following commits:

d8531ef [Fei Wang] Delete test.log
72b19a9 [scwf] fix HiveInspectorSuite test error
parent 94d60b70
No related branches found
No related tags found
No related merge requests found
...@@ -19,6 +19,7 @@ package org.apache.spark.sql.hive ...@@ -19,6 +19,7 @@ package org.apache.spark.sql.hive
import java.sql.Date import java.sql.Date
import java.util import java.util
import java.util.{Locale, TimeZone}
import org.apache.hadoop.hive.serde2.io.DoubleWritable import org.apache.hadoop.hive.serde2.io.DoubleWritable
import org.apache.hadoop.hive.serde2.objectinspector.primitive.PrimitiveObjectInspectorFactory import org.apache.hadoop.hive.serde2.objectinspector.primitive.PrimitiveObjectInspectorFactory
...@@ -63,6 +64,11 @@ class HiveInspectorSuite extends FunSuite with HiveInspectors { ...@@ -63,6 +64,11 @@ class HiveInspectorSuite extends FunSuite with HiveInspectors {
.get()) .get())
} }
// Timezone is fixed to America/Los_Angeles for those timezone sensitive tests (timestamp_*)
TimeZone.setDefault(TimeZone.getTimeZone("America/Los_Angeles"))
// Add Locale setting
Locale.setDefault(Locale.US)
val data = val data =
Literal(true) :: Literal(true) ::
Literal(0.asInstanceOf[Byte]) :: Literal(0.asInstanceOf[Byte]) ::
...@@ -121,11 +127,11 @@ class HiveInspectorSuite extends FunSuite with HiveInspectors { ...@@ -121,11 +127,11 @@ class HiveInspectorSuite extends FunSuite with HiveInspectors {
def checkValues(row1: Seq[Any], row2: Seq[Any]): Unit = { def checkValues(row1: Seq[Any], row2: Seq[Any]): Unit = {
row1.zip(row2).map { row1.zip(row2).map {
case (r1, r2) => checkValues(r1, r2) case (r1, r2) => checkValue(r1, r2)
} }
} }
def checkValues(v1: Any, v2: Any): Unit = { def checkValue(v1: Any, v2: Any): Unit = {
(v1, v2) match { (v1, v2) match {
case (r1: Decimal, r2: Decimal) => case (r1: Decimal, r2: Decimal) =>
// Ignore the Decimal precision // Ignore the Decimal precision
...@@ -195,26 +201,26 @@ class HiveInspectorSuite extends FunSuite with HiveInspectors { ...@@ -195,26 +201,26 @@ class HiveInspectorSuite extends FunSuite with HiveInspectors {
}) })
checkValues(row, unwrap(wrap(row, toInspector(dt)), toInspector(dt)).asInstanceOf[Row]) checkValues(row, unwrap(wrap(row, toInspector(dt)), toInspector(dt)).asInstanceOf[Row])
checkValues(null, unwrap(wrap(null, toInspector(dt)), toInspector(dt))) checkValue(null, unwrap(wrap(null, toInspector(dt)), toInspector(dt)))
} }
test("wrap / unwrap Array Type") { test("wrap / unwrap Array Type") {
val dt = ArrayType(dataTypes(0)) val dt = ArrayType(dataTypes(0))
val d = row(0) :: row(0) :: Nil val d = row(0) :: row(0) :: Nil
checkValues(d, unwrap(wrap(d, toInspector(dt)), toInspector(dt))) checkValue(d, unwrap(wrap(d, toInspector(dt)), toInspector(dt)))
checkValues(null, unwrap(wrap(null, toInspector(dt)), toInspector(dt))) checkValue(null, unwrap(wrap(null, toInspector(dt)), toInspector(dt)))
checkValues(d, unwrap(wrap(d, toInspector(Literal(d, dt))), toInspector(Literal(d, dt)))) checkValue(d, unwrap(wrap(d, toInspector(Literal(d, dt))), toInspector(Literal(d, dt))))
checkValues(d, unwrap(wrap(null, toInspector(Literal(d, dt))), toInspector(Literal(d, dt)))) checkValue(d, unwrap(wrap(null, toInspector(Literal(d, dt))), toInspector(Literal(d, dt))))
} }
test("wrap / unwrap Map Type") { test("wrap / unwrap Map Type") {
val dt = MapType(dataTypes(0), dataTypes(1)) val dt = MapType(dataTypes(0), dataTypes(1))
val d = Map(row(0) -> row(1)) val d = Map(row(0) -> row(1))
checkValues(d, unwrap(wrap(d, toInspector(dt)), toInspector(dt))) checkValue(d, unwrap(wrap(d, toInspector(dt)), toInspector(dt)))
checkValues(null, unwrap(wrap(null, toInspector(dt)), toInspector(dt))) checkValue(null, unwrap(wrap(null, toInspector(dt)), toInspector(dt)))
checkValues(d, unwrap(wrap(d, toInspector(Literal(d, dt))), toInspector(Literal(d, dt)))) checkValue(d, unwrap(wrap(d, toInspector(Literal(d, dt))), toInspector(Literal(d, dt))))
checkValues(d, unwrap(wrap(null, toInspector(Literal(d, dt))), toInspector(Literal(d, dt)))) checkValue(d, unwrap(wrap(null, toInspector(Literal(d, dt))), toInspector(Literal(d, dt))))
} }
} }
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment