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

    https://github.com/apache/spark/pull/14971#discussion_r80375572
  
    --- Diff: 
sql/hive/src/test/scala/org/apache/spark/sql/hive/StatisticsSuite.scala ---
    @@ -259,6 +260,230 @@ class StatisticsSuite extends QueryTest with 
TestHiveSingleton with SQLTestUtils
         }
       }
     
    +  private def createNonPartitionedTable(
    +      tabName: String,
    +      analyzedBySpark: Boolean = true,
    +      analyzedByHive: Boolean = true): Unit = {
    +    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")
    +    if (analyzedBySpark) sql(s"ANALYZE TABLE $tabName COMPUTE STATISTICS")
    +    if (analyzedByHive) 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(_)))
    +
    +    if (analyzedByHive) {
    +      assert(StringUtils.filterPattern(describeResult1, 
"*numRows\\s+500*").nonEmpty)
    +    } else {
    +      assert(StringUtils.filterPattern(describeResult1, 
"*numRows\\s+500*").isEmpty)
    +    }
    +  }
    +
    +  private def extractStatsPropValues(
    +      descOutput: Seq[String],
    +      propKey: String): Option[BigInt] = {
    +    val str = descOutput
    +      .filterNot(_.contains(HiveExternalCatalog.STATISTICS_PREFIX))
    +      .filter(_.contains(propKey))
    +    if (str.isEmpty) {
    +      None
    +    } else {
    +      assert(str.length == 1, "found more than one matches")
    +      val pattern = new Regex(s"""$propKey\\s+(-?\\d+)""")
    +      val pattern(value) = str.head.trim
    +      Option(BigInt(value))
    +    }
    +  }
    +
    +  test("get statistics when not analyzed in both Hive and Spark") {
    +    val tabName = "tab1"
    +    val hiveClient = 
spark.sharedState.externalCatalog.asInstanceOf[HiveExternalCatalog].client
    +    hiveClient.runSqlHive("set hive.stats.autogather=false")
    --- End diff --
    
    This is not related to the code. Let me remove it. 
    
    No matter whether this is true or false, totalSize is a positive value. 
Also tried `INSERT OVERWRITE`. Still the same. Maybe a bug in Hive?
    
    Originally, I want to see the impact. It does not behave consistently with 
my installed Hive version. 


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