3

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)

complete log

If I replace "assert" with "println" statement, test case is passing.

I have tried extending test class with "Serializable", but same exception persist.

user811602
  • 1,314
  • 2
  • 17
  • 47
  • See https://stackoverflow.com/questions/42081003/scalatest-and-spark-giving-java-io-notserializableexception-org-scalatest-asse/42081112 for some pointers – Niyaz Apr 27 '21 at 21:02

0 Answers0