-
Notifications
You must be signed in to change notification settings - Fork 29k
[SPARK-15365] [SQL]: When table size statistics are not available from metastore, we should fallback to HDFS #13150
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
4 commits
Select commit
Hold shift + click to select a range
1f6086f
[SPARK-15365] [SQL]: When table size statistics are not available fro…
Parth-Brahmbhatt 9729d72
Addressing review comments.
Parth-Brahmbhatt f5d5dde
Adding a config to control if we should fall back to HDFS in absence …
Parth-Brahmbhatt ff69f91
Addressing more review comments, adding a test case.
Parth-Brahmbhatt 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 |
|---|---|---|
|
|
@@ -17,9 +17,12 @@ | |
|
|
||
| package org.apache.spark.sql.hive | ||
|
|
||
| import java.io.IOException | ||
|
|
||
| import scala.collection.JavaConverters._ | ||
|
|
||
| import com.google.common.base.Objects | ||
| import org.apache.hadoop.fs.FileSystem | ||
| import org.apache.hadoop.hive.common.StatsSetupConst | ||
| import org.apache.hadoop.hive.metastore.{TableType => HiveTableType} | ||
| import org.apache.hadoop.hive.metastore.api.FieldSchema | ||
|
|
@@ -114,17 +117,31 @@ private[hive] case class MetastoreRelation( | |
| val rawDataSize = hiveQlTable.getParameters.get(StatsSetupConst.RAW_DATA_SIZE) | ||
| // TODO: check if this estimate is valid for tables after partition pruning. | ||
| // NOTE: getting `totalSize` directly from params is kind of hacky, but this should be | ||
| // relatively cheap if parameters for the table are populated into the metastore. An | ||
| // alternative would be going through Hadoop's FileSystem API, which can be expensive if a lot | ||
| // of RPCs are involved. Besides `totalSize`, there are also `numFiles`, `numRows`, | ||
| // `rawDataSize` keys (see StatsSetupConst in Hive) that we can look at in the future. | ||
| // relatively cheap if parameters for the table are populated into the metastore. | ||
| // Besides `totalSize`, there are also `numFiles`, `numRows`, `rawDataSize` keys | ||
| // (see StatsSetupConst in Hive) that we can look at in the future. | ||
| BigInt( | ||
| // When table is external,`totalSize` is always zero, which will influence join strategy | ||
| // so when `totalSize` is zero, use `rawDataSize` instead | ||
| // if the size is still less than zero, we use default size | ||
| Option(totalSize).map(_.toLong).filter(_ > 0) | ||
| .getOrElse(Option(rawDataSize).map(_.toLong).filter(_ > 0) | ||
| .getOrElse(sparkSession.sessionState.conf.defaultSizeInBytes))) | ||
| // if the size is still less than zero, we try to get the file size from HDFS. | ||
| // given this is only needed for optimization, if the HDFS call fails we return the default. | ||
| if (Option(totalSize).map(_.toLong).getOrElse(0L) > 0) { | ||
|
||
| totalSize.toLong | ||
| } else if (Option(rawDataSize).map(_.toLong).getOrElse(0L) > 0) { | ||
| rawDataSize.toLong | ||
| } else if (sparkSession.sessionState.conf.fallBackToHdfsForStatsEnabled) { | ||
| try { | ||
| val hadoopConf = sparkSession.sessionState.newHadoopConf() | ||
| val fs: FileSystem = hiveQlTable.getPath.getFileSystem(hadoopConf) | ||
| fs.getContentSummary(hiveQlTable.getPath).getLength | ||
| } catch { | ||
| case e: IOException => | ||
| logWarning("Failed to get table size from hdfs.", e) | ||
| sparkSession.sessionState.conf.defaultSizeInBytes | ||
| } | ||
| } else { | ||
| sparkSession.sessionState.conf.defaultSizeInBytes | ||
| }) | ||
| } | ||
| ) | ||
|
|
||
|
|
||
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.
nit: missing period after hdfs