From c491e2ed90afc980d197d54cb965213bdd192b4b Mon Sep 17 00:00:00 2001 From: setjet Date: Fri, 26 May 2017 15:07:28 -0700 Subject: [PATCH] [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 Closes #18097 from setjet/spark-20873. --- .../spark/sql/execution/columnar/ColumnType.scala | 2 +- .../sql/execution/columnar/ColumnTypeSuite.scala | 14 ++++++++++++++ 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/sql/core/src/main/scala/org/apache/spark/sql/execution/columnar/ColumnType.scala b/sql/core/src/main/scala/org/apache/spark/sql/execution/columnar/ColumnType.scala index 703bde2531..5cfb003e4f 100644 --- a/sql/core/src/main/scala/org/apache/spark/sql/execution/columnar/ColumnType.scala +++ b/sql/core/src/main/scala/org/apache/spark/sql/execution/columnar/ColumnType.scala @@ -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}") } } } diff --git a/sql/core/src/test/scala/org/apache/spark/sql/execution/columnar/ColumnTypeSuite.scala b/sql/core/src/test/scala/org/apache/spark/sql/execution/columnar/ColumnTypeSuite.scala index 5f2a3aaff6..ff05049551 100644 --- a/sql/core/src/test/scala/org/apache/spark/sql/execution/columnar/ColumnTypeSuite.scala +++ b/sql/core/src/test/scala/org/apache/spark/sql/execution/columnar/ColumnTypeSuite.scala @@ -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")) + } }