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


##########
backends-velox/src/test/scala/org/apache/gluten/execution/TestOperator.scala:
##########
@@ -1236,4 +1236,34 @@ 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") {

Review Comment:
   > With timezone 
   
   I believe it's ok. Spark's conversion of the date type to timestamp is only 
supported up to the day of the day, and will not cause problems in different 
time zones.  
   ```
   scala> val df = spark.sql("select date'2023-01-02 01:01:01' as ts")
   df: org.apache.spark.sql.DataFrame = [ts: date]
   
   scala> df.show
   +----------+
   |        ts|
   +----------+
   |2023-01-02|
   +----------+
   
   scala> spark.sql("set spark.sql.session.timeZone = America/Los_Angeles")
   res22: 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").show
   +-------------------+
   |                 ts|
   +-------------------+
   |2023-01-02 00:00:00|
   +-------------------+
   
   
   scala> spark.sql("set spark.sql.session.timeZone = Asia/Shanghai")
   res24: 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").show
   +-------------------+
   |                 ts|
   +-------------------+
   |2023-01-02 00:00:00|
   +-------------------+
   
   ```
   



-- 
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