Github user mbasmanova commented on a diff in the pull request:

    https://github.com/apache/spark/pull/18421#discussion_r125763666
  
    --- Diff: 
sql/hive/src/test/scala/org/apache/spark/sql/hive/StatisticsSuite.scala ---
    @@ -201,6 +202,193 @@ class StatisticsSuite extends 
StatisticsCollectionTestBase with TestHiveSingleto
         }
       }
     
    +  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
    +    }
    +
    +    withTable(tableName) {
    +      sql(s"CREATE TABLE $tableName (key STRING, value STRING) PARTITIONED 
BY (ds STRING)")
    +
    +      sql(s"INSERT INTO TABLE $tableName PARTITION (ds='2010-01-01') 
SELECT * FROM src")
    +      sql(
    +        s"""
    +           |INSERT INTO TABLE $tableName PARTITION (ds='2010-01-02')
    +           |SELECT * FROM src
    +           |UNION ALL
    +           |SELECT * FROM src
    +         """.stripMargin)
    +      sql(s"INSERT INTO TABLE $tableName PARTITION (ds='2010-01-03') 
SELECT * FROM src")
    +
    +      sql(s"ANALYZE TABLE $tableName PARTITION (ds='2010-01-01') COMPUTE 
STATISTICS").collect()
    +
    +      sql(s"ANALYZE TABLE $tableName PARTITION (ds='2010-01-02') COMPUTE 
STATISTICS").collect()
    +
    +      assert(queryStats("2010-01-01").rowCount.get === 500)
    +      assert(queryStats("2010-01-01").sizeInBytes === 5812)
    +
    +      assert(queryStats("2010-01-02").rowCount.get === 2*500)
    +      assert(queryStats("2010-01-02").sizeInBytes === 2*5812)
    +    }
    +  }
    +
    +  test("analyze single partition noscan") {
    +    val tableName = "analyzeTable_part"
    +
    +    def queryStats(ds: String): CatalogStatistics = {
    +      val partition =
    +        
spark.sessionState.catalog.getPartition(TableIdentifier(tableName), Map("ds" -> 
ds))
    +      partition.stats.get
    +    }
    +
    +    withTable(tableName) {
    +      sql(s"CREATE TABLE $tableName (key STRING, value STRING) PARTITIONED 
BY (ds STRING)")
    +
    +      sql(s"INSERT INTO TABLE $tableName PARTITION (ds='2010-01-01') 
SELECT * FROM src")
    +      sql(
    +        s"""
    +           |INSERT INTO TABLE $tableName PARTITION (ds='2010-01-02')
    +           |SELECT * FROM src
    +           |UNION ALL
    +           |SELECT * FROM src
    +         """.stripMargin)
    +      sql(s"INSERT INTO TABLE $tableName PARTITION (ds='2010-01-03') 
SELECT * FROM src")
    +
    +      sql(s"ANALYZE TABLE $tableName PARTITION (ds='2010-01-01') COMPUTE 
STATISTICS NOSCAN")
    +        .collect()
    +
    +      sql(s"ANALYZE TABLE $tableName PARTITION (ds='2010-01-02') COMPUTE 
STATISTICS NOSCAN")
    +        .collect()
    +
    +      assert(queryStats("2010-01-01").rowCount === None)
    +      assert(queryStats("2010-01-01").sizeInBytes === 5812)
    +
    +      assert(queryStats("2010-01-02").rowCount === None)
    +      assert(queryStats("2010-01-02").sizeInBytes === 2*5812)
    +    }
    +  }
    +
    +  test("analyze a set of partitions") {
    +    val tableName = "analyzeTable_part"
    +
    +    def queryStats(ds: String, hr: String): Option[CatalogStatistics] = {
    +      val tableId = TableIdentifier(tableName)
    +      val partition =
    +        spark.sessionState.catalog.getPartition(tableId, Map("ds" -> ds, 
"hr" -> hr))
    +      partition.stats
    +    }
    +
    +    def assertStats(ds: String, hr: String, rowCount: BigInt, sizeInBytes: 
BigInt): Unit = {
    +      val stats = queryStats(ds, hr).get
    +      assert(stats.rowCount === Some(rowCount))
    +      assert(stats.sizeInBytes === sizeInBytes)
    +    }
    +
    +    def assertNoStats(ds: String, hr: String): Unit = {
    +      assert(queryStats(ds, hr) === None)
    +    }
    +
    +    def createPartition(ds: String, hr: Int, query: String): Unit = {
    --- End diff --
    
    I created this method to make the test code more concise. For example, this 
method helps avoid multi-line methods calls like this:
    
    sql(
            s"""
               |INSERT INTO TABLE $tableName PARTITION (ds='2010-01-02', hr=11)
               |SELECT * FROM src
               |UNION ALL
               |SELECT * FROM src
             """.stripMargin)
    
    becomes 
    
    createPartition("2010-01-02", 11, "SELECT * FROM SRC UNION ALL SELECT * 
FROM SRC")


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

Reply via email to