Github user cloud-fan commented on a diff in the pull request:
https://github.com/apache/spark/pull/18205#discussion_r121595388
--- Diff:
sql/hive/src/test/scala/org/apache/spark/sql/hive/execution/PruneFileSourcePartitionsSuite.scala
---
@@ -66,4 +68,45 @@ class PruneFileSourcePartitionsSuite extends QueryTest
with SQLTestUtils with Te
}
}
}
+
+ test("SPARK-20986 Reset table's statistics after
PruneFileSourcePartitions rule") {
+ withTempView("tempTbl") {
+ withTable("partTbl") {
+ spark.range(10).selectExpr("id").createOrReplaceTempView("tempTbl")
+ sql("CREATE TABLE partTbl (id INT) PARTITIONED BY (part INT)
STORED AS parquet")
+ for (part <- Seq(1, 2)) {
+ sql(
+ s"""
+ |INSERT OVERWRITE TABLE partTbl PARTITION (part='$part')
+ |select id from tempTbl
+ """.stripMargin)
+ }
+
+ val tableName = "partTbl"
+ sql(s"ANALYZE TABLE partTbl COMPUTE STATISTICS")
+ val tableStats =
+
spark.sessionState.catalog.getTableMetadata(TableIdentifier(tableName)).stats
+ assert(tableStats.isDefined && tableStats.get.sizeInBytes > 0,
"tableStats is lost")
+
+ withSQLConf(SQLConf.ENABLE_FALL_BACK_TO_HDFS_FOR_STATS.key ->
"true") {
+ val df = sql("SELECT * FROM partTbl where part = 1")
+ val query = df.queryExecution.analyzed.analyze
+ val sizes1 = query.collect {
+ case relation: LogicalRelation =>
relation.catalogTable.get.stats.get.sizeInBytes
+ }
+ assert(sizes1.size === 1, s"Size wrong for:\n
${df.queryExecution}")
+ assert(sizes1(0) == tableStats.get.sizeInBytes)
+ val relations = Optimize.execute(query).collect {
+ case relation: LogicalRelation => relation
+ }
+ assert(relations.size === 1, s"Size wrong for:\n
${df.queryExecution}")
+ val size2 = relations(0).computeStats(conf).sizeInBytes
+ val size3 = relations(0).catalogTable.get.stats.get.sizeInBytes
--- End diff --
nit:
```
assert(size2 == relations(0).catalogTable.get.stats.get.sizeInBytes)
assert(size2 < tableStats.get.sizeInBytes)
```
---
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]