-
Notifications
You must be signed in to change notification settings - Fork 29k
[SPARK-6024][SQL] When a data source table has too many columns, it's schema cannot be stored in metastore. #4795
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 3 commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
e9b4f70
Failed test.
yhuai 12bacae
If the JSON string of a schema is too large, split it before storing …
yhuai cc1d472
Make the schema wider.
yhuai 143927a
Simplify code.
yhuai 73e71b4
Address comments.
yhuai 4882e6f
Address comments.
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -69,13 +69,25 @@ private[hive] class HiveMetastoreCatalog(hive: HiveContext) extends Catalog with | |
| val table = synchronized { | ||
| client.getTable(in.database, in.name) | ||
| } | ||
| val schemaString = table.getProperty("spark.sql.sources.schema") | ||
| val userSpecifiedSchema = | ||
| if (schemaString == null) { | ||
| None | ||
| } else { | ||
| Some(DataType.fromJson(schemaString).asInstanceOf[StructType]) | ||
| val schemaString = Option(table.getProperty("spark.sql.sources.schema")) | ||
| .orElse { | ||
| // If spark.sql.sources.schema is not defined, we either splitted the schema to multiple | ||
| // parts or the schema was not defined. To determine if the schema was defined, | ||
| // we check spark.sql.sources.schema.numOfParts. | ||
| Option(table.getProperty("spark.sql.sources.schema.numOfParts")) match { | ||
| case Some(numOfParts) => | ||
| val parts = (0 until numOfParts.toInt).map { index => | ||
| Option(table.getProperty(s"spark.sql.sources.schema.part.${index}")) | ||
| .getOrElse("Could not read schema from the metastore because it is corrupted.") | ||
| } | ||
| // Stick all parts back to a single schema string in the JSON representation. | ||
| Some(parts.mkString) | ||
| case None => None // The schema was not defined. | ||
| } | ||
| } | ||
|
|
||
| val userSpecifiedSchema = | ||
| schemaString.flatMap(s => Some(DataType.fromJson(s).asInstanceOf[StructType])) | ||
| // It does not appear that the ql client for the metastore has a way to enumerate all the | ||
| // SerDe properties directly... | ||
| val options = table.getTTable.getSd.getSerdeInfo.getParameters.toMap | ||
|
|
@@ -119,7 +131,26 @@ private[hive] class HiveMetastoreCatalog(hive: HiveContext) extends Catalog with | |
|
|
||
| tbl.setProperty("spark.sql.sources.provider", provider) | ||
| if (userSpecifiedSchema.isDefined) { | ||
| tbl.setProperty("spark.sql.sources.schema", userSpecifiedSchema.get.json) | ||
| val threshold = hive.conf.schemaStringLengthThreshold | ||
| val schemaJsonString = userSpecifiedSchema.get.json | ||
| // Check if the size of the JSON string of the schema exceeds the threshold. | ||
| if (schemaJsonString.size > threshold) { | ||
| // Need to split the string. | ||
| val parts = schemaJsonString.grouped(threshold).toSeq | ||
| // First, record the total number of parts we have. | ||
| tbl.setProperty("spark.sql.sources.schema.numOfParts", parts.size.toString) | ||
| // Second, write every part to table property. | ||
| parts.zipWithIndex.foreach { | ||
| case (part, index) => | ||
| tbl.setProperty(s"spark.sql.sources.schema.part.${index}", part) | ||
| } | ||
| } else { | ||
| // The length is less than the threshold, just put it in the table property. | ||
| tbl.setProperty("spark.sql.sources.schema.numOfParts", "1") | ||
| // We use spark.sql.sources.schema instead of using spark.sql.sources.schema.part.0 | ||
| // because users may have already created data source tables in metastore. | ||
| tbl.setProperty("spark.sql.sources.schema", schemaJsonString) | ||
|
||
| } | ||
| } | ||
| options.foreach { case (key, value) => tbl.setSerdeParam(key, value) } | ||
|
|
||
|
|
||
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.
we can easily consolidate this path and remove the convoluted Option.orElse followed by pattern matching.