Github user vanzin commented on a diff in the pull request:
https://github.com/apache/spark/pull/15189#discussion_r80530739
--- Diff:
sql/core/src/test/scala/org/apache/spark/sql/execution/columnar/InMemoryColumnarQuerySuite.scala
---
@@ -232,4 +232,29 @@ class InMemoryColumnarQuerySuite extends QueryTest
with SharedSQLContext {
val columnTypes2 = List.fill(length2)(IntegerType)
val columnarIterator2 = GenerateColumnAccessor.generate(columnTypes2)
}
+
+ test("SPARK-17549: cached table size should be correctly calculated") {
+ val data = spark.sparkContext.parallelize(1 to 10, 5).map { i => (i,
i.toLong) }
+ .toDF("col1", "col2")
+ val plan = spark.sessionState.executePlan(data.logicalPlan).sparkPlan
+ val cached = InMemoryRelation(true, 5, MEMORY_ONLY, plan, None)
+
+ // Materialize the data.
+ val expectedAnswer = data.collect()
+ checkAnswer(cached, expectedAnswer)
+
+ // Check that the right size was calculated.
+ val expectedColSizes = expectedAnswer.size * (INT.defaultSize +
LONG.defaultSize)
+ assert(cached.statistics.sizeInBytes === expectedColSizes)
+
+ // Create a projection of the cached data and make sure the statistics
are correct.
+ val projected = cached.withOutput(Seq(plan.output.last))
+ assert(projected.statistics.sizeInBytes === expectedAnswer.size *
LONG.defaultSize)
--- End diff --
Ok, I looked again at a heap dump with a couple of cached relations and
you're right; I had misinterpreted the previous data. I'll remove these tests
and simplify the code.
Still I'd be a little more comfortable if there was an assert in
`InMemoryRelation.withOutput` that the new output at least is of the same size
as the previous one...
---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at [email protected] or file a JIRA ticket
with INFRA.
---
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]