@@ -25,22 +25,22 @@ import org.apache.spark.sql.catalyst.InternalRow
2525import org .apache .spark .sql .catalyst .analysis .MultiInstanceRelation
2626import org .apache .spark .sql .catalyst .expressions ._
2727import org .apache .spark .sql .catalyst .plans .logical
28- import org .apache .spark .sql .catalyst .plans .logical .{ LogicalPlan , Statistics }
28+ import org .apache .spark .sql .catalyst .plans .logical .Statistics
2929import org .apache .spark .sql .execution .SparkPlan
30- import org .apache .spark .sql .execution .datasources .LogicalRelation
3130import org .apache .spark .storage .StorageLevel
3231import org .apache .spark .util .LongAccumulator
3332
3433
3534object InMemoryRelation {
36-
3735 def apply (
3836 useCompression : Boolean ,
3937 batchSize : Int ,
4038 storageLevel : StorageLevel ,
4139 child : SparkPlan ,
42- tableName : Option [String ]): InMemoryRelation =
43- new InMemoryRelation (child.output, useCompression, batchSize, storageLevel, child, tableName)()
40+ tableName : Option [String ],
41+ stats : Option [Statistics ]): InMemoryRelation =
42+ new InMemoryRelation (child.output, useCompression, batchSize, storageLevel, child, tableName)(
43+ statsOfPlanToCache = stats)
4444}
4545
4646
@@ -62,7 +62,8 @@ case class InMemoryRelation(
6262 @ transient child : SparkPlan ,
6363 tableName : Option [String ])(
6464 @ transient var _cachedColumnBuffers : RDD [CachedBatch ] = null ,
65- val batchStats : LongAccumulator = child.sqlContext.sparkContext.longAccumulator)
65+ val batchStats : LongAccumulator = child.sqlContext.sparkContext.longAccumulator,
66+ statsOfPlanToCache : Option [Statistics ] = None )
6667 extends logical.LeafNode with MultiInstanceRelation {
6768
6869 override protected def innerChildren : Seq [SparkPlan ] = Seq (child)
@@ -73,20 +74,13 @@ case class InMemoryRelation(
7374
7475 override def computeStats (): Statistics = {
7576 if (batchStats.value == 0L ) {
76- inheritedStats.getOrElse(Statistics (sizeInBytes = child.sqlContext.conf.defaultSizeInBytes))
77+ statsOfPlanToCache.getOrElse(Statistics (sizeInBytes =
78+ child.sqlContext.conf.defaultSizeInBytes))
7779 } else {
7880 Statistics (sizeInBytes = batchStats.value.longValue)
7981 }
8082 }
8183
82- private var inheritedStats : Option [Statistics ] = None
83-
84- private [execution] def setStatsFromCachedPlan (planToCache : LogicalPlan ): Unit = {
85- require(planToCache.conf.cboEnabled, " you cannot use the stats of cached plan in" +
86- " InMemoryRelation without cbo enabled" )
87- inheritedStats = Some (planToCache.stats)
88- }
89-
9084 // If the cached column buffers were not passed in, we calculate them in the constructor.
9185 // As in Spark, the actual work of caching is lazy.
9286 if (_cachedColumnBuffers == null ) {
0 commit comments