-
Notifications
You must be signed in to change notification settings - Fork 29.2k
[SPARK-36563][SQL] dynamicPartitionOverwrite can direct rename to targetPath instead of partition path one by one when targetPath is empty #33811
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -1224,6 +1224,16 @@ object SQLConf { | |
| .stringConf | ||
| .createOptional | ||
|
|
||
| val FILE_STAGING_DIR = | ||
| buildConf("spark.sql.source.stagingDir") | ||
|
Member
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. This looks orthogonal what your PR aims. Could you spin off this new configuration as a new PR?
Contributor
Author
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. Let me do this first. |
||
| .doc("The staging directory of Spark job. Spark uses it to deal with files with " + | ||
| "absolute output path, or writing data into partitioned directory when " + | ||
| "dynamic partition overwrite mode.") | ||
| .version("3.3.0") | ||
| .internal() | ||
| .stringConf | ||
| .createWithDefault(".spark-staging") | ||
|
|
||
| val FILE_COMMIT_PROTOCOL_CLASS = | ||
| buildConf("spark.sql.sources.commitProtocolClass") | ||
| .version("2.1.1") | ||
|
|
@@ -3824,6 +3834,8 @@ class SQLConf extends Serializable with Logging { | |
| def partitionColumnTypeInferenceEnabled: Boolean = | ||
| getConf(SQLConf.PARTITION_COLUMN_TYPE_INFERENCE) | ||
|
|
||
| def fileStagingDir: String = getConf(SQLConf.FILE_STAGING_DIR) | ||
|
|
||
| def fileCommitProtocolClass: String = getConf(SQLConf.FILE_COMMIT_PROTOCOL_CLASS) | ||
|
|
||
| def parallelPartitionDiscoveryThreshold: Int = | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -189,6 +189,33 @@ class PartitionedWriteSuite extends QueryTest with SharedSparkSession { | |
| } | ||
| } | ||
| } | ||
|
|
||
| test("SPARK-36563: dynamic partition overwrite can rename table path when reasonable") { | ||
| withTempDir { stagingDir => | ||
| withSQLConf(SQLConf.PARTITION_OVERWRITE_MODE.key -> | ||
| SQLConf.PartitionOverwriteMode.DYNAMIC.toString, | ||
| SQLConf.FILE_STAGING_DIR.key -> stagingDir.getAbsolutePath) { | ||
| withTempDir { d => | ||
| withTable("t") { | ||
| sql( | ||
| s""" | ||
| | CREATE TABLE t(c1 int, p1 int) USING PARQUET PARTITIONED BY(p1) | ||
| | LOCATION '${d.getAbsolutePath}' | ||
| """.stripMargin) | ||
|
|
||
| val df = Seq((1, 2), (3, 4)).toDF("c1", "p1") | ||
| df.write | ||
| .partitionBy("p1") | ||
| .mode("overwrite") | ||
| .saveAsTable("t") | ||
| checkAnswer(sql("SELECT * FROM t"), df) | ||
| checkAnswer(sql("SELECT * FROM t WHERE p1 = 2"), Row(1, 2) :: Nil) | ||
| checkAnswer(sql("SELECT * FROM t WHERE p1 = 4"), Row(3, 4) :: Nil) | ||
|
Member
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. Does this test case fail before your PR? IIUC, this doesn't provide a test coverage.
Contributor
Author
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.
Just to show in new way, it can write data as before? |
||
| } | ||
| } | ||
| } | ||
| } | ||
| } | ||
| } | ||
|
|
||
| /** | ||
|
|
||
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.
Do we have a test coverage for both
fs.existandfs.listStatus?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.
Should have