dcoliversun commented on code in PR #5240:
URL: https://github.com/apache/incubator-gluten/pull/5240#discussion_r1549344491


##########
backends-velox/src/test/scala/org/apache/gluten/execution/TestOperator.scala:
##########
@@ -1236,4 +1238,52 @@ class TestOperator extends 
VeloxWholeStageTransformerSuite {
       }
     }
   }
+
+  test("Cast date to string") {
+    withTempPath {
+      path =>
+        Seq("2023-01-01", "2023-01-02", "2023-01-03")
+          .toDF("dateColumn")
+          .select(to_date($"dateColumn", "yyyy-MM-dd").as("dateColumn"))
+          .write
+          .parquet(path.getCanonicalPath)
+        
spark.read.parquet(path.getCanonicalPath).createOrReplaceTempView("view")
+        runQueryAndCompare("SELECT cast(dateColumn as string) from view") {
+          checkGlutenOperatorMatch[ProjectExecTransformer]
+        }
+    }
+  }
+
+  test("Cast date to timestamp") {
+    withTempPath {
+      path =>
+        Seq("2023-01-01", "2023-01-02", "2023-01-03")
+          .toDF("dateColumn")
+          .select(to_date($"dateColumn", "yyyy-MM-dd").as("dateColumn"))
+          .write
+          .parquet(path.getCanonicalPath)
+        
spark.read.parquet(path.getCanonicalPath).createOrReplaceTempView("view")
+        runQueryAndCompare("SELECT cast(dateColumn as timestamp) from view") {
+          checkGlutenOperatorMatch[ProjectExecTransformer]
+        }
+    }
+  }
+
+  test("cast date to timestamp with timezone") {
+    sql("SET spark.sql.session.timeZone = America/Los_Angeles")
+    val dfWithLA = sql("SELECT cast(date'2023-01-02 01:01:01' as timestamp) as 
ts")
+
+    sql("SET spark.sql.session.timeZone = Asia/Shanghai")
+    val dfWithSH = sql("SELECT cast(date'2023-01-02 01:01:01' as timestamp) as 
ts")
+
+    // They should be the same because date in spark represents the day
+    checkAnswer(dfWithLA, Row(Timestamp.valueOf("2023-01-02 00:00:00")))

Review Comment:
   @rui-mo I found that velox and spark behave inconsistently. In the Los 
Angeles time zone, velox returned `2023-01-01.08:00:00`. Please see the 
specific process  
   ```plain
   scala> spark.sql("SET spark.sql.session.timeZone = America/Los_Angeles")
   res11: org.apache.spark.sql.DataFrame = [key: string, value: string]
   
   scala> spark.sql("SELECT cast(date'2023-01-02 01:01:01' as timestamp) as ts")
   res12: org.apache.spark.sql.DataFrame = [ts: timestamp]
   
   scala> res12.explain
   == Physical Plan ==
   VeloxColumnarToRowExec
   +- ^(7) ProjectExecTransformer [2023-01-02 00:00:00 AS ts#94]
      +- ^(7) InputIteratorTransformer[fake_column#96]
         +- ^(7) InputAdapter
            +- ^(7) RowToVeloxColumnar
               +- *(1) Scan OneRowRelation[fake_column#96]
   
   
   
   scala> res12.show
   +-------------------+
   |                 ts|
   +-------------------+
   |2023-01-02 00:00:00|
   +-------------------+
   ```
   
   I understand this is a velox bug? Datetypes in spark do not carry the time 
zone [1], but velox does.
   > DateType: Represents values comprising values of fields year, month and 
day, without a time-zone.
   
   ref:
   1. https://spark.apache.org/docs/latest/sql-ref-datatypes.html
   
   



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


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

Reply via email to