This is an automated email from the ASF dual-hosted git repository.
maxgekk pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/spark.git
The following commit(s) were added to refs/heads/master by this push:
new 195090a [SPARK-35764][SQL] Assign pretty names to
TimestampWithoutTZType
195090a is described below
commit 195090afcc8ed138336b353edc0a4db6f0f5f168
Author: Gengliang Wang <[email protected]>
AuthorDate: Tue Jun 15 12:15:13 2021 +0300
[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

### 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 <[email protected]>
Signed-off-by: Max Gekk <[email protected]>
---
.../org/apache/spark/sql/types/TimestampWithoutTZType.scala | 2 ++
.../apache/spark/sql/catalyst/expressions/CastSuite.scala | 13 +++++++++++++
2 files changed, 15 insertions(+)
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 558f5ee..856d549 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 c268d52..910c757 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))
+ }
+ }
}
/**
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]