[SPARK-20873][SQL] Improve the error message for unsupported Column Type
## What changes were proposed in this pull request? Upon encountering an invalid columntype, the column type object is printed, rather than the type. This change improves this by outputting its name. ## How was this patch tested? Added a simple unit test to verify the contents of the raised exception Author: setjet <rubenljanssen@gmail.com> Closes #18097 from setjet/spark-20873.
This commit is contained in:
parent
ae33abf71b
commit
c491e2ed90
|
@ -684,7 +684,7 @@ private[columnar] object ColumnType {
|
|||
case struct: StructType => STRUCT(struct)
|
||||
case udt: UserDefinedType[_] => apply(udt.sqlType)
|
||||
case other =>
|
||||
throw new Exception(s"Unsupported type: $other")
|
||||
throw new Exception(s"Unsupported type: ${other.simpleString}")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -144,4 +144,18 @@ class ColumnTypeSuite extends SparkFunSuite with Logging {
|
|||
ColumnType(DecimalType(19, 0))
|
||||
}
|
||||
}
|
||||
|
||||
test("show type name in type mismatch error") {
|
||||
val invalidType = new DataType {
|
||||
override def defaultSize: Int = 1
|
||||
override private[spark] def asNullable: DataType = this
|
||||
override def typeName: String = "invalid type name"
|
||||
}
|
||||
|
||||
val message = intercept[java.lang.Exception] {
|
||||
ColumnType(invalidType)
|
||||
}.getMessage
|
||||
|
||||
assert(message.contains("Unsupported type: invalid type name"))
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue