Github user CodingCat commented on a diff in the pull request: https://github.com/apache/spark/pull/19864#discussion_r155587468 --- Diff: sql/core/src/test/scala/org/apache/spark/sql/execution/columnar/InMemoryColumnarQuerySuite.scala --- @@ -479,4 +481,32 @@ class InMemoryColumnarQuerySuite extends QueryTest with SharedSQLContext { } } } + + test("SPARK-22673: InMemoryRelation should utilize existing stats whenever possible") { + withSQLConf("spark.sql.cbo.enabled" -> "true") { + // scalastyle:off + val workDir = s"${Utils.createTempDir()}/table1" + val data = Seq(100, 200, 300, 400).toDF("count") + data.write.parquet(workDir) + val dfFromFile = spark.read.parquet(workDir).cache() + val inMemoryRelation = dfFromFile.queryExecution.optimizedPlan.collect { + case plan: InMemoryRelation => plan + }.head + // InMemoryRelation's stats is Long.MaxValue before the underlying RDD is materialized + assert(inMemoryRelation.computeStats().sizeInBytes === Long.MaxValue) + // InMemoryRelation's stats is updated after materializing RDD + dfFromFile.collect() + assert(inMemoryRelation.computeStats().sizeInBytes === 16) + // test of catalog table + val dfFromTable = spark.catalog.createTable("table1", workDir).cache() + val inMemoryRelation2 = dfFromTable.queryExecution.optimizedPlan. + collect { case plan: InMemoryRelation => plan }.head + // Even CBO enabled, InMemoryRelation's stats keeps as the default one before table's stats + // is calculated + assert(inMemoryRelation2.computeStats().sizeInBytes === Long.MaxValue) --- End diff -- done
--- --------------------------------------------------------------------- To unsubscribe, e-mail: reviews-unsubscr...@spark.apache.org For additional commands, e-mail: reviews-h...@spark.apache.org