-
Notifications
You must be signed in to change notification settings - Fork 29k
[SPARK-29786][SQL] Fix MetaException when dropping a partition not exists on HDFS #26422
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 11 commits
90233e4
7a246d5
783211f
355496e
74d5984
84b1da8
248b6cf
c20c390
9d75854
5a5ff74
f4b3793
4d1c35e
7cf7c6b
f8b96de
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,8 +27,8 @@ import scala.collection.JavaConverters._ | |
| import scala.collection.mutable | ||
| import scala.collection.mutable.ArrayBuffer | ||
|
|
||
| import org.apache.hadoop.fs.Path | ||
| import org.apache.hadoop.hive.common.StatsSetupConst | ||
| import org.apache.hadoop.fs.{Path, PathFilter} | ||
| import org.apache.hadoop.hive.common.{FileUtils, StatsSetupConst} | ||
| import org.apache.hadoop.hive.conf.HiveConf | ||
| import org.apache.hadoop.hive.conf.HiveConf.ConfVars | ||
| import org.apache.hadoop.hive.metastore.{IMetaStoreClient, TableType => HiveTableType} | ||
|
|
@@ -616,6 +616,23 @@ private[hive] class HiveClientImpl( | |
| shim.createPartitions(client, db, table, parts, ignoreIfExists) | ||
| } | ||
|
|
||
| val HIDDEN_FILES_PATH_FILTER: PathFilter = (p: Path) => { | ||
| val name = p.getName | ||
| !name.startsWith("_") && !name.startsWith(".") | ||
| } | ||
|
|
||
| @throws[Exception] | ||
| private def isEmptyPath(dirPath: Path): Boolean = { | ||
| val inpFs = dirPath.getFileSystem(conf) | ||
| if (inpFs.exists(dirPath)) { | ||
| val fStats = inpFs.listStatus(dirPath, HIDDEN_FILES_PATH_FILTER) | ||
| if (fStats.nonEmpty) { | ||
| return false | ||
| } | ||
| } | ||
| true | ||
| } | ||
|
|
||
| override def dropPartitions( | ||
| db: String, | ||
| table: String, | ||
|
|
@@ -638,6 +655,17 @@ private[hive] class HiveClientImpl( | |
| s"No partition is dropped. One partition spec '$s' does not exist in table '$table' " + | ||
| s"database '$db'") | ||
| } | ||
| // Check whether the partition we are going to drop is empty. | ||
| // We make a dummy one for the empty partition. See [SPARK-29786] for more details. | ||
| parts.foreach { partition => | ||
| val partPath = partition.getPath.head | ||
| if (isEmptyPath(partPath)) { | ||
|
||
| val fs = partPath.getFileSystem(conf) | ||
| fs.mkdirs(partPath) | ||
| fs.deleteOnExit(partPath) | ||
| } | ||
| partition | ||
| } | ||
| parts.map(_.getValues) | ||
| }.distinct | ||
| var droppedParts = ArrayBuffer.empty[java.util.List[String]] | ||
|
|
||
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.
is this how hive resolve the problem?
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.
Yes, It's the same method as Hive uses.
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.
Isn't it bad for performance? i.e. you call
fs.existsandfs.listStatusfor each partition.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.
Yes, but only affect
drop partitions. I think it's necessary and won't take much time to do the check while dropping.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.
Can you point to the Hive source code that does the same thing? i.e. create a dummy directory before dropping the partition.
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.
In Hive 1.x, it's like this.
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.
is it for DROP PARTITION?
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.
No, it will check every query before executing. Maybe it's better to do the check before all queries?
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.
Does Spark have a problem to do table scan when partition directory not exist?
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.
It's related to #24668, and controlled by
spark.sql.files.ignoreMissingFiles.Spark will check it when listing leaf files.