-
Notifications
You must be signed in to change notification settings - Fork 29k
[SPARK-18659] [SQL] Incorrect behaviors in overwrite table for datasource tables #16088
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 2 commits
f3875ae
4b6a4ee
c68bc81
f4356f0
b79cef4
a9f9710
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 |
|---|---|---|
|
|
@@ -687,13 +687,14 @@ class SessionCatalog( | |
| tableName: TableIdentifier, | ||
| specs: Seq[TablePartitionSpec], | ||
| ignoreIfNotExists: Boolean, | ||
| purge: Boolean): Unit = { | ||
| purge: Boolean, | ||
| retainData: Boolean): Unit = { | ||
|
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. shall we provide a default value? looks like most of the time we want it to be false
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. It seemed a little safer to make it mandatory to avoid some component forgetting to propagate it. |
||
| val db = formatDatabaseName(tableName.database.getOrElse(getCurrentDatabase)) | ||
| val table = formatTableName(tableName.table) | ||
| requireDbExists(db) | ||
| requireTableExists(TableIdentifier(table, Option(db))) | ||
| requirePartialMatchedPartitionSpec(specs, getTableMetadata(tableName)) | ||
| externalCatalog.dropPartitions(db, table, specs, ignoreIfNotExists, purge) | ||
| externalCatalog.dropPartitions(db, table, specs, ignoreIfNotExists, purge, retainData) | ||
| } | ||
|
|
||
| /** | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -217,16 +217,25 @@ case class DataSourceAnalysis(conf: CatalystConf) extends Rule[LogicalPlan] { | |
| if (deletedPartitions.nonEmpty) { | ||
| AlterTableDropPartitionCommand( | ||
| l.catalogTable.get.identifier, deletedPartitions.toSeq, | ||
| ifExists = true, purge = true).run(t.sparkSession) | ||
| ifExists = true, purge = true, | ||
|
||
| retainData = true /* already deleted */).run(t.sparkSession) | ||
| } | ||
| } | ||
| } | ||
| t.location.refresh() | ||
| } | ||
|
|
||
| val staticPartitionKeys: TablePartitionSpec = if (overwrite.enabled) { | ||
| overwrite.staticPartitionKeys.map { case (k, v) => | ||
| (partitionSchema.map(_.name).find(_.equalsIgnoreCase(k)).get, v) | ||
| } | ||
| } else { | ||
| Map.empty | ||
| } | ||
|
|
||
| val insertCmd = InsertIntoHadoopFsRelationCommand( | ||
| outputPath, | ||
| if (overwrite.enabled) overwrite.staticPartitionKeys else Map.empty, | ||
| staticPartitionKeys, | ||
| customPartitionLocations, | ||
| partitionSchema, | ||
| t.bucketSpec, | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -847,9 +847,11 @@ private[spark] class HiveExternalCatalog(conf: SparkConf, hadoopConf: Configurat | |
| table: String, | ||
| parts: Seq[TablePartitionSpec], | ||
| ignoreIfNotExists: Boolean, | ||
| purge: Boolean): Unit = withClient { | ||
| purge: Boolean, | ||
| deleteFiles: Boolean): Unit = withClient { | ||
|
||
| requireTableExists(db, table) | ||
| client.dropPartitions(db, table, parts.map(lowerCasePartitionSpec), ignoreIfNotExists, purge) | ||
| client.dropPartitions( | ||
| db, table, parts.map(lowerCasePartitionSpec), ignoreIfNotExists, purge, deleteFiles) | ||
| } | ||
|
|
||
| override def renamePartitions( | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.
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.
shall we put the
!retainDatain the definition ofshouldRemovePartitionLocation? which looks more logicalThere 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.
Done