Github user mbasmanova commented on a diff in the pull request: https://github.com/apache/spark/pull/18421#discussion_r126724336 --- Diff: sql/hive/src/test/scala/org/apache/spark/sql/hive/StatisticsSuite.scala --- @@ -181,6 +182,151 @@ class StatisticsSuite extends StatisticsCollectionTestBase with TestHiveSingleto } } + private val SELECT_FROM_SRC = "SELECT '1', 'A' from src" + + test("analyze single partition") { + val tableName = "analyzeTable_part" + + def queryStats(ds: String): CatalogStatistics = { + val partition = + spark.sessionState.catalog.getPartition(TableIdentifier(tableName), Map("ds" -> ds)) + partition.stats.get + } + + def createPartition(ds: String, query: String): Unit = { + sql(s"INSERT INTO TABLE $tableName PARTITION (ds='$ds') $query") + } + + withTable(tableName) { + sql(s"CREATE TABLE $tableName (key STRING, value STRING) PARTITIONED BY (ds STRING)") + + createPartition("2010-01-01", SELECT_FROM_SRC) + createPartition("2010-01-02", s"$SELECT_FROM_SRC UNION ALL $SELECT_FROM_SRC") + createPartition("2010-01-03", SELECT_FROM_SRC) --- End diff -- @wzhfy, I'm using multiple partitions to protect against bugs like the following: - ANALYZE PARTITION collects stats for the whole table instead of a single partition (hence, test table needs to have 2+ partitions) - ANALYZE PARTITION collects stats for the *first* partition instead of the partition specified in the SQL command (hence, need to analyze a couple of different partitions) Using "analyze single partition" for the test name I was hoping to communicate the intent of testing analyzing of a single partition as opposed to a set of partitions. Does this make sense? Do you still want me to reduce the test to a single-partition table?
--- 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 infrastruct...@apache.org or file a JIRA ticket with INFRA. --- --------------------------------------------------------------------- To unsubscribe, e-mail: reviews-unsubscr...@spark.apache.org For additional commands, e-mail: reviews-h...@spark.apache.org