-
Notifications
You must be signed in to change notification settings - Fork 29k
[SPARK-16313][SQL][BRANCH-1.6] Spark should not silently drop exceptions in file listing #14139
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
Closed
Closed
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
a0387ad
Spark should not silently drop exceptions in file listing
yhuai b98ee09
Fix tests
yhuai 5aaa96b
Comments and format
yhuai 5d66df7
More comments
yhuai 82d3711
Update
yhuai af5b7b3
Make it clear that it is a hack
yhuai 072aa3f
Add pr link
yhuai File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -273,6 +273,22 @@ private[hive] class HiveMetastoreCatalog(val client: ClientInterface, hive: Hive | |
| serdeProperties = options) | ||
| } | ||
|
|
||
| def hasPartitionColumns(relation: HadoopFsRelation): Boolean = { | ||
| try { | ||
| // HACK for "[SPARK-16313][SQL][BRANCH-1.6] Spark should not silently drop exceptions in | ||
| // file listing" https://github.com/apache/spark/pull/14139 | ||
| // Calling hadoopFsRelation.partitionColumns will trigger the refresh call of | ||
| // the HadoopFsRelation, which will validate input paths. However, when we create | ||
| // an empty table, the dir of the table has not been created, which will | ||
| // cause a FileNotFoundException. So, at here we will catch the FileNotFoundException | ||
| // and return false. | ||
| relation.partitionColumns.nonEmpty | ||
| } catch { | ||
| case _: java.io.FileNotFoundException => | ||
| 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. This function is equivalent with |
||
|
|
||
| def newHiveCompatibleMetastoreTable(relation: HadoopFsRelation, serde: HiveSerDe): HiveTable = { | ||
| def schemaToHiveColumn(schema: StructType): Seq[HiveColumn] = { | ||
| schema.map { field => | ||
|
|
@@ -284,12 +300,18 @@ private[hive] class HiveMetastoreCatalog(val client: ClientInterface, hive: Hive | |
| } | ||
|
|
||
| assert(partitionColumns.isEmpty) | ||
| assert(relation.partitionColumns.isEmpty) | ||
| assert(!hasPartitionColumns(relation)) | ||
|
|
||
| HiveTable( | ||
| specifiedDatabase = Option(dbName), | ||
| name = tblName, | ||
| schema = schemaToHiveColumn(relation.schema), | ||
| // HACK for "[SPARK-16313][SQL][BRANCH-1.6] Spark should not silently drop exceptions in | ||
| // file listing" https://github.com/apache/spark/pull/14139 | ||
| // Since the table is not partitioned, we use dataSchema instead of using schema. | ||
| // Using schema which will trigger partition discovery on the path that | ||
| // may not be created causing FileNotFoundException. So, we just get dataSchema | ||
| // instead of calling relation.schema. | ||
| schema = schemaToHiveColumn(relation.dataSchema), | ||
| partitionColumns = Nil, | ||
| tableType = tableType, | ||
| properties = tableProperties.toMap, | ||
|
|
@@ -312,14 +334,14 @@ private[hive] class HiveMetastoreCatalog(val client: ClientInterface, hive: Hive | |
| (None, message) | ||
|
|
||
| case (Some(serde), relation: HadoopFsRelation) | ||
| if relation.paths.length == 1 && relation.partitionColumns.isEmpty => | ||
| if relation.paths.length == 1 && !hasPartitionColumns(relation) => | ||
| val hiveTable = newHiveCompatibleMetastoreTable(relation, serde) | ||
| val message = | ||
| s"Persisting data source relation $qualifiedTableName with a single input path " + | ||
| s"into Hive metastore in Hive compatible format. Input path: ${relation.paths.head}." | ||
| (Some(hiveTable), message) | ||
|
|
||
| case (Some(serde), relation: HadoopFsRelation) if relation.partitionColumns.nonEmpty => | ||
| case (Some(serde), relation: HadoopFsRelation) if hasPartitionColumns(relation) => | ||
| val message = | ||
| s"Persisting partitioned data source relation $qualifiedTableName into " + | ||
| "Hive metastore in Spark SQL specific format, which is NOT compatible with Hive. " + | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
I'd add to the comment that this is a hack for [SPARK-16313][SQL][BRANCH-1.6] Spark should not silently drop exceptions in file listing
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.
Done