[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:
setjet 2017-05-26 15:07:28 -07:00 committed by Xiao Li
parent ae33abf71b
commit c491e2ed90
2 changed files with 15 additions and 1 deletions

View file

@ -684,7 +684,7 @@ private[columnar] object ColumnType {
case struct: StructType => STRUCT(struct) case struct: StructType => STRUCT(struct)
case udt: UserDefinedType[_] => apply(udt.sqlType) case udt: UserDefinedType[_] => apply(udt.sqlType)
case other => case other =>
throw new Exception(s"Unsupported type: $other") throw new Exception(s"Unsupported type: ${other.simpleString}")
} }
} }
} }

View file

@ -144,4 +144,18 @@ class ColumnTypeSuite extends SparkFunSuite with Logging {
ColumnType(DecimalType(19, 0)) 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"))
}
} }