Skip to content
Snippets Groups Projects
Commit 66fe819a authored by Reynold Xin's avatar Reynold Xin
Browse files

[SPARK-19149][SQL] Follow-up: simplify cache implementation.

## What changes were proposed in this pull request?
This patch simplifies slightly the logical plan statistics cache implementation, as discussed in https://github.com/apache/spark/pull/16529

## How was this patch tested?
N/A - this has no behavior change.

Author: Reynold Xin <rxin@databricks.com>

Closes #16544 from rxin/SPARK-19149.
parent 30a07071
No related branches found
No related tags found
No related merge requests found
......@@ -82,17 +82,22 @@ abstract class LogicalPlan extends QueryPlan[LogicalPlan] with Logging {
}
/** A cache for the estimated statistics, such that it will only be computed once. */
private val statsCache = new ThreadLocal[Option[Statistics]] {
override protected def initialValue: Option[Statistics] = None
}
private var statsCache: Option[Statistics] = None
def stats(conf: CatalystConf): Statistics = statsCache.get.getOrElse {
statsCache.set(Some(computeStats(conf)))
statsCache.get.get
/**
* Returns the estimated statistics for the current logical plan node. Under the hood, this
* method caches the return value, which is computed based on the configuration passed in the
* first time. If the configuration changes, the cache can be invalidated by calling
* [[invalidateStatsCache()]].
*/
final def stats(conf: CatalystConf): Statistics = statsCache.getOrElse {
statsCache = Some(computeStats(conf))
statsCache.get
}
def invalidateStatsCache(): Unit = {
statsCache.set(None)
/** Invalidates the stats cache. See [[stats]] for more information. */
final def invalidateStatsCache(): Unit = {
statsCache = None
children.foreach(_.invalidateStatsCache())
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment