aboutsummaryrefslogtreecommitdiff
path: root/sql/catalyst/src/main
diff options
context:
space:
mode:
authorReynold Xin <rxin@databricks.com>2017-01-11 14:25:36 -0800
committerReynold Xin <rxin@databricks.com>2017-01-11 14:25:36 -0800
commit66fe819ada6435f3a351c2d257e73b8e6f6085cd (patch)
treeed7c76082694c3fd742cc1f6b1d0fd54ffe0a611 /sql/catalyst/src/main
parent30a07071f099c0ebcf04c4df61f8d414dcbad7b5 (diff)
downloadspark-66fe819ada6435f3a351c2d257e73b8e6f6085cd.tar.gz
spark-66fe819ada6435f3a351c2d257e73b8e6f6085cd.tar.bz2
spark-66fe819ada6435f3a351c2d257e73b8e6f6085cd.zip
[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.
Diffstat (limited to 'sql/catalyst/src/main')
-rw-r--r--sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/plans/logical/LogicalPlan.scala21
1 files changed, 13 insertions, 8 deletions
diff --git a/sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/plans/logical/LogicalPlan.scala b/sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/plans/logical/LogicalPlan.scala
index 9e5ba9ca8f..0587a59214 100644
--- a/sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/plans/logical/LogicalPlan.scala
+++ b/sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/plans/logical/LogicalPlan.scala
@@ -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())
}