-
Notifications
You must be signed in to change notification settings - Fork 29.2k
[SPARK-19153][SQL]DataFrameWriter.saveAsTable work with create partitioned table #16593
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
windpiger
wants to merge
24
commits into
apache:master
from
windpiger:saveAsTableWithPartitionedTable
Closed
Changes from all commits
Commits
Show all changes
24 commits
Select commit
Hold shift + click to select a range
6c31d01
[SPARK-19153][SQL]DataFrameWriter.saveAsTable work with create partit…
windpiger 7c09a7c
fix a code style
windpiger 046ead7
fix the schema order with partiontionkeys
windpiger 6d2cec6
merge with master fix confilcts
windpiger 76f643a
remove a empty line
windpiger 4122c5f
reset nonstrict conf in testcast,and option some code
windpiger 4612a52
remove a empty line
windpiger f40adbe
optimize some code
windpiger a656474
remove a redundant in table
windpiger 0b0e64b
optimize some code
windpiger d15b947
change a comment
windpiger 2da6c7e
fix a style
windpiger ef16944
modify test case
windpiger 9270851
modify a comment
windpiger 8ff256a
fix tc
windpiger 14aed85
modify a comment
windpiger 7d38fae
add some test case
windpiger 2f04952
fix test case failed
windpiger 082abd2
delete a comment
windpiger 4410de9
modify the test case
windpiger 21f113a
fix a test case
windpiger c7896c3
merget with master and modify some logic
windpiger 4c50f49
remove some useless import
windpiger 7bdc265
fix test case
windpiger File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -1353,12 +1353,6 @@ class HiveDDLSuite | |
| sql("INSERT INTO t SELECT 2, 'b'") | ||
| checkAnswer(spark.table("t"), Row(9, "x") :: Row(2, "b") :: Nil) | ||
|
|
||
| val e = intercept[AnalysisException] { | ||
| Seq(1 -> "a").toDF("i", "j").write.format("hive").partitionBy("i").saveAsTable("t2") | ||
| } | ||
| assert(e.message.contains("A Create Table As Select (CTAS) statement is not allowed " + | ||
| "to create a partitioned table using Hive")) | ||
|
|
||
| val e2 = intercept[AnalysisException] { | ||
| Seq(1 -> "a").toDF("i", "j").write.format("hive").bucketBy(4, "i").saveAsTable("t2") | ||
| } | ||
|
|
@@ -1371,6 +1365,22 @@ class HiveDDLSuite | |
| } | ||
| } | ||
|
|
||
| test("create partitioned hive serde table as select") { | ||
| 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) | ||
|
|
||
| Seq((1, 2, 3)).toDF("i", "j", "k").write.mode("overwrite").format("hive") | ||
| .partitionBy("j", "k").saveAsTable("t") | ||
| checkAnswer(spark.table("t"), Row(1, 2, 3) :: Nil) | ||
|
|
||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think this test case is a bit fat, maybe we can split it into two or three smaller ones? e.g.: test("create hive serde table with DataFrameWriter.saveAsTable - basic") ...
test("create hive serde table with DataFrameWriter.saveAsTable - overwrite and append") ...
test("create hive serde table with DataFrameWriter.saveAsTable - partitioned") ... |
||
| spark.sql("create table t1 using hive partitioned by (i) as select 1 as i, 'a' as j") | ||
| checkAnswer(spark.table("t1"), Row("a", 1) :: Nil) | ||
| } | ||
| } | ||
| } | ||
|
|
||
| test("read/write files with hive data source is not allowed") { | ||
| withTempDir { dir => | ||
| val e = intercept[AnalysisException] { | ||
|
|
@@ -1390,7 +1400,7 @@ class HiveDDLSuite | |
| spark.sessionState.catalog.getTableMetadata(TableIdentifier(tblName)).schema.map(_.name) | ||
| } | ||
|
|
||
| withTable("t", "t1", "t2", "t3", "t4") { | ||
| withTable("t", "t1", "t2", "t3", "t4", "t5", "t6") { | ||
| sql("CREATE TABLE t(a int, b int, c int, d int) USING parquet PARTITIONED BY (d, b)") | ||
| assert(getTableColumns("t") == Seq("a", "c", "d", "b")) | ||
|
|
||
|
|
@@ -1411,7 +1421,14 @@ class HiveDDLSuite | |
| sql("CREATE TABLE t4(a int, b int, c int, d int) USING hive PARTITIONED BY (d, b)") | ||
| assert(getTableColumns("t4") == Seq("a", "c", "d", "b")) | ||
|
|
||
| // TODO: add test for creating partitioned hive serde table as select, once we support it. | ||
| withSQLConf("hive.exec.dynamic.partition.mode" -> "nonstrict") { | ||
| sql("CREATE TABLE t5 USING hive PARTITIONED BY (d, b) AS SELECT 1 a, 1 b, 1 c, 1 d") | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. please also test |
||
| assert(getTableColumns("t5") == Seq("a", "c", "d", "b")) | ||
|
|
||
| Seq((1, 1, 1, 1)).toDF("a", "b", "c", "d").write.format("hive") | ||
| .partitionBy("d", "b").saveAsTable("t6") | ||
| assert(getTableColumns("t6") == Seq("a", "c", "d", "b")) | ||
| } | ||
| } | ||
| } | ||
| } | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we don't need to test
overwritebehavior so many times, just create a table withSeq(10 -> "y").toDF("i", "j").write.partitionBy("i")and overwrite it withSeq((1, 2, 3)).toDF("i", "j", "k").write.partitionBy("j", "k")