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

    https://github.com/apache/spark/pull/14971#discussion_r78305513
  
    --- Diff: 
sql/hive/src/test/scala/org/apache/spark/sql/hive/StatisticsSuite.scala ---
    @@ -259,6 +259,156 @@ class StatisticsSuite extends QueryTest with 
TestHiveSingleton with SQLTestUtils
         }
       }
     
    +  private def createNonPartitionedTable(tabName: String): 
Option[Statistics] = {
    +    val hiveClient = 
spark.sharedState.externalCatalog.asInstanceOf[HiveExternalCatalog].client
    +    sql(
    +      s"""
    +         |CREATE TABLE $tabName (key STRING, value STRING)
    +         |STORED AS TEXTFILE
    +         |TBLPROPERTIES ('prop1' = 'val1', 'prop2' = 'val2')
    +       """.stripMargin)
    +    sql(s"INSERT INTO TABLE $tabName SELECT * FROM src")
    +    sql(s"ANALYZE TABLE $tabName COMPUTE STATISTICS")
    +    hiveClient.runSqlHive(s"ANALYZE TABLE $tabName COMPUTE STATISTICS")
    +    val describeResult1 = hiveClient.runSqlHive(s"DESCRIBE FORMATTED 
$tabName")
    +
    +    val tableMetadata =
    +      
spark.sessionState.catalog.getTableMetadata(TableIdentifier(tabName)).properties
    +    // statistics info is not contained in the metadata of the original 
table
    +    assert(Seq(StatsSetupConst.COLUMN_STATS_ACCURATE,
    +      StatsSetupConst.NUM_FILES,
    +      StatsSetupConst.NUM_PARTITIONS,
    +      StatsSetupConst.ROW_COUNT,
    +      StatsSetupConst.RAW_DATA_SIZE,
    +      StatsSetupConst.TOTAL_SIZE).forall(!tableMetadata.contains(_)))
    +
    +    assert(StringUtils.filterPattern(describeResult1, 
"*numRows\\s+500*").nonEmpty)
    +    checkStats(
    +      tabName, isDataSourceTable = false, hasSizeInBytes = true, 
expectedRowCounts = Some(500))
    +  }
    +
    +  test("alter table rename after analyze table") {
    +    val oldName = "tab1"
    +    val newName = "tab2"
    +    withTable(oldName, newName) {
    +      val fetchedStats1 = createNonPartitionedTable(oldName)
    +      sql(s"ALTER TABLE $oldName RENAME TO $newName")
    +      val fetchedStats2 = checkStats(
    +        newName, isDataSourceTable = false, hasSizeInBytes = true, 
expectedRowCounts = Some(500))
    +      assert(fetchedStats1 == fetchedStats2)
    +
    +      // ALTER TABLE RENAME does not affect the contents of Hive specific 
statistics
    +      val hiveClient = 
spark.sharedState.externalCatalog.asInstanceOf[HiveExternalCatalog].client
    +      val describeResult = hiveClient.runSqlHive(s"DESCRIBE FORMATTED 
$newName")
    +      assert(StringUtils.filterPattern(describeResult, 
"*numRows\\s+500*").nonEmpty)
    +    }
    +  }
    +
    +  test("alter table SET TBLPROPERTIES after analyze table") {
    +    val tabName = "tab1"
    +    withTable(tabName) {
    +      val fetchedStats1 = createNonPartitionedTable(tabName)
    +
    +      sql(s"ALTER TABLE $tabName SET TBLPROPERTIES ('foo' = 'a')")
    +      val fetchedStats2 = checkStats(
    +        tabName, isDataSourceTable = false, hasSizeInBytes = true, 
expectedRowCounts = Some(500))
    +      assert(fetchedStats1 == fetchedStats2)
    +
    +      // ALTER TABLE SET TBLPROPERTIES invalidates some contents of Hive 
specific statistics
    +      // This is triggered by the Hive alterTable API
    +      val hiveClient = 
spark.sharedState.externalCatalog.asInstanceOf[HiveExternalCatalog].client
    +      val describeResult = hiveClient.runSqlHive(s"DESCRIBE FORMATTED 
$tabName")
    +      assert(StringUtils.filterPattern(describeResult, 
"*numRows\\s+-1*").nonEmpty)
    +    }
    +  }
    +
    +  test("alter table UNSET TBLPROPERTIES after analyze table") {
    +    val tabName = "tab1"
    +    withTable(tabName) {
    +      val fetchedStats1 = createNonPartitionedTable(tabName)
    +
    +      sql(s"ALTER TABLE $tabName UNSET TBLPROPERTIES ('prop1')")
    +      val fetchedStats2 = checkStats(
    +        tabName, isDataSourceTable = false, hasSizeInBytes = true, 
expectedRowCounts = Some(500))
    +      assert(fetchedStats1 == fetchedStats2)
    +
    +      // ALTER TABLE UNSET TBLPROPERTIES invalidates some contents of Hive 
specific statistics
    +      // This is triggered by the Hive alterTable API
    +      val hiveClient = 
spark.sharedState.externalCatalog.asInstanceOf[HiveExternalCatalog].client
    +      val describeResult = hiveClient.runSqlHive(s"DESCRIBE FORMATTED 
$tabName")
    +      assert(StringUtils.filterPattern(describeResult, 
"*numRows\\s+-1*").nonEmpty)
    +    }
    +  }
    +
    +  test("add/drop partitions - managed table") {
    --- End diff --
    
    FYI, when we drop partitions of EXTERNAL tables, `ANALYZE TABLE` is unable 
to exclude them from statistics. This should be fixed with 
https://issues.apache.org/jira/browse/SPARK-17129, if my understanding is right.


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