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

    https://github.com/apache/spark/pull/18309#discussion_r123890894
  
    --- Diff: 
sql/hive/src/test/scala/org/apache/spark/sql/hive/StatisticsSuite.scala ---
    @@ -128,6 +129,77 @@ class StatisticsSuite extends 
StatisticsCollectionTestBase with TestHiveSingleto
           TableIdentifier("tempTable"), ignoreIfNotExists = true, purge = 
false)
       }
     
    +  test("SPARK-21079 - analyze table with location different than that of 
individual partitions") {
    +    def queryTotalSize(tableName: String): BigInt =
    +      
spark.table(tableName).queryExecution.analyzed.stats(conf).sizeInBytes
    +
    +    val tableName = "analyzeTable_part"
    +    withTable(tableName) {
    +      withTempPath { path =>
    +        sql(s"CREATE TABLE $tableName (key STRING, value STRING) 
PARTITIONED BY (ds STRING)")
    +
    +        val partitionDates = List("2010-01-01", "2010-01-02", "2010-01-03")
    +        partitionDates.foreach { ds =>
    +          sql(s"INSERT INTO TABLE $tableName PARTITION (ds='$ds') SELECT * 
FROM src")
    +        }
    +
    +        sql(s"ALTER TABLE $tableName SET LOCATION '$path'")
    +
    +        sql(s"ANALYZE TABLE $tableName COMPUTE STATISTICS noscan")
    +
    +        assert(queryTotalSize(tableName) === BigInt(17436))
    +      }
    +    }
    +  }
    +
    +  test("SPARK-21079 - analyze partitioned table with only a subset of 
partitions visible") {
    +    def queryTotalSize(tableName: String): BigInt =
    +      
spark.table(tableName).queryExecution.analyzed.stats(conf).sizeInBytes
    +
    +    val sourceTableName = "analyzeTable_part"
    +    val tableName = "analyzeTable_part_vis"
    +    withTable(sourceTableName, tableName) {
    +      withTempPath { path =>
    +          // Create a table with 3 partitions all located under a single 
top-level directory 'path'
    +          sql(
    +            s"""
    +               |CREATE TABLE $sourceTableName (key STRING, value STRING)
    +               |PARTITIONED BY (ds STRING)
    +               |LOCATION '$path'
    +             """.stripMargin)
    +
    +          val partitionDates = List("2010-01-01", "2010-01-02", 
"2010-01-03")
    +          partitionDates.foreach { ds =>
    +              sql(
    +                s"""
    +                   |INSERT INTO TABLE $sourceTableName PARTITION (ds='$ds')
    +                   |SELECT * FROM src
    +                 """.stripMargin)
    +          }
    +
    +          // Create another table referring to the same location
    +          sql(
    +            s"""
    +               |CREATE TABLE $tableName (key STRING, value STRING)
    +               |PARTITIONED BY (ds STRING)
    +               |LOCATION '$path'
    +             """.stripMargin)
    +
    +          // Register only one of the partitions found on disk
    +          val ds = partitionDates.head
    +          sql(s"ALTER TABLE $tableName ADD PARTITION (ds='$ds')").collect()
    +
    +          // Analyze original table - expect 3 partitions
    +          sql(s"ANALYZE TABLE $sourceTableName COMPUTE STATISTICS noscan")
    +          assert(queryTotalSize(sourceTableName) === BigInt(3 * 5812))
    +
    +          // Analyze partial-copy table - expect only 1 partition
    +          sql(s"ANALYZE TABLE $tableName COMPUTE STATISTICS noscan")
    +          assert(queryTotalSize(tableName) === BigInt(5812))
    --- End diff --
    
    I am afraid this hard-coded values might not succeed in some other 
platforms. We might need to adjust the way. However, let me first merge this. 
If needed, we might need to submit a follow-up PR. cc @cloud-fan @wzhfy 


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