peter-toth commented on a change in pull request #24742: [SPARK-27881][SQL] 
Support CAST (... FORMAT <pattern>) expression
URL: https://github.com/apache/spark/pull/24742#discussion_r289423018
 
 

 ##########
 File path: sql/core/src/test/resources/sql-tests/inputs/cast-format.sql
 ##########
 @@ -0,0 +1,53 @@
+CREATE TEMPORARY VIEW strings(s1, s2, s3, s4, s5, s6, s7) AS VALUES (
+  null,
+  '2019',
+  '2019 05',
+  '2019 05 28',
+  '2019 05 28 17 03 53',
+  '2019 05 28 17 03 53 123',
+  '2019 05 28 17 03 53 123456'
+);
+
+SELECT
+    CAST(s1 AS DATE FORMAT 'yyyy'),
+    CAST(s2 AS DATE FORMAT 'yyyy'),
+    CAST(s3 AS DATE FORMAT 'yyyy MM'),
+    CAST(s4 AS DATE FORMAT 'yyyy MM dd'),
+    CAST(s2 AS DATE FORMAT 'invalid')
+FROM strings;
+
+SELECT
+    CAST(s1 AS TIMESTAMP FORMAT 'yyyy'),
+    CAST(s2 AS TIMESTAMP FORMAT 'yyyy'),
+    CAST(s3 AS TIMESTAMP FORMAT 'yyyy MM'),
+    CAST(s4 AS TIMESTAMP FORMAT 'yyyy MM dd'),
+    CAST(s5 AS TIMESTAMP FORMAT 'yyyy MM dd HH mm ss'),
+    CAST(s6 AS TIMESTAMP FORMAT 'yyyy MM dd HH mm ss SSS'),
+    CAST(s7 AS TIMESTAMP FORMAT 'yyyy MM dd HH mm ss SSSSSS'),
 
 Review comment:
   Thanks, I've changed it a bit, now covers the above cases.

----------------------------------------------------------------
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.
 
For queries about this service, please contact Infrastructure at:
[email protected]


With regards,
Apache Git Services

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

Reply via email to