-
Notifications
You must be signed in to change notification settings - Fork 29k
[SPARK-30427][SQL] Add config item for limiting partition number when calculating statistics through File System #27129
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
10 commits
Select commit
Hold shift + click to select a range
96469c8
rebase code.
fuwhu 2287631
Fix compile error.
fuwhu 2c2da94
update default value of MAX_PARTITION_NUMBER_FOR_STATS_CALCULATION_VI…
fuwhu 6f31548
Refine code.
fuwhu bccdc3e
refine code
fuwhu d62171d
Check whether the partition number to calculate sizeInBytes is less t…
fuwhu faffdf8
fix scala code style.
fuwhu a06288c
refine tests.
fuwhu 3c27224
roll back the check on partition number when calculating statistics i…
fuwhu 8b14ce4
fix test failure
fuwhu 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 |
|---|---|---|
|
|
@@ -26,6 +26,7 @@ import org.apache.spark.sql.catalyst.expressions.{And, AttributeSet, Expression, | |
| import org.apache.spark.sql.catalyst.planning.PhysicalOperation | ||
| import org.apache.spark.sql.catalyst.plans.logical.{Filter, LogicalPlan, Project} | ||
| import org.apache.spark.sql.catalyst.rules.Rule | ||
| import org.apache.spark.sql.execution.command.CommandUtils | ||
| import org.apache.spark.sql.execution.datasources.DataSourceStrategy | ||
| import org.apache.spark.sql.internal.SQLConf | ||
|
|
||
|
|
@@ -73,19 +74,30 @@ private[sql] class PruneHiveTablePartitions(session: SparkSession) | |
| private def updateTableMeta( | ||
| tableMeta: CatalogTable, | ||
| prunedPartitions: Seq[CatalogTablePartition]): CatalogTable = { | ||
| val sizeOfPartitions = prunedPartitions.map { partition => | ||
| val partitionsWithSize = prunedPartitions.map { partition => | ||
| val rawDataSize = partition.parameters.get(StatsSetupConst.RAW_DATA_SIZE).map(_.toLong) | ||
| val totalSize = partition.parameters.get(StatsSetupConst.TOTAL_SIZE).map(_.toLong) | ||
| if (rawDataSize.isDefined && rawDataSize.get > 0) { | ||
| rawDataSize.get | ||
| (partition, rawDataSize.get) | ||
| } else if (totalSize.isDefined && totalSize.get > 0L) { | ||
| totalSize.get | ||
| (partition, totalSize.get) | ||
| } else { | ||
| 0L | ||
| (partition, 0L) | ||
| } | ||
| } | ||
| if (sizeOfPartitions.forall(_ > 0)) { | ||
| val sizeInBytes = sizeOfPartitions.sum | ||
| if (partitionsWithSize.forall(_._2 > 0)) { | ||
| val sizeInBytes = partitionsWithSize.map(_._2).sum | ||
| tableMeta.copy(stats = Some(CatalogStatistics(sizeInBytes = BigInt(sizeInBytes)))) | ||
| } else if (partitionsWithSize.count(_._2 == 0) <= conf.maxPartNumForStatsCalculateViaFS) { | ||
|
Member
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. @fuwhu, are you're proposing a configuration to automatically calculate the size? why don't you just manually run analyze comment to calculate the stats? It's weird to do this based on the number of partitions. |
||
| val sizeInBytes = | ||
| partitionsWithSize.map(pair => { | ||
| if (pair._2 == 0) { | ||
| CommandUtils.calculateLocationSize( | ||
| session.sessionState, tableMeta.identifier, pair._1.storage.locationUri) | ||
| } else { | ||
| pair._2 | ||
| } | ||
| }).sum | ||
| tableMeta.copy(stats = Some(CatalogStatistics(sizeInBytes = BigInt(sizeInBytes)))) | ||
| } else { | ||
| tableMeta | ||
|
|
||
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
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.
why do we need to do calculation here? I think it introduces extra cost.
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.
you mean just leave the tableMeta unchanged (which is table level meta without partition pruning) if there is at least one partition whose size is not available in meta store ?
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
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.
some discussion about this was in #26805 (comment)