-
Notifications
You must be signed in to change notification settings - Fork 29.3k
[SPARK-24860][SQL] Support setting of partitionOverWriteMode in output options for writing DataFrame #21818
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
[SPARK-24860][SQL] Support setting of partitionOverWriteMode in output options for writing DataFrame #21818
Changes from 2 commits
7dd2eab
7d0752b
605a325
a4ebf9d
03c0926
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 |
|---|---|---|
|
|
@@ -27,6 +27,7 @@ import org.apache.spark.sql.catalyst.catalog.{BucketSpec, CatalogTable, CatalogT | |
| import org.apache.spark.sql.catalyst.catalog.CatalogTypes.TablePartitionSpec | ||
| import org.apache.spark.sql.catalyst.expressions.Attribute | ||
| import org.apache.spark.sql.catalyst.plans.logical.LogicalPlan | ||
| import org.apache.spark.sql.catalyst.util.CaseInsensitiveMap | ||
| import org.apache.spark.sql.execution.SparkPlan | ||
| import org.apache.spark.sql.execution.command._ | ||
| import org.apache.spark.sql.internal.SQLConf.PartitionOverwriteMode | ||
|
|
@@ -91,8 +92,12 @@ case class InsertIntoHadoopFsRelationCommand( | |
|
|
||
| val pathExists = fs.exists(qualifiedOutputPath) | ||
|
|
||
| val enableDynamicOverwrite = | ||
| sparkSession.sessionState.conf.partitionOverwriteMode == PartitionOverwriteMode.DYNAMIC | ||
| val parameters = CaseInsensitiveMap(options) | ||
|
|
||
| val enableDynamicOverwrite = parameters.get("partitionOverwriteMode") | ||
| .map(mode => PartitionOverwriteMode.withName(mode.toUpperCase)) | ||
| .getOrElse(sparkSession.sessionState.conf.partitionOverwriteMode) == | ||
| PartitionOverwriteMode.DYNAMIC | ||
|
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. nit: this is too long |
||
| // This config only makes sense when we are overwriting a partitioned dataset with dynamic | ||
| // partition columns. | ||
| val dynamicPartitionOverwrite = enableDynamicOverwrite && mode == SaveMode.Overwrite && | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -486,6 +486,25 @@ class InsertSuite extends DataSourceTest with SharedSQLContext { | |
| } | ||
| } | ||
| } | ||
| test("SPARK-24860: dynamic partition overwrite specified per source without catalog table") { | ||
|
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. nit: add a blank file before this new test case |
||
| withTempPath { path => | ||
| Seq((1, 1, 1)).toDF("i", "part1", "part2") | ||
|
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. can we simplify the test? ideally we only need one partition column, and write some initial data to the table. then do an overwrite with partitionOverwriteMode=dynamic, and another overwrite with partitionOverwriteMode=static. |
||
| .write.partitionBy("part1", "part2") | ||
| .option("partitionOverwriteMode", "dynamic") | ||
| .parquet(path.getAbsolutePath) | ||
| checkAnswer(spark.read.parquet(path.getAbsolutePath), Row(1, 1, 1)) | ||
|
|
||
| Seq((2, 1, 1)).toDF("i", "part1", "part2") | ||
| .write.partitionBy("part1", "part2").mode("overwrite") | ||
| .option("partitionOverwriteMode", "dynamic").parquet(path.getAbsolutePath) | ||
| checkAnswer(spark.read.parquet(path.getAbsolutePath), Row(2, 1, 1)) | ||
|
|
||
| Seq((2, 2, 2)).toDF("i", "part1", "part2") | ||
| .write.partitionBy("part1", "part2").mode("overwrite") | ||
| .option("partitionOverwriteMode", "dynamic").parquet(path.getAbsolutePath) | ||
| checkAnswer(spark.read.parquet(path.getAbsolutePath), Row(2, 1, 1) :: Row(2, 2, 2) :: Nil) | ||
| } | ||
| } | ||
|
|
||
| test("SPARK-20236: dynamic partition overwrite") { | ||
| withSQLConf(SQLConf.PARTITION_OVERWRITE_MODE.key -> PartitionOverwriteMode.DYNAMIC.toString) { | ||
|
|
||
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.
Also need to explain the precedence between the option and sqlconf.