This is an automated email from the ASF dual-hosted git repository.

gurwls223 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 ea1f922  [SPARK-37707][SQL][FOLLOWUP] Allow implicitly casting Date 
type to AnyTimestampType under ANSI mode
ea1f922 is described below

commit ea1f922e232b0193927cdeec529083f274b108ac
Author: Gengliang Wang <[email protected]>
AuthorDate: Tue Feb 15 19:06:17 2022 +0900

    [SPARK-37707][SQL][FOLLOWUP] Allow implicitly casting Date type to 
AnyTimestampType under ANSI mode
    
    ### What changes were proposed in this pull request?
    
    Followup of https://github.com/apache/spark/pull/34976: allow implicitly 
casting Date type to AnyTimestampType under ANSI mode
    
    ### Why are the changes needed?
    
    AnyTimestampType is a type collection for Timestamp and TimestampNTZ. As 
Spark allows implicit casting Date as Timestamp/TimestampNTZ under ANSI mode, 
Date can be cast as AnyTimestampType as well.
    
    ### Does this PR introduce _any_ user-facing change?
    
    Yes, allow implicitly casting Date type to AnyTimestampType under ANSI mode
    
    ### How was this patch tested?
    
    Unit  test
    
    Closes #35522 from gengliangwang/fixMoreAnsiTest.
    
    Authored-by: Gengliang Wang <[email protected]>
    Signed-off-by: Hyukjin Kwon <[email protected]>
---
 .../apache/spark/sql/catalyst/analysis/AnsiTypeCoercion.scala |  3 +++
 .../spark/sql/catalyst/analysis/TypeCoercionSuite.scala       | 11 +++++++++++
 2 files changed, 14 insertions(+)

diff --git 
a/sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/analysis/AnsiTypeCoercion.scala
 
b/sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/analysis/AnsiTypeCoercion.scala
index 61142fc..90f28fb 100644
--- 
a/sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/analysis/AnsiTypeCoercion.scala
+++ 
b/sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/analysis/AnsiTypeCoercion.scala
@@ -204,6 +204,9 @@ object AnsiTypeCoercion extends TypeCoercionBase {
       case (StringType, AnyTimestampType) =>
         Some(AnyTimestampType.defaultConcreteType)
 
+      case (DateType, AnyTimestampType) =>
+        Some(AnyTimestampType.defaultConcreteType)
+
       case (_, target: DataType) =>
         if (Cast.canANSIStoreAssign(inType, target)) {
           Some(target)
diff --git 
a/sql/catalyst/src/test/scala/org/apache/spark/sql/catalyst/analysis/TypeCoercionSuite.scala
 
b/sql/catalyst/src/test/scala/org/apache/spark/sql/catalyst/analysis/TypeCoercionSuite.scala
index 8ea5886..63ad84e 100644
--- 
a/sql/catalyst/src/test/scala/org/apache/spark/sql/catalyst/analysis/TypeCoercionSuite.scala
+++ 
b/sql/catalyst/src/test/scala/org/apache/spark/sql/catalyst/analysis/TypeCoercionSuite.scala
@@ -190,6 +190,7 @@ abstract class TypeCoercionSuiteBase extends AnalysisTest {
   test("implicit type cast - DateType") {
     val checkedType = DateType
     checkTypeCasting(checkedType, castableTypes = Seq(checkedType, StringType) 
++ datetimeTypes)
+    shouldCast(checkedType, AnyTimestampType, 
AnyTimestampType.defaultConcreteType)
     shouldNotCast(checkedType, DecimalType)
     shouldNotCast(checkedType, NumericType)
     shouldNotCast(checkedType, IntegralType)
@@ -198,6 +199,16 @@ abstract class TypeCoercionSuiteBase extends AnalysisTest {
   test("implicit type cast - TimestampType") {
     val checkedType = TimestampType
     checkTypeCasting(checkedType, castableTypes = Seq(checkedType, StringType) 
++ datetimeTypes)
+    shouldCast(checkedType, AnyTimestampType, checkedType)
+    shouldNotCast(checkedType, DecimalType)
+    shouldNotCast(checkedType, NumericType)
+    shouldNotCast(checkedType, IntegralType)
+  }
+
+  test("implicit type cast - TimestampNTZType") {
+    val checkedType = TimestampNTZType
+    checkTypeCasting(checkedType, castableTypes = Seq(checkedType, StringType) 
++ datetimeTypes)
+    shouldCast(checkedType, AnyTimestampType, checkedType)
     shouldNotCast(checkedType, DecimalType)
     shouldNotCast(checkedType, NumericType)
     shouldNotCast(checkedType, IntegralType)

---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to