-
Notifications
You must be signed in to change notification settings - Fork 29.3k
[SPARK-18107][SQL] Insert overwrite statement runs much slower in spark-sql than it does in hive-client #15667
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 3 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 |
|---|---|---|
|
|
@@ -37,6 +37,7 @@ import org.apache.spark.sql.catalyst.InternalRow | |
| import org.apache.spark.sql.catalyst.expressions.Attribute | ||
| import org.apache.spark.sql.catalyst.plans.physical.Partitioning | ||
| import org.apache.spark.sql.execution.{SparkPlan, UnaryExecNode} | ||
| import org.apache.spark.sql.execution.command.{AlterTableAddPartitionCommand, AlterTableDropPartitionCommand} | ||
| import org.apache.spark.sql.hive._ | ||
| import org.apache.spark.sql.hive.HiveShim.{ShimFileSinkDesc => FileSinkDesc} | ||
| import org.apache.spark.SparkException | ||
|
|
@@ -257,7 +258,31 @@ case class InsertIntoHiveTable( | |
| table.catalogTable.identifier.table, | ||
| partitionSpec) | ||
|
|
||
| var doOverwrite = overwrite | ||
|
|
||
| if (oldPart.isEmpty || !ifNotExists) { | ||
| // SPARK-18107: Insert overwrite runs much slower than hive-client. | ||
| // Newer Hive largely improves insert overwrite performance. As Spark uses older Hive | ||
| // version and we may not want to catch up new Hive version every time. We delete the | ||
| // Hive partition first and then load data file into the Hive partition. | ||
| if (oldPart.nonEmpty && overwrite) { | ||
| oldPart.get.storage.locationUri.map { uri => | ||
| val partitionPath = new Path(uri) | ||
| val fs = partitionPath.getFileSystem(hadoopConf) | ||
| if (fs.exists(partitionPath)) { | ||
| val pathPermission = fs.getFileStatus(partitionPath).getPermission() | ||
| if (!fs.delete(partitionPath, true)) { | ||
| throw new RuntimeException( | ||
| "Cannot remove partition directory '" + partitionPath.toString) | ||
| } else { | ||
| fs.mkdirs(partitionPath, pathPermission) | ||
|
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. Is the mkdir necessary?
Member
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. I was thinking Hive will complain if the dir is not existing. But looks like it won't. Let me remove this and see if all tests can be passed. |
||
| } | ||
| // Don't let Hive do overwrite operation since it is slower. | ||
| doOverwrite = false | ||
| } | ||
| } | ||
| } | ||
|
|
||
| // inheritTableSpecs is set to true. It should be set to false for an IMPORT query | ||
| // which is currently considered as a Hive native command. | ||
| val inheritTableSpecs = true | ||
|
|
@@ -266,7 +291,7 @@ case class InsertIntoHiveTable( | |
| table.catalogTable.identifier.table, | ||
| outputPath.toString, | ||
| partitionSpec, | ||
| isOverwrite = overwrite, | ||
| isOverwrite = doOverwrite, | ||
| holdDDLTime = holdDDLTime, | ||
| inheritTableSpecs = inheritTableSpecs) | ||
| } | ||
|
|
||
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.
nit:
doHiveOverwrite?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.
ok. updated.