[SPARK-35764][SQL] Assign pretty names to TimestampWithoutTZType
### What changes were proposed in this pull request? In the PR, I propose to override the typeName() method in TimestampWithoutTZType, and assign it a name according to the ANSI SQL standard ![image](https://user-images.githubusercontent.com/1097932/122013859-2cf50680-cdf1-11eb-9fcd-0ec1b59fb5c0.png) ### Why are the changes needed? To improve Spark SQL user experience, and have readable types in error messages. ### Does this PR introduce _any_ user-facing change? No, the new timestamp type is not released yet. ### How was this patch tested? Unit test Closes #32915 from gengliangwang/typename. Authored-by: Gengliang Wang <gengliang@apache.org> Signed-off-by: Max Gekk <max.gekk@gmail.com>
This commit is contained in:
parent
a50bd8f810
commit
195090afcc
|
@ -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
|
||||
}
|
||||
|
||||
|
|
|
@ -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))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
Loading…
Reference in a new issue