-
Notifications
You must be signed in to change notification settings - Fork 28.6k
[SPARK-18087] [SQL] Optimize insert to not require REPAIR TABLE #15633
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 |
---|---|---|
|
@@ -26,6 +26,7 @@ import org.apache.spark.sql.catalyst.{CatalystConf, CatalystTypeConverters, Inte | |
import org.apache.spark.sql.catalyst.CatalystTypeConverters.convertToScala | ||
import org.apache.spark.sql.catalyst.analysis._ | ||
import org.apache.spark.sql.catalyst.catalog.{CatalogTable, SimpleCatalogRelation} | ||
import org.apache.spark.sql.catalyst.catalog.CatalogTypes.TablePartitionSpec | ||
import org.apache.spark.sql.catalyst.expressions | ||
import org.apache.spark.sql.catalyst.expressions._ | ||
import org.apache.spark.sql.catalyst.planning.PhysicalOperation | ||
|
@@ -34,7 +35,7 @@ import org.apache.spark.sql.catalyst.plans.logical.{LogicalPlan, Project, Union} | |
import org.apache.spark.sql.catalyst.plans.physical.{HashPartitioning, UnknownPartitioning} | ||
import org.apache.spark.sql.catalyst.rules.Rule | ||
import org.apache.spark.sql.execution.{RowDataSourceScanExec, SparkPlan} | ||
import org.apache.spark.sql.execution.command.{AlterTableRecoverPartitionsCommand, DDLUtils, ExecutedCommandExec} | ||
import org.apache.spark.sql.execution.command.{AlterTableAddPartitionCommand, DDLUtils, ExecutedCommandExec} | ||
import org.apache.spark.sql.sources._ | ||
import org.apache.spark.sql.types._ | ||
import org.apache.spark.unsafe.types.UTF8String | ||
|
@@ -179,24 +180,30 @@ case class DataSourceAnalysis(conf: CatalystConf) extends Rule[LogicalPlan] { | |
"Cannot overwrite a path that is also being read from.") | ||
} | ||
|
||
def refreshPartitionsCallback(updatedPartitions: Seq[TablePartitionSpec]): Unit = { | ||
if (l.catalogTable.isDefined && | ||
l.catalogTable.get.partitionColumnNames.nonEmpty && | ||
l.catalogTable.get.partitionProviderIsHive) { | ||
val metastoreUpdater = AlterTableAddPartitionCommand( | ||
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 just copy the main logic of 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'd rather keep it, since the fetch overhead is pretty small |
||
l.catalogTable.get.identifier, | ||
updatedPartitions.map(p => (p, None)), | ||
ifNotExists = true) | ||
metastoreUpdater.run(t.sparkSession) | ||
} | ||
t.location.refresh() | ||
} | ||
|
||
val insertCmd = InsertIntoHadoopFsRelationCommand( | ||
outputPath, | ||
query.resolve(t.partitionSchema, t.sparkSession.sessionState.analyzer.resolver), | ||
t.bucketSpec, | ||
t.fileFormat, | ||
() => t.location.refresh(), | ||
refreshPartitionsCallback, | ||
t.options, | ||
query, | ||
mode) | ||
|
||
if (l.catalogTable.isDefined && l.catalogTable.get.partitionColumnNames.nonEmpty && | ||
l.catalogTable.get.partitionProviderIsHive) { | ||
// TODO(ekl) we should be more efficient here and only recover the newly added partitions | ||
val recoverPartitionCmd = AlterTableRecoverPartitionsCommand(l.catalogTable.get.identifier) | ||
Union(insertCmd, recoverPartitionCmd) | ||
} else { | ||
insertCmd | ||
} | ||
insertCmd | ||
} | ||
} | ||
|
||
|
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 move this
if
out of the function? e.g.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.
imo that is a little harder to read, since you have two anonymous function declarations instead of one.