Uploaded image for project: 'Spark'
  1. Spark
  2. SPARK-37935 Migrate onto error classes
  3. SPARK-49044

Improve error message in ValidateExternalType

    XMLWordPrintableJSON

Details

    • Sub-task
    • Status: Resolved
    • Trivial
    • Resolution: Fixed
    • 4.0.0
    • 4.0.0
    • SQL

    Description

      When we have mixed schema rows error message "{actual} is not a valid external type for schema of {expected}" that don't help to understand column with problem. I suggest to add information about source column.

      How to reproduce

      class ErrorMsgSuite extends AnyFunSuite with SharedSparkContext {
        test("shouldThrowSchemaError") {
          val seq: Seq[Row] = Seq(
            Row(
              toBytes("0"),
              toBytes(""),
              1L,
            ),
            Row(
              toBytes("0"),
              toBytes(""),
              1L,
            ),
          )    val schema: StructType = new StructType()
            .add("f1", BinaryType)
            .add("f3", StringType)
            .add("f2", LongType)    val df = sqlContext.createDataFrame(sqlContext.sparkContext.parallelize(seq), schema)    val exception = intercept[RuntimeException] {
            df.show()
          }    assert(
            exception.getCause.getMessage
              .contains("[B is not a valid external type for schema of string")
          )
          assertResult(
            "[B is not a valid external type for schema of string"
          )(exception.getCause.getMessage)
        }  def toBytes(x: String): Array[Byte] = x.toCharArray.map(_.toByte)
      } 

      After fix error message may contain extra info

      [B is not a valid external type for schema of string at getexternalrowfield(assertnotnull(input[0, org.apache.spark.sql.Row, true]), 1, f3) 

      Code: https://github.com/mrk-andreev/example-spark-schema/blob/main/spark_4.0.0/src/test/scala/ErrorMsgSuite.scala 

      Attachments

        Issue Links

          Activity

            People

              mrkandreev Mark Andreev
              mrkandreev Mark Andreev
              Votes:
              0 Vote for this issue
              Watchers:
              3 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: