Github user cloud-fan commented on a diff in the pull request:
https://github.com/apache/spark/pull/16593#discussion_r96785016
--- Diff:
sql/hive/src/test/scala/org/apache/spark/sql/hive/execution/HiveDDLSuite.scala
---
@@ -1361,6 +1355,38 @@ class HiveDDLSuite
}
}
+ test("create hive serde table as select with DataFrameWriter.saveAsTable
with partitionBy") {
+ withTable("t", "t1") {
+ withSQLConf("hive.exec.dynamic.partition.mode" -> "nonstrict") {
+ Seq(10 -> "y").toDF("i",
"j").write.format("hive").partitionBy("i").saveAsTable("t")
+ checkAnswer(spark.table("t"), Row("y", 10) :: Nil)
+ var table =
spark.sessionState.catalog.getTableMetadata(TableIdentifier("t"))
+ var partitionSchema = table.partitionSchema
+ assert(partitionSchema.size == 1 && partitionSchema.fields(0).name
== "i" &&
+ partitionSchema.fields(0).dataType == IntegerType)
+
+ Seq(11 -> "z").toDF("i",
"j").write.mode("overwrite").format("hive")
+ .partitionBy("j").saveAsTable("t")
+ checkAnswer(spark.table("t"), Row(11, "z") :: Nil)
+ table =
spark.sessionState.catalog.getTableMetadata(TableIdentifier("t"))
+ partitionSchema = table.partitionSchema
+ assert(partitionSchema.size == 1 && partitionSchema.fields(0).name
== "j" &&
+ partitionSchema.fields(0).dataType == StringType)
+
+ Seq((1, 2, 3)).toDF("i", "j",
"k").write.mode("overwrite").format("hive")
+ .partitionBy("k", "j").saveAsTable("t")
+ checkAnswer(spark.table("t"), Row(1, 3, 2) :: Nil)
+
+ Seq((1, 2, 3)).toDF("i", "j",
"k").write.mode("overwrite").format("hive")
--- End diff --
I think we don't need to test `overwrite` behavior so many times, just
create a table with `Seq(10 -> "y").toDF("i", "j").write.partitionBy("i")` and
overwrite it with `Seq((1, 2, 3)).toDF("i", "j", "k").write.partitionBy("j",
"k")`
---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at [email protected] or file a JIRA ticket
with INFRA.
---
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]