Github user rdblue commented on a diff in the pull request:
https://github.com/apache/spark/pull/12239#discussion_r60611716
--- Diff:
sql/hive/src/test/scala/org/apache/spark/sql/hive/InsertIntoHiveTableSuite.scala
---
@@ -259,4 +261,78 @@ class InsertIntoHiveTableSuite extends QueryTest with
TestHiveSingleton with Bef
sql("DROP TABLE table_with_partition")
}
+
+ test("Reject partitioning that does not match table") {
+ sqlContext.setConf("hive.exec.dynamic.partition.mode", "nonstrict")
+ sql("CREATE TABLE partitioned (id bigint, data string) PARTITIONED BY
(part string)")
+ val data = (1 to 10).map(i => (i, s"data-$i", if ((i % 2) == 0) "even"
else "odd"))
+ .toDF("id", "data", "part")
+
+ intercept[AnalysisException] {
+ // cannot partition by 2 fields when there is only one in the table
definition
+ data.write.partitionBy("part", "data").insertInto("partitioned")
+ }
+ }
+
+ test("Test partition mode = strict") {
+ sqlContext.conf.unsetConf("hive.exec.dynamic.partition.mode")
+ sql("CREATE TABLE partitioned (id bigint, data string) PARTITIONED BY
(part string)")
+ val data = (1 to 10).map(i => (i, s"data-$i", if ((i % 2) == 0) "even"
else "odd"))
+ .toDF("id", "data", "part")
+
+ intercept[SparkException] {
+ data.write.insertInto("partitioned")
+ }
+ }
+
+ test("Detect table partitioning") {
+ sqlContext.setConf("hive.exec.dynamic.partition.mode", "nonstrict")
+
+ sql("CREATE TABLE source (id bigint, data string, part string)")
+ val data = (1 to 10).map(i => (i, s"data-$i", if ((i % 2) == 0) "even"
else "odd")).toDF()
+
+ data.write.insertInto("source")
+ checkAnswer(sql("SELECT * FROM source"), data.collect().toSeq)
+
+ sql("CREATE TABLE partitioned (id bigint, data string) PARTITIONED BY
(part string)")
+ // this will pick up the output partitioning from the table definition
+ sqlContext.table("source").write.insertInto("partitioned")
+
+ checkAnswer(sql("SELECT * FROM partitioned"), data.collect().toSeq)
+
+ sqlContext.conf.unsetConf("hive.exec.dynamic.partition.mode")
+ }
+
+ test("Detect table partitioning with correct partition order") {
--- End diff --
@cloud-fan, this is the test that checks partition columns are in the
correct order for the table (since Hive assumes they are when writing).
---
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]