-
Notifications
You must be signed in to change notification settings - Fork 29.3k
[SPARK-33075][SQL] Enable auto bucketed scan by default (disable only for cached query) #30138
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 5 commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
7315be8
Enable auto bucketed table scan by default (disable only for cached q…
c21 610b598
Address all comments
c21 da54eaa
avoid unnecessary line break
c21 09c6ca9
Fix style
c21 8c1d11e
Address comment to make the method not public
c21 9e6aaf4
Remove duplicated comments
c21 070da00
Remove comment for version
c21 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 |
|---|---|---|
|
|
@@ -22,6 +22,7 @@ import scala.collection.immutable.IndexedSeq | |
| import org.apache.hadoop.fs.{FileSystem, Path} | ||
|
|
||
| import org.apache.spark.internal.Logging | ||
| import org.apache.spark.internal.config.ConfigEntry | ||
| import org.apache.spark.sql.{Dataset, SparkSession} | ||
| import org.apache.spark.sql.catalyst.expressions.{Attribute, SubqueryExpression} | ||
| import org.apache.spark.sql.catalyst.optimizer.EliminateResolvedHint | ||
|
|
@@ -31,6 +32,7 @@ import org.apache.spark.sql.execution.columnar.{DefaultCachedBatchSerializer, In | |
| import org.apache.spark.sql.execution.command.CommandUtils | ||
| import org.apache.spark.sql.execution.datasources.{FileIndex, HadoopFsRelation, LogicalRelation} | ||
| import org.apache.spark.sql.execution.datasources.v2.{DataSourceV2Relation, FileTable} | ||
| import org.apache.spark.sql.internal.SQLConf | ||
| import org.apache.spark.storage.StorageLevel | ||
| import org.apache.spark.storage.StorageLevel.MEMORY_AND_DISK | ||
|
|
||
|
|
@@ -55,6 +57,17 @@ class CacheManager extends Logging with AdaptiveSparkPlanHelper { | |
| @transient @volatile | ||
| private var cachedData = IndexedSeq[CachedData]() | ||
|
|
||
| /** | ||
| * Configurations needs to be turned off, to avoid regression for cached query, so that the | ||
| * outputPartitioning of the underlying cached query plan can be leveraged later. | ||
| * Configurations include: | ||
| * 1. AQE | ||
| * 2. Automatic bucketed table scan | ||
| */ | ||
| private val forceDisableConfigs: Seq[ConfigEntry[Boolean]] = Seq( | ||
| SQLConf.ADAPTIVE_EXECUTION_ENABLED, | ||
| SQLConf.AUTO_BUCKETED_SCAN_ENABLED) | ||
|
|
||
| /** Clears all cached tables. */ | ||
| def clearCache(): Unit = this.synchronized { | ||
| cachedData.foreach(_.cachedRepresentation.cacheBuilder.clearCache()) | ||
|
|
@@ -79,10 +92,11 @@ class CacheManager extends Logging with AdaptiveSparkPlanHelper { | |
| if (lookupCachedData(planToCache).nonEmpty) { | ||
| logWarning("Asked to cache already cached data.") | ||
| } else { | ||
| // Turn off AQE so that the outputPartitioning of the underlying plan can be leveraged. | ||
| val sessionWithAqeOff = getOrCloneSessionWithAqeOff(query.sparkSession) | ||
| val inMemoryRelation = sessionWithAqeOff.withActive { | ||
| val qe = sessionWithAqeOff.sessionState.executePlan(planToCache) | ||
| // Turn off configs so that the outputPartitioning of the underlying plan can be leveraged. | ||
|
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. nit: this comment seems duplicated with above.
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. @viirya - removed. |
||
| val sessionWithConfigsOff = SparkSession.getOrCloneSessionWithConfigsOff( | ||
| query.sparkSession, forceDisableConfigs) | ||
| val inMemoryRelation = sessionWithConfigsOff.withActive { | ||
| val qe = sessionWithConfigsOff.sessionState.executePlan(planToCache) | ||
| InMemoryRelation( | ||
| storageLevel, | ||
| qe, | ||
|
|
@@ -188,10 +202,11 @@ class CacheManager extends Logging with AdaptiveSparkPlanHelper { | |
| } | ||
| needToRecache.map { cd => | ||
| cd.cachedRepresentation.cacheBuilder.clearCache() | ||
| // Turn off AQE so that the outputPartitioning of the underlying plan can be leveraged. | ||
| val sessionWithAqeOff = getOrCloneSessionWithAqeOff(spark) | ||
| val newCache = sessionWithAqeOff.withActive { | ||
| val qe = sessionWithAqeOff.sessionState.executePlan(cd.plan) | ||
| // Turn off configs so that the outputPartitioning of the underlying plan can be leveraged. | ||
| val sessionWithConfigsOff = SparkSession.getOrCloneSessionWithConfigsOff( | ||
| spark, forceDisableConfigs) | ||
| val newCache = sessionWithConfigsOff.withActive { | ||
| val qe = sessionWithConfigsOff.sessionState.executePlan(cd.plan) | ||
| InMemoryRelation(cd.cachedRepresentation.cacheBuilder, qe) | ||
| } | ||
| val recomputedPlan = cd.copy(cachedRepresentation = newCache) | ||
|
|
||
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
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.
this is not needed for internal APIs.
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.
@cloud-fan - removed.