diff --git a/sql/catalyst/src/main/scala/org/apache/spark/sql/types/TimestampWithoutTZType.scala b/sql/catalyst/src/main/scala/org/apache/spark/sql/types/TimestampWithoutTZType.scala index 558f5ee94a..856d5497f7 100644 --- a/sql/catalyst/src/main/scala/org/apache/spark/sql/types/TimestampWithoutTZType.scala +++ b/sql/catalyst/src/main/scala/org/apache/spark/sql/types/TimestampWithoutTZType.scala @@ -48,6 +48,8 @@ class TimestampWithoutTZType private() extends AtomicType { */ override def defaultSize: Int = 8 + override def typeName: String = "timestamp without time zone" + private[spark] override def asNullable: TimestampWithoutTZType = this } diff --git a/sql/catalyst/src/test/scala/org/apache/spark/sql/catalyst/expressions/CastSuite.scala b/sql/catalyst/src/test/scala/org/apache/spark/sql/catalyst/expressions/CastSuite.scala index c268d52c4f..910c757233 100644 --- a/sql/catalyst/src/test/scala/org/apache/spark/sql/catalyst/expressions/CastSuite.scala +++ b/sql/catalyst/src/test/scala/org/apache/spark/sql/catalyst/expressions/CastSuite.scala @@ -1295,6 +1295,19 @@ abstract class AnsiCastSuiteBase extends CastSuiteBase { } } } + + test("disallow type conversions between Numeric types and Timestamp without time zone type") { + import DataTypeTestUtils.numericTypes + checkInvalidCastFromNumericType(TimestampWithoutTZType) + var errorMsg = "cannot cast bigint to timestamp without time zone" + verifyCastFailure(cast(Literal(0L), TimestampWithoutTZType), Some(errorMsg)) + + val timestampWithoutTZLiteral = Literal.create(LocalDateTime.now(), TimestampWithoutTZType) + errorMsg = "cannot cast timestamp without time zone to" + numericTypes.foreach { numericType => + verifyCastFailure(cast(timestampWithoutTZLiteral, numericType), Some(errorMsg)) + } + } } /**