Github user cloud-fan commented on a diff in the pull request:

    https://github.com/apache/spark/pull/15360#discussion_r83365814
  
    --- Diff: 
sql/hive/src/test/scala/org/apache/spark/sql/hive/StatisticsSuite.scala ---
    @@ -358,53 +358,189 @@ class StatisticsSuite extends QueryTest with 
TestHiveSingleton with SQLTestUtils
         }
       }
     
    -  test("generate column-level statistics and load them from hive 
metastore") {
    +  private def getStatsBeforeAfterUpdate(isAnalyzeColumns: Boolean): 
(Statistics, Statistics) = {
    +    val tableName = "tbl"
    +    var statsBeforeUpdate: Statistics = null
    +    var statsAfterUpdate: Statistics = null
    +    withTable(tableName) {
    +      val tableIndent = TableIdentifier(tableName, Some("default"))
    +      val catalog = 
spark.sessionState.catalog.asInstanceOf[HiveSessionCatalog]
    +      sql(s"CREATE TABLE $tableName (key int) USING PARQUET")
    +      sql(s"INSERT INTO $tableName SELECT 1")
    +      if (isAnalyzeColumns) {
    +        sql(s"ANALYZE TABLE $tableName COMPUTE STATISTICS FOR COLUMNS key")
    +      } else {
    +        sql(s"ANALYZE TABLE $tableName COMPUTE STATISTICS")
    +      }
    +      // Table lookup will make the table cached.
    +      catalog.lookupRelation(tableIndent)
    +      statsBeforeUpdate = catalog.getCachedDataSourceTable(tableIndent)
    +        .asInstanceOf[LogicalRelation].catalogTable.get.stats.get
    +
    +      sql(s"INSERT INTO $tableName SELECT 2")
    +      if (isAnalyzeColumns) {
    +        sql(s"ANALYZE TABLE $tableName COMPUTE STATISTICS FOR COLUMNS key")
    +      } else {
    +        sql(s"ANALYZE TABLE $tableName COMPUTE STATISTICS")
    +      }
    +      catalog.lookupRelation(tableIndent)
    +      statsAfterUpdate = catalog.getCachedDataSourceTable(tableIndent)
    +        .asInstanceOf[LogicalRelation].catalogTable.get.stats.get
    +    }
    +    (statsBeforeUpdate, statsAfterUpdate)
    +  }
    +
    +  test("test refreshing table stats of cached data source table by 
`ANALYZE TABLE` statement") {
    +    val (statsBeforeUpdate, statsAfterUpdate) = 
getStatsBeforeAfterUpdate(isAnalyzeColumns = false)
    +
    +    assert(statsBeforeUpdate.sizeInBytes > 0)
    +    assert(statsBeforeUpdate.rowCount.contains(1))
    --- End diff --
    
    nit: we should not use `Option` as a collection, but use it more explicitly 
`statsBeforeUpdate.rowCount == Some(1)` . BTW `Option.contains` is not in scala 
2.10


---
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

Reply via email to