AngersZhuuuu commented on a change in pull request #30421:
URL: https://github.com/apache/spark/pull/30421#discussion_r585201524



##########
File path: sql/core/src/test/scala/org/apache/spark/sql/SQLInsertTestSuite.scala
##########
@@ -209,6 +211,72 @@ trait SQLInsertTestSuite extends QueryTest with 
SQLTestUtils {
     }
   }
 
+  test("SPARK-33474: Support typed literals as partition spec values") {
+    withTable("t1", "t3") {
+      val binaryStr = "Spark SQL"
+      val binaryHexStr = 
Hex.hex(UTF8String.fromString(binaryStr).getBytes).toString
+      sql(
+        """
+          | CREATE TABLE t1(name STRING, part1 DATE, part2 TIMESTAMP, part3 
BINARY,
+          |  part4 STRING, part5 STRING, part6 STRING)
+          | USING PARQUET PARTITIONED BY (part1, part2, part3, part4, part5, 
part6)""".stripMargin)
+
+      sql(
+        s"""
+           | INSERT INTO t1 PARTITION(
+           | part1 = date'2019-01-01',
+           | part2 = timestamp'2019-01-01 11:11:11',
+           | part3 = X'$binaryHexStr',
+           | part4 = 'a',
+           | part5 = 'a',
+           | part6 = 'a'
+           | ) VALUES('a')""".stripMargin)
+      checkAnswer(sql(
+        """
+          | SELECT
+          |   name,
+          |   CAST(part1 AS STRING),
+          |   CAST(part2 as STRING),
+          |   CAST(part3 as STRING),
+          |   CAST(part4 as STRING),
+          |   CAST(part5 as STRING),
+          |   CAST(part6 as STRING)
+          | FROM t1""".stripMargin),
+        Row("a", "2019-01-01", "2019-01-01 11:11:11", "Spark SQL", "a", "a", 
"a"))
+
+      // test type conversion
+      sql(
+        s"""
+           | INSERT INTO t1 PARTITION(

Review comment:
       > nit: we can use INSERT OVERWRITE here so that the `checkAnswer` only 
need to check one row
   
   They have different partition values, so we cant do like this. Add a `part7` 
to specify different partition and only check one row.




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



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

Reply via email to