Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[SPARK-22280][SQL][TEST] Improve StatisticsSuite to test convertMetastore properly #19500

Closed
wants to merge 3 commits into from
Closed
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -937,26 +937,22 @@ class StatisticsSuite extends StatisticsCollectionTestBase with TestHiveSingleto
}

test("test statistics of LogicalRelation converted from Hive serde tables") {
val parquetTable = "parquetTable"
val orcTable = "orcTable"
withTable(parquetTable, orcTable) {
sql(s"CREATE TABLE $parquetTable (key STRING, value STRING) STORED AS PARQUET")
sql(s"CREATE TABLE $orcTable (key STRING, value STRING) STORED AS ORC")
sql(s"INSERT INTO TABLE $parquetTable SELECT * FROM src")
sql(s"INSERT INTO TABLE $orcTable SELECT * FROM src")

// the default value for `spark.sql.hive.convertMetastoreParquet` is true, here we just set it
// for robustness
withSQLConf(HiveUtils.CONVERT_METASTORE_PARQUET.key -> "true") {
checkTableStats(parquetTable, hasSizeInBytes = false, expectedRowCounts = None)
sql(s"ANALYZE TABLE $parquetTable COMPUTE STATISTICS")
checkTableStats(parquetTable, hasSizeInBytes = true, expectedRowCounts = Some(500))
}
withSQLConf(HiveUtils.CONVERT_METASTORE_ORC.key -> "true") {
// We still can get tableSize from Hive before Analyze
checkTableStats(orcTable, hasSizeInBytes = true, expectedRowCounts = None)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you explain why orc table has size before analyze command while parquet table does not?

Copy link
Member Author

@dongjoon-hyun dongjoon-hyun Oct 16, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is old test case by SPARK-17410.
The original test case before SPARK-17410 wasn't and my new test case didn't.
It's due to convertMetastoreXXX. Hive INSERT will generate stats.

sql(s"ANALYZE TABLE $orcTable COMPUTE STATISTICS")
checkTableStats(orcTable, hasSizeInBytes = true, expectedRowCounts = Some(500))
Seq("orc", "parquet").foreach { format =>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe "orcTbl" and "parquetTbl" are better?

Copy link
Member Author

@dongjoon-hyun dongjoon-hyun Oct 16, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is used in STORED AS $format, too. This is a minimal. :)

Seq("true", "false").foreach { isConverted =>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We prefer to using Seq(true, false)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for review, @gatorsmile . Sure.

withSQLConf(
HiveUtils.CONVERT_METASTORE_ORC.key -> isConverted,
HiveUtils.CONVERT_METASTORE_PARQUET.key -> isConverted) {
withTable(format) {
sql(s"CREATE TABLE $format (key STRING, value STRING) STORED AS $format")
sql(s"INSERT INTO TABLE $format SELECT * FROM src")

val hasHiveStats = !isConverted.toBoolean
checkTableStats(format, hasSizeInBytes = hasHiveStats, expectedRowCounts = None)

sql(s"ANALYZE TABLE $format COMPUTE STATISTICS")
checkTableStats(format, hasSizeInBytes = true, expectedRowCounts = Some(500))
}
}
}
}
}
Expand Down