I have written generic Scala method, which after reading hive column definition, create hive table. Signature of method, for same is:
def createHiveTable(tableName: String, metaDataList: List[SchemaColumnDefinition]) = { ....}
case class SchemaColumnDefinition(name: String,
dataType: String,
precision: Option[Integer],
scale: Option[Integer]) {
I have written one unit test-case for same
"createHiveTable" should " create hive table with provided column definition" in {
// GIVEN
val columns = SchemaColumnDefinition("testIntColumn", "INT", None, None) ::
SchemaColumnDefinition("testStringColumn", "STRING", None, None) ::
SchemaColumnDefinition("testDecimalColumn", "DECIMAL", None, None) ::
Nil
val testTableName = "testTable"
// WHEN
HiveTableManager.createHiveTable(testTableName, columns)
// THEN
sparkSession.catalog.listColumns(testTableName).foreach { columnDefinition =>
columnDefinition.name match {
case "testIntColumn" => assert(columnDefinition.dataType.toLowerCase == "int")
case "testStringColumn" => assert(columnDefinition.dataType.toLowerCase == "string")
case "testDecimalColumn" => assert(columnDefinition.dataType.toLowerCase == "decimal(10,0)")
}
}
}
But on running same, I am getting following exception:
[scalatest] Cause: java.io.NotSerializableException: org.scalatest.Assertions$AssertionsHelper
[scalatest] Serialization stack:
[scalatest] - object not serializable (class: org.scalatest.Assertions$AssertionsHelper, value: org.scalatest.Assertions$AssertionsHelper@420068a)
[scalatest] - field (class: org.scalatest.FlatSpec, name: assertionsHelper, type: class org.scalatest.Assertions$AssertionsHelper)
[scalatest] - object (class com.demo.spark.executor.hive.HiveTableManagerTest, HiveTableManagerTest)
If I replace "assert" with "println" statement, test case is passing.
I have tried extending test class with "Serializable", but same exception persist.