AngersZhuuuu commented on a change in pull request #30421:
URL: https://github.com/apache/spark/pull/30421#discussion_r581935782
##########
File path: sql/core/src/test/scala/org/apache/spark/sql/SQLQuerySuite.scala
##########
@@ -4021,6 +4021,27 @@ class SQLQuerySuite extends QueryTest with
SharedSparkSession with AdaptiveSpark
}
}
}
+
+ test("SPARK-33474: Support TypeConstructed partition spec value") {
+ withTable("t1", "t2", "t4") {
+ sql("CREATE TABLE t1(name STRING, part DATE) USING PARQUET PARTITIONED
BY (part)")
+ sql("INSERT INTO t1 PARTITION(part = date'2019-01-02') VALUES('a')")
+ checkAnswer(sql("SELECT name, CAST(part AS STRING) FROM t1"), Row("a",
"2019-01-02"))
+
+ sql("CREATE TABLE t2(name STRING, part TIMESTAMP) USING PARQUET
PARTITIONED BY (part)")
+ sql("INSERT INTO t2 PARTITION(part = timestamp'2019-01-02 11:11:11')
VALUES('a')")
+ checkAnswer(sql("SELECT name, CAST(part AS STRING) FROM t2"), Row("a",
"2019-01-02 11:11:11"))
+
+ val e = intercept[AnalysisException] {
+ sql("CREATE TABLE t3(name STRING, part INTERVAL) USING PARQUET
PARTITIONED BY (part)")
+ }.getMessage
+ assert(e.contains("Cannot use interval for partition column"))
+
+ sql("CREATE TABLE t4(name STRING, part BINARY) USING CSV PARTITIONED BY
(part)")
+ sql(s"INSERT INTO t4 PARTITION(part = X'537061726B2053514C')
VALUES('a')")
+ checkAnswer(sql("SELECT name, cast(part as string) FROM t4"), Row("a",
"Spark SQL"))
+ }
Review comment:
For these three concern
> All the literals are supported. Non-literals are forbidden. e.g.
part_col=array(1) does not create a string value "array(1)".
Now type constructor only support `DATE` `TIMESTAMP` `INTERVAL` `X`, so
that's not a concern.
> Null literal is supported. We should use null instead of "null" to
represent it.
It's solved since #30538
> If the literal data type doesn't match the partition column data type,
we should do type check and cast like normal table insertion.
Seems there is auto type conversion. I will check this with UT
----------------------------------------------------------------
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]