You are viewing a plain text version of this content. The canonical link for it is here.
Posted to reviews@spark.apache.org by wzhfy <gi...@git.apache.org> on 2016/08/19 06:29:17 UTC
[GitHub] spark pull request #14712: [SPARK-17072] [SQL] support table-level statistic...
GitHub user wzhfy opened a pull request:
https://github.com/apache/spark/pull/14712
[SPARK-17072] [SQL] support table-level statistics generation and storing into/loading from metastore
## What changes were proposed in this pull request?
1. support generation table-level statistics for "Analyze Table table COMPUTE STATISTICS" command (without "noscan").
2. support storing these statistics into metastore and loading them from metastore.
3. extend Statistics class by adding estimatedSize and rowCount.
## How was this patch tested?
unit tests
You can merge this pull request into a Git repository by running:
$ git pull https://github.com/wzhfy/spark tableStats
Alternatively you can review and apply these changes as the patch at:
https://github.com/apache/spark/pull/14712.patch
To close this pull request, make a commit to your master/trunk branch
with (at least) the following in the commit message:
This closes #14712
----
commit 4375e76c7ef4dd68e91f2bc5d5aa1cd31c4d3989
Author: wangzhenhua <wa...@huawei.com>
Date: 2016-08-19T06:17:44Z
support table-level statistics
----
---
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 infrastructure@apache.org or file a JIRA ticket
with INFRA.
---
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org
[GitHub] spark pull request #14712: [SPARK-17072] [SQL] support table-level statistic...
Posted by viirya <gi...@git.apache.org>.
Github user viirya commented on a diff in the pull request:
https://github.com/apache/spark/pull/14712#discussion_r76917963
--- Diff: sql/hive/src/main/scala/org/apache/spark/sql/hive/HiveExternalCatalog.scala ---
@@ -401,6 +401,13 @@ private[spark] class HiveExternalCatalog(conf: SparkConf, hadoopConf: Configurat
}
}
+ override def alterTableStats(tableDefinition: CatalogTable): Unit = withClient {
--- End diff --
I am hesitant to add another public API which looks like is overlapping with `alterTable`.
---
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 infrastructure@apache.org or file a JIRA ticket
with INFRA.
---
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org
[GitHub] spark pull request #14712: [SPARK-17072] [SQL] support table-level statistic...
Posted by gatorsmile <gi...@git.apache.org>.
Github user gatorsmile commented on a diff in the pull request:
https://github.com/apache/spark/pull/14712#discussion_r76920921
--- Diff: sql/hive/src/test/scala/org/apache/spark/sql/hive/StatisticsSuite.scala ---
@@ -168,6 +169,81 @@ class StatisticsSuite extends QueryTest with TestHiveSingleton with SQLTestUtils
TableIdentifier("tempTable"), ignoreIfNotExists = true, purge = false)
}
+ private def checkMetastoreRelationStats(
+ tableName: String,
+ totalSize: Long,
+ rowCount: Option[BigInt]): Unit = {
+ val df = sql(s"SELECT * FROM $tableName")
+ val relations = df.queryExecution.analyzed.collect { case rel: MetastoreRelation =>
+ rel.statistics
--- End diff --
this is useless, 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 infrastructure@apache.org or file a JIRA ticket
with INFRA.
---
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org
[GitHub] spark pull request #14712: [SPARK-17072] [SQL] support table-level statistic...
Posted by wzhfy <gi...@git.apache.org>.
Github user wzhfy commented on a diff in the pull request:
https://github.com/apache/spark/pull/14712#discussion_r75573715
--- Diff: sql/hive/src/main/scala/org/apache/spark/sql/hive/MetastoreRelation.scala ---
@@ -141,7 +142,16 @@ private[hive] case class MetastoreRelation(
sparkSession.sessionState.conf.defaultSizeInBytes
})
}
- )
+ val tableParams = hiveQlTable.getParameters
+ val rowCount = tableParams.get(AnalyzeTableCommand.ROW_COUNT)
+ if (rowCount != null && rowCount.toLong >=0) {
--- End diff --
actually, I will need the if block to decide whether to compute total size when we have column stats.
Although we can still use Option(rowCount).map(some function)... for the second property estimatedSize, this looks not intuitive. The if-else is easier to read.
So I'll keep the if-else block, what do you think?
---
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 infrastructure@apache.org or file a JIRA ticket
with INFRA.
---
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org
[GitHub] spark issue #14712: [SPARK-17072] [SQL] support table-level statistics gener...
Posted by AmplabJenkins <gi...@git.apache.org>.
Github user AmplabJenkins commented on the issue:
https://github.com/apache/spark/pull/14712
Test PASSed.
Refer to this link for build results (access rights to CI server needed):
https://amplab.cs.berkeley.edu/jenkins//job/SparkPullRequestBuilder/64850/
Test PASSed.
---
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 infrastructure@apache.org or file a JIRA ticket
with INFRA.
---
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org
[GitHub] spark issue #14712: [SPARK-17072] [SQL] support table-level statistics gener...
Posted by SparkQA <gi...@git.apache.org>.
Github user SparkQA commented on the issue:
https://github.com/apache/spark/pull/14712
**[Test build #64641 has started](https://amplab.cs.berkeley.edu/jenkins/job/SparkPullRequestBuilder/64641/consoleFull)** for PR 14712 at commit [`aef78d4`](https://github.com/apache/spark/commit/aef78d4bffac4dad99d1646c659e626a4eccb26b).
---
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 infrastructure@apache.org or file a JIRA ticket
with INFRA.
---
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org
[GitHub] spark pull request #14712: [SPARK-17072] [SQL] support table-level statistic...
Posted by wzhfy <gi...@git.apache.org>.
Github user wzhfy commented on a diff in the pull request:
https://github.com/apache/spark/pull/14712#discussion_r76381470
--- Diff: sql/hive/src/main/scala/org/apache/spark/sql/hive/HiveExternalCatalog.scala ---
@@ -401,6 +401,13 @@ private[spark] class HiveExternalCatalog(conf: SparkConf, hadoopConf: Configurat
}
}
+ override def alterTableStats(tableDefinition: CatalogTable): Unit = withClient {
--- End diff --
is it ok that we put the logic into the original alterTable? That is, update properties from catalogStats every time we call alterTable.
---
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 infrastructure@apache.org or file a JIRA ticket
with INFRA.
---
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org
[GitHub] spark issue #14712: [SPARK-17072] [SQL] support table-level statistics gener...
Posted by cloud-fan <gi...@git.apache.org>.
Github user cloud-fan commented on the issue:
https://github.com/apache/spark/pull/14712
> we must set STATS_GENERATED_VIA_STATS_TASK, otherwise the stats won't be stored
What if we use different property names to store statistics?
---
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 infrastructure@apache.org or file a JIRA ticket
with INFRA.
---
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org
[GitHub] spark pull request #14712: [SPARK-17072] [SQL] support table-level statistic...
Posted by cloud-fan <gi...@git.apache.org>.
Github user cloud-fan commented on a diff in the pull request:
https://github.com/apache/spark/pull/14712#discussion_r77307355
--- Diff: sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/catalog/interface.scala ---
@@ -130,6 +130,7 @@ case class CatalogTable(
createTime: Long = System.currentTimeMillis,
lastAccessTime: Long = -1,
properties: Map[String, String] = Map.empty,
+ stats: Option[Statistics] = None,
--- End diff --
`LogicalRelation` doesn't need to be updated I think.
---
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 infrastructure@apache.org or file a JIRA ticket
with INFRA.
---
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org
[GitHub] spark pull request #14712: [SPARK-17072] [SQL] support table-level statistic...
Posted by gatorsmile <gi...@git.apache.org>.
Github user gatorsmile commented on a diff in the pull request:
https://github.com/apache/spark/pull/14712#discussion_r76920234
--- Diff: sql/hive/src/test/scala/org/apache/spark/sql/hive/StatisticsSuite.scala ---
@@ -168,6 +169,81 @@ class StatisticsSuite extends QueryTest with TestHiveSingleton with SQLTestUtils
TableIdentifier("tempTable"), ignoreIfNotExists = true, purge = false)
}
+ private def checkMetastoreRelationStats(
+ tableName: String,
+ totalSize: Long,
+ rowCount: Option[BigInt]): Unit = {
--- End diff --
`totalSize` => `expectedTotalSize`
`rowCount` => `expectedRowCount`
---
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 infrastructure@apache.org or file a JIRA ticket
with INFRA.
---
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org
[GitHub] spark pull request #14712: [SPARK-17072] [SQL] support table-level statistic...
Posted by wzhfy <gi...@git.apache.org>.
Github user wzhfy commented on a diff in the pull request:
https://github.com/apache/spark/pull/14712#discussion_r76948258
--- Diff: sql/hive/src/main/scala/org/apache/spark/sql/hive/MetastoreRelation.scala ---
@@ -140,7 +145,12 @@ private[hive] case class MetastoreRelation(
sparkSession.sessionState.conf.defaultSizeInBytes
})
}
- )
+ if (catalogTable.catalogStats.isDefined) {
--- End diff --
good point, let me fix it
---
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 infrastructure@apache.org or file a JIRA ticket
with INFRA.
---
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org
[GitHub] spark pull request #14712: [SPARK-17072] [SQL] support table-level statistic...
Posted by wzhfy <gi...@git.apache.org>.
Github user wzhfy commented on a diff in the pull request:
https://github.com/apache/spark/pull/14712#discussion_r76922102
--- Diff: sql/hive/src/test/scala/org/apache/spark/sql/hive/StatisticsSuite.scala ---
@@ -168,6 +169,81 @@ class StatisticsSuite extends QueryTest with TestHiveSingleton with SQLTestUtils
TableIdentifier("tempTable"), ignoreIfNotExists = true, purge = false)
}
+ private def checkMetastoreRelationStats(
+ tableName: String,
+ totalSize: Long,
+ rowCount: Option[BigInt]): Unit = {
+ val df = sql(s"SELECT * FROM $tableName")
+ val relations = df.queryExecution.analyzed.collect { case rel: MetastoreRelation =>
+ rel.statistics
+ assert(rel.statistics.sizeInBytes === totalSize)
+ assert(rel.statistics.rowCount === rowCount)
+ }
+ assert(relations.size === 1)
+ }
+
+ private def checkLogicalRelationStats(tableName: String, rowCount: Option[BigInt]): Unit = {
+ val df = sql(s"SELECT * FROM $tableName")
+ val relations = df.queryExecution.analyzed.collect { case rel: LogicalRelation =>
+ assert(rel.statistics.sizeInBytes === rel.relation.sizeInBytes)
--- End diff --
btw, spark 2.0 has some bugs on Windows during tests, mainly about paths.
---
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 infrastructure@apache.org or file a JIRA ticket
with INFRA.
---
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org
[GitHub] spark pull request #14712: [SPARK-17072] [SQL] support table-level statistic...
Posted by cloud-fan <gi...@git.apache.org>.
Github user cloud-fan commented on a diff in the pull request:
https://github.com/apache/spark/pull/14712#discussion_r77113174
--- Diff: sql/core/src/main/scala/org/apache/spark/sql/execution/datasources/LogicalRelation.scala ---
@@ -52,7 +52,8 @@ case class LogicalRelation(
// Logical Relations are distinct if they have different output for the sake of transformations.
override def equals(other: Any): Boolean = other match {
- case l @ LogicalRelation(otherRelation, _, _) => relation == otherRelation && output == l.output
+ case l @ LogicalRelation(otherRelation, _, _) =>
+ relation == otherRelation && output == l.output
--- End diff --
unnecessary change?
---
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 infrastructure@apache.org or file a JIRA ticket
with INFRA.
---
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org
[GitHub] spark pull request #14712: [SPARK-17072] [SQL] support table-level statistic...
Posted by gatorsmile <gi...@git.apache.org>.
Github user gatorsmile commented on a diff in the pull request:
https://github.com/apache/spark/pull/14712#discussion_r76926133
--- Diff: sql/hive/src/main/scala/org/apache/spark/sql/hive/HiveExternalCatalog.scala ---
@@ -401,6 +401,13 @@ private[spark] class HiveExternalCatalog(conf: SparkConf, hadoopConf: Configurat
}
}
+ override def alterTableStats(tableDefinition: CatalogTable): Unit = withClient {
--- End diff --
Yeah, agree with @cloud-fan .
If we want to set it using `alter table`, we should use the dedicated command (just like what Hive does):
```SQL
ALTER TABLE UPDATE STATISTICS SET
```
Let us remove `alterTableStats` and minimize the code changes? We can discuss how to do it properly when we start this JIRA: https://issues.apache.org/jira/browse/SPARK-17282
---
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 infrastructure@apache.org or file a JIRA ticket
with INFRA.
---
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org
[GitHub] spark pull request #14712: [SPARK-17072] [SQL] support table-level statistic...
Posted by cloud-fan <gi...@git.apache.org>.
Github user cloud-fan commented on a diff in the pull request:
https://github.com/apache/spark/pull/14712#discussion_r77300889
--- Diff: sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/catalog/interface.scala ---
@@ -130,6 +130,7 @@ case class CatalogTable(
createTime: Long = System.currentTimeMillis,
lastAccessTime: Long = -1,
properties: Map[String, String] = Map.empty,
+ stats: Option[Statistics] = None,
--- End diff --
nit: we should also update `toStrimg` to include `stats`.
---
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 infrastructure@apache.org or file a JIRA ticket
with INFRA.
---
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org
[GitHub] spark pull request #14712: [SPARK-17072] [SQL] support table-level statistic...
Posted by cloud-fan <gi...@git.apache.org>.
Github user cloud-fan commented on a diff in the pull request:
https://github.com/apache/spark/pull/14712#discussion_r77303388
--- Diff: sql/hive/src/main/scala/org/apache/spark/sql/hive/HiveExternalCatalog.scala ---
@@ -383,21 +384,34 @@ private[spark] class HiveExternalCatalog(conf: SparkConf, hadoopConf: Configurat
requireTableExists(db, tableDefinition.identifier.table)
verifyTableProperties(tableDefinition)
- if (DDLUtils.isDatasourceTable(tableDefinition)) {
- val oldDef = client.getTable(db, tableDefinition.identifier.table)
+ // convert table statistics to properties so that we can persist them through hive api
+ val catalogTable = if (tableDefinition.stats.isDefined) {
--- End diff --
nit:
```
val statsProps = if (tableDefinition.stats.isDefined) {
val stats = tableDefinition.stats.get
...
} else {
Map.empty
}
if (DDLUtils.isDatasourceTable(catalogTable)) {
...
val newDef = tableDefinition.copy(
...
properties = oldDataSourceProps ++ tableDefinition.properties ++ statsProps,
)
}
```
---
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 infrastructure@apache.org or file a JIRA ticket
with INFRA.
---
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org
[GitHub] spark pull request #14712: [SPARK-17072] [SQL] support table-level statistic...
Posted by wzhfy <gi...@git.apache.org>.
Github user wzhfy commented on a diff in the pull request:
https://github.com/apache/spark/pull/14712#discussion_r76929362
--- Diff: sql/hive/src/main/scala/org/apache/spark/sql/hive/HiveExternalCatalog.scala ---
@@ -401,6 +401,13 @@ private[spark] class HiveExternalCatalog(conf: SparkConf, hadoopConf: Configurat
}
}
+ override def alterTableStats(tableDefinition: CatalogTable): Unit = withClient {
--- End diff --
I see. OK, i'll remove this.
---
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 infrastructure@apache.org or file a JIRA ticket
with INFRA.
---
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org
[GitHub] spark issue #14712: [SPARK-17072] [SQL] support table-level statistics gener...
Posted by cloud-fan <gi...@git.apache.org>.
Github user cloud-fan commented on the issue:
https://github.com/apache/spark/pull/14712
looks pretty good now! I left some comments about some small issues, thanks for working on it!
---
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 infrastructure@apache.org or file a JIRA ticket
with INFRA.
---
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org
[GitHub] spark pull request #14712: [SPARK-17072] [SQL] support table-level statistic...
Posted by gatorsmile <gi...@git.apache.org>.
Github user gatorsmile commented on a diff in the pull request:
https://github.com/apache/spark/pull/14712#discussion_r75544361
--- Diff: sql/core/src/main/scala/org/apache/spark/sql/execution/command/AnalyzeTableCommand.scala ---
@@ -108,4 +126,8 @@ case class AnalyzeTableCommand(tableName: String) extends RunnableCommand {
object AnalyzeTableCommand {
val TOTAL_SIZE_FIELD = "totalSize"
+ // same as org.apache.hadoop.hive.common.StatsSetupConst
+ val ROW_COUNT = "numRows"
+ val STATS_GENERATED_VIA_STATS_TASK = "STATS_GENERATED_VIA_STATS_TASK"
+ val TRUE = "true"
--- End diff --
Agree. It is not case sensitive. I tried it using the Hive command line. It works well even if it is `TrUe`
---
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 infrastructure@apache.org or file a JIRA ticket
with INFRA.
---
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org
[GitHub] spark issue #14712: [SPARK-17072] [SQL] support table-level statistics gener...
Posted by AmplabJenkins <gi...@git.apache.org>.
Github user AmplabJenkins commented on the issue:
https://github.com/apache/spark/pull/14712
Merged build finished. Test FAILed.
---
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 infrastructure@apache.org or file a JIRA ticket
with INFRA.
---
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org
[GitHub] spark pull request #14712: [SPARK-17072] [SQL] support table-level statistic...
Posted by rxin <gi...@git.apache.org>.
Github user rxin commented on a diff in the pull request:
https://github.com/apache/spark/pull/14712#discussion_r75439413
--- Diff: sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/plans/logical/LogicalPlan.scala ---
@@ -95,6 +95,12 @@ abstract class LogicalPlan extends QueryPlan[LogicalPlan] with Logging {
}
/**
+ * Estimate complete [[Statistics]] for this plan. Each plan need to override this to get
+ * complete statistics.
+ */
+ def completeStats: Statistics = statistics
--- End diff --
You can merge the two even now. In the worst case they can be controlled via a config?
---
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 infrastructure@apache.org or file a JIRA ticket
with INFRA.
---
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org
[GitHub] spark pull request #14712: [SPARK-17072] [SQL] support table-level statistic...
Posted by wzhfy <gi...@git.apache.org>.
Github user wzhfy commented on a diff in the pull request:
https://github.com/apache/spark/pull/14712#discussion_r77002553
--- Diff: sql/hive/src/main/scala/org/apache/spark/sql/hive/HiveExternalCatalog.scala ---
@@ -383,21 +383,36 @@ private[spark] class HiveExternalCatalog(conf: SparkConf, hadoopConf: Configurat
requireTableExists(db, tableDefinition.identifier.table)
verifyTableProperties(tableDefinition)
- if (DDLUtils.isDatasourceTable(tableDefinition)) {
- val oldDef = client.getTable(db, tableDefinition.identifier.table)
+ // convert table statistics to properties so that we can persist them through hive api
+ val catalogTable = if (tableDefinition.catalogStats.isDefined) {
+ // first we need to clear the old (i.e. inaccurate) stats
--- End diff --
yeah, it's better to move the logic from **HiveClientImpl** into **restoreTableMeta**
---
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 infrastructure@apache.org or file a JIRA ticket
with INFRA.
---
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org
[GitHub] spark pull request #14712: [SPARK-17072] [SQL] support table-level statistic...
Posted by cloud-fan <gi...@git.apache.org>.
Github user cloud-fan commented on a diff in the pull request:
https://github.com/apache/spark/pull/14712#discussion_r76385250
--- Diff: sql/hive/src/main/scala/org/apache/spark/sql/hive/HiveExternalCatalog.scala ---
@@ -401,6 +401,13 @@ private[spark] class HiveExternalCatalog(conf: SparkConf, hadoopConf: Configurat
}
}
+ override def alterTableStats(tableDefinition: CatalogTable): Unit = withClient {
--- End diff --
is it really separated? It looks like we just call `alterTable` in `alterTableState`.
---
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 infrastructure@apache.org or file a JIRA ticket
with INFRA.
---
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org
[GitHub] spark pull request #14712: [SPARK-17072] [SQL] support table-level statistic...
Posted by viirya <gi...@git.apache.org>.
Github user viirya commented on a diff in the pull request:
https://github.com/apache/spark/pull/14712#discussion_r76920785
--- Diff: sql/core/src/main/scala/org/apache/spark/sql/execution/datasources/LogicalRelation.scala ---
@@ -33,7 +33,8 @@ import org.apache.spark.util.Utils
case class LogicalRelation(
relation: BaseRelation,
expectedOutputAttributes: Option[Seq[Attribute]] = None,
- metastoreTableIdentifier: Option[TableIdentifier] = None)
+ metastoreTableIdentifier: Option[TableIdentifier] = None,
+ inheritedStats: Option[Statistics] = None)
--- End diff --
For MetastoreRelation, isn't LogicalRelation simply using MetastoreRelation's statistics?
---
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 infrastructure@apache.org or file a JIRA ticket
with INFRA.
---
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org
[GitHub] spark pull request #14712: [SPARK-17072] [SQL] support table-level statistic...
Posted by wzhfy <gi...@git.apache.org>.
Github user wzhfy commented on a diff in the pull request:
https://github.com/apache/spark/pull/14712#discussion_r76354939
--- Diff: sql/core/src/main/scala/org/apache/spark/sql/execution/command/AnalyzeTableCommand.scala ---
@@ -88,14 +89,70 @@ case class AnalyzeTableCommand(tableName: String) extends RunnableCommand {
}
}.getOrElse(0L)
- // Update the Hive metastore if the total size of the table is different than the size
- // recorded in the Hive metastore.
- // This logic is based on org.apache.hadoop.hive.ql.exec.StatsTask.aggregateStats().
- if (newTotalSize > 0 && newTotalSize != oldTotalSize) {
+ var needUpdate = false
+ val totalSize = if (newTotalSize > 0 && newTotalSize != oldTotalSize) {
+ needUpdate = true
+ newTotalSize
+ } else {
+ oldTotalSize
+ }
+ var numRows: Option[BigInt] = None
+ if (!noscan) {
+ val oldRowCount: Long = if (catalogTable.catalogStats.isDefined) {
+ catalogTable.catalogStats.get.rowCount.map(_.toLong).getOrElse(-1L)
+ } else {
+ -1L
+ }
+ val newRowCount = sparkSession.table(tableName).count()
+ if (newRowCount >= 0 && newRowCount != oldRowCount) {
+ numRows = Some(BigInt(newRowCount))
+ needUpdate = true
+ }
+ }
+ // Update the metastore if the above statistics of the table are different from those
+ // recorded in the metastore.
+ if (needUpdate) {
+ sessionState.catalog.alterTable(
+ catalogTable.copy(
+ catalogStats = Some(Statistics(
+ sizeInBytes = totalSize, rowCount = numRows))),
+ fromAnalyze = true)
+
+ // Refresh the cache of the table in the catalog.
+ sessionState.catalog.refreshTable(tableIdent)
+ }
+
+ // data source tables have been converted into LogicalRelations
+ case logicalRel: LogicalRelation if logicalRel.metastoreTableIdentifier.isDefined =>
--- End diff --
you can run my added test case "test table-level statistics for data source table created in HiveExternalCatalog"
---
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 infrastructure@apache.org or file a JIRA ticket
with INFRA.
---
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org
[GitHub] spark issue #14712: [SPARK-17072] [SQL] support table-level statistics gener...
Posted by SparkQA <gi...@git.apache.org>.
Github user SparkQA commented on the issue:
https://github.com/apache/spark/pull/14712
**[Test build #64567 has started](https://amplab.cs.berkeley.edu/jenkins/job/SparkPullRequestBuilder/64567/consoleFull)** for PR 14712 at commit [`3407c7f`](https://github.com/apache/spark/commit/3407c7f7aa62503e62c7c4847ad6a2568a676c38).
---
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 infrastructure@apache.org or file a JIRA ticket
with INFRA.
---
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org
[GitHub] spark issue #14712: [SPARK-17072] [SQL] support table-level statistics gener...
Posted by gatorsmile <gi...@git.apache.org>.
Github user gatorsmile commented on the issue:
https://github.com/apache/spark/pull/14712
If the goal also includes the interoperability with Hive, the test cases should also verify whether the table property `COLUMN_STATS_ACCURATE` is `true` or not. This should be implicitly updated by Hive.
---
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 infrastructure@apache.org or file a JIRA ticket
with INFRA.
---
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org
[GitHub] spark pull request #14712: [SPARK-17072] [SQL] support table-level statistic...
Posted by cloud-fan <gi...@git.apache.org>.
Github user cloud-fan commented on a diff in the pull request:
https://github.com/apache/spark/pull/14712#discussion_r76386013
--- Diff: sql/hive/src/main/scala/org/apache/spark/sql/hive/client/HiveClientImpl.scala ---
@@ -427,6 +430,44 @@ private[hive] class HiveClientImpl(
client.alterTable(qualifiedTableName, hiveTable)
}
+ override def alterTableStats(table: CatalogTable): Unit = withHiveState {
--- End diff --
Currently the `HiveClient` is responsible to talk to hive metastore and convert hive meta(HiveTable) to Spark meta(CatalogTable).
The `HiveExternalCatalog` is responsible to act as bridge between external catalog interface and hive client, and do some tricks if the hive client can't support the functionality defined by external catalog.
---
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 infrastructure@apache.org or file a JIRA ticket
with INFRA.
---
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org
[GitHub] spark pull request #14712: [SPARK-17072] [SQL] support table-level statistic...
Posted by wzhfy <gi...@git.apache.org>.
Github user wzhfy commented on a diff in the pull request:
https://github.com/apache/spark/pull/14712#discussion_r76919518
--- Diff: sql/hive/src/main/scala/org/apache/spark/sql/hive/HiveExternalCatalog.scala ---
@@ -401,6 +401,13 @@ private[spark] class HiveExternalCatalog(conf: SparkConf, hadoopConf: Configurat
}
}
+ override def alterTableStats(tableDefinition: CatalogTable): Unit = withClient {
--- End diff --
@viirya There's two ways to set/replace properties:
1. We use statistics info in CatalogTable to set these properties - this is called by analyze command and I put this logic into alterTableStats method;
2. We set these properties directly - this is the path of alter table command.
If we put alterTableStats logic in the original alterTable method, we can't set the properties by the second way, because they will be always replaced by stats in CatalogTable.
---
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 infrastructure@apache.org or file a JIRA ticket
with INFRA.
---
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org
[GitHub] spark pull request #14712: [SPARK-17072] [SQL] support table-level statistic...
Posted by wzhfy <gi...@git.apache.org>.
Github user wzhfy commented on a diff in the pull request:
https://github.com/apache/spark/pull/14712#discussion_r75568863
--- Diff: sql/core/src/main/scala/org/apache/spark/sql/execution/SparkSqlParser.scala ---
@@ -99,9 +99,7 @@ class SparkSqlAstBuilder(conf: SQLConf) extends AstBuilder {
ctx.identifier.getText.toLowerCase == "noscan") {
--- End diff --
@cloud-fan noscan won't scan files, it only collects statistics like total size. Without noscan, we will collect other stats like row count and column level stats.
---
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 infrastructure@apache.org or file a JIRA ticket
with INFRA.
---
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org
[GitHub] spark issue #14712: [SPARK-17072] [SQL] support table-level statistics gener...
Posted by AmplabJenkins <gi...@git.apache.org>.
Github user AmplabJenkins commented on the issue:
https://github.com/apache/spark/pull/14712
Test FAILed.
Refer to this link for build results (access rights to CI server needed):
https://amplab.cs.berkeley.edu/jenkins//job/SparkPullRequestBuilder/64625/
Test FAILed.
---
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 infrastructure@apache.org or file a JIRA ticket
with INFRA.
---
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org
[GitHub] spark issue #14712: [SPARK-17072] [SQL] support table-level statistics gener...
Posted by gatorsmile <gi...@git.apache.org>.
Github user gatorsmile commented on the issue:
https://github.com/apache/spark/pull/14712
So far, the test coverage is weak. Could we add more test cases to cover all the corner cases? Thanks!
---
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 infrastructure@apache.org or file a JIRA ticket
with INFRA.
---
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org
[GitHub] spark pull request #14712: [SPARK-17072] [SQL] support table-level statistic...
Posted by cloud-fan <gi...@git.apache.org>.
Github user cloud-fan commented on a diff in the pull request:
https://github.com/apache/spark/pull/14712#discussion_r76966709
--- Diff: sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/catalog/interface.scala ---
@@ -130,6 +130,7 @@ case class CatalogTable(
createTime: Long = System.currentTimeMillis,
lastAccessTime: Long = -1,
properties: Map[String, String] = Map.empty,
+ catalogStats: Option[Statistics] = None,
--- End diff --
nit: according to the other names, I think we don't need the `catalog` prefix, i.e. `stats` or `statistics` is fine.
---
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 infrastructure@apache.org or file a JIRA ticket
with INFRA.
---
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org
[GitHub] spark pull request #14712: [SPARK-17072] [SQL] support table-level statistic...
Posted by cloud-fan <gi...@git.apache.org>.
Github user cloud-fan commented on a diff in the pull request:
https://github.com/apache/spark/pull/14712#discussion_r76967533
--- Diff: sql/hive/src/main/scala/org/apache/spark/sql/hive/HiveExternalCatalog.scala ---
@@ -383,21 +383,36 @@ private[spark] class HiveExternalCatalog(conf: SparkConf, hadoopConf: Configurat
requireTableExists(db, tableDefinition.identifier.table)
verifyTableProperties(tableDefinition)
- if (DDLUtils.isDatasourceTable(tableDefinition)) {
- val oldDef = client.getTable(db, tableDefinition.identifier.table)
+ // convert table statistics to properties so that we can persist them through hive api
+ val catalogTable = if (tableDefinition.catalogStats.isDefined) {
+ // first we need to clear the old (i.e. inaccurate) stats
--- End diff --
We can remove the statistics properties and convert them to `Statistics` object in `restoreTableMeta`
---
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 infrastructure@apache.org or file a JIRA ticket
with INFRA.
---
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org
[GitHub] spark issue #14712: [SPARK-17072] [SQL] support table-level statistics gener...
Posted by AmplabJenkins <gi...@git.apache.org>.
Github user AmplabJenkins commented on the issue:
https://github.com/apache/spark/pull/14712
Test PASSed.
Refer to this link for build results (access rights to CI server needed):
https://amplab.cs.berkeley.edu/jenkins//job/SparkPullRequestBuilder/64886/
Test PASSed.
---
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 infrastructure@apache.org or file a JIRA ticket
with INFRA.
---
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org
[GitHub] spark issue #14712: [SPARK-17072] [SQL] support table-level statistics gener...
Posted by SparkQA <gi...@git.apache.org>.
Github user SparkQA commented on the issue:
https://github.com/apache/spark/pull/14712
**[Test build #64713 has finished](https://amplab.cs.berkeley.edu/jenkins/job/SparkPullRequestBuilder/64713/consoleFull)** for PR 14712 at commit [`56ec68e`](https://github.com/apache/spark/commit/56ec68e455cefcc589db0336a580754662d8257c).
* This patch **fails Spark unit tests**.
* This patch merges cleanly.
* This patch adds no public classes.
---
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 infrastructure@apache.org or file a JIRA ticket
with INFRA.
---
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org
[GitHub] spark issue #14712: [SPARK-17072] [SQL] support table-level statistics gener...
Posted by gatorsmile <gi...@git.apache.org>.
Github user gatorsmile commented on the issue:
https://github.com/apache/spark/pull/14712
These tests block multiple PRs. It is midnight in China. : ) Let me do a quick fix based on the comments of @cloud-fan and @hvanhovell
---
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 infrastructure@apache.org or file a JIRA ticket
with INFRA.
---
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org
[GitHub] spark issue #14712: [SPARK-17072] [SQL] support table-level statistics gener...
Posted by SparkQA <gi...@git.apache.org>.
Github user SparkQA commented on the issue:
https://github.com/apache/spark/pull/14712
**[Test build #64567 has finished](https://amplab.cs.berkeley.edu/jenkins/job/SparkPullRequestBuilder/64567/consoleFull)** for PR 14712 at commit [`3407c7f`](https://github.com/apache/spark/commit/3407c7f7aa62503e62c7c4847ad6a2568a676c38).
* This patch **fails to build**.
* This patch merges cleanly.
* This patch adds no public classes.
---
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 infrastructure@apache.org or file a JIRA ticket
with INFRA.
---
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org
[GitHub] spark pull request #14712: [SPARK-17072] [SQL] support table-level statistic...
Posted by hvanhovell <gi...@git.apache.org>.
Github user hvanhovell commented on a diff in the pull request:
https://github.com/apache/spark/pull/14712#discussion_r77610557
--- Diff: sql/hive/src/test/scala/org/apache/spark/sql/hive/StatisticsSuite.scala ---
@@ -168,6 +171,154 @@ class StatisticsSuite extends QueryTest with TestHiveSingleton with SQLTestUtils
TableIdentifier("tempTable"), ignoreIfNotExists = true, purge = false)
}
+ private def checkMetastoreRelationStats(
+ tableName: String,
+ expectedStats: Option[Statistics]): Unit = {
+ val df = sql(s"SELECT * FROM $tableName")
+ val relations = df.queryExecution.analyzed.collect { case rel: MetastoreRelation =>
+ expectedStats match {
+ case Some(es) =>
+ assert(rel.catalogTable.stats.isDefined)
+ val stats = rel.catalogTable.stats.get
+ assert(stats.sizeInBytes === es.sizeInBytes)
+ assert(stats.rowCount === es.rowCount)
+ case None =>
+ assert(rel.catalogTable.stats.isEmpty)
+ }
+ rel
+ }
+ assert(relations.size === 1)
+ }
+
+ test("test table-level statistics for hive tables created in HiveExternalCatalog") {
+ val textTable = "textTable"
+ withTable(textTable) {
+ // Currently Spark's statistics are self-contained, we don't have statistics until we use
+ // the `ANALYZE TABLE` command.
+ sql(s"CREATE TABLE $textTable (key STRING, value STRING) STORED AS TEXTFILE")
+ checkMetastoreRelationStats(textTable, expectedStats = None)
+ sql(s"INSERT INTO TABLE $textTable SELECT * FROM src")
+ checkMetastoreRelationStats(textTable, expectedStats = None)
+
+ // noscan won't count the number of rows
+ sql(s"ANALYZE TABLE $textTable COMPUTE STATISTICS noscan")
+ checkMetastoreRelationStats(textTable, expectedStats =
+ Some(Statistics(sizeInBytes = 5812, rowCount = None)))
--- End diff --
This is probably caused by Hive's `hive.exec.compress.output`; try setting this to `false`. I do agree with @cloud-fan, that equality testing in these cases is very brittle.
---
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 infrastructure@apache.org or file a JIRA ticket
with INFRA.
---
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org
[GitHub] spark pull request #14712: [SPARK-17072] [SQL] support table-level statistic...
Posted by hvanhovell <gi...@git.apache.org>.
Github user hvanhovell commented on a diff in the pull request:
https://github.com/apache/spark/pull/14712#discussion_r76533558
--- Diff: sql/core/src/main/scala/org/apache/spark/sql/execution/command/AnalyzeTableCommand.scala ---
@@ -88,14 +87,66 @@ case class AnalyzeTableCommand(tableName: String) extends RunnableCommand {
}
}.getOrElse(0L)
- // Update the Hive metastore if the total size of the table is different than the size
- // recorded in the Hive metastore.
- // This logic is based on org.apache.hadoop.hive.ql.exec.StatsTask.aggregateStats().
- if (newTotalSize > 0 && newTotalSize != oldTotalSize) {
+ var needUpdate = false
+ val totalSize = if (newTotalSize > 0 && newTotalSize != oldTotalSize) {
+ needUpdate = true
+ newTotalSize
+ } else {
+ oldTotalSize
+ }
+ var numRows: Option[BigInt] = None
--- End diff --
Is it ok to remove the `numRows` statistics if we issue a `ANALYZE TABLE tbl_a NOSCAN`?
---
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 infrastructure@apache.org or file a JIRA ticket
with INFRA.
---
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org
[GitHub] spark pull request #14712: [SPARK-17072] [SQL] support table-level statistic...
Posted by wzhfy <gi...@git.apache.org>.
Github user wzhfy commented on a diff in the pull request:
https://github.com/apache/spark/pull/14712#discussion_r76380753
--- Diff: sql/hive/src/main/scala/org/apache/spark/sql/hive/HiveExternalCatalog.scala ---
@@ -401,6 +401,13 @@ private[spark] class HiveExternalCatalog(conf: SparkConf, hadoopConf: Configurat
}
}
+ override def alterTableStats(tableDefinition: CatalogTable): Unit = withClient {
--- End diff --
I want to separate the logic of processing stats from the normal alterTable method
---
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 infrastructure@apache.org or file a JIRA ticket
with INFRA.
---
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org
[GitHub] spark pull request #14712: [SPARK-17072] [SQL] support table-level statistic...
Posted by hvanhovell <gi...@git.apache.org>.
Github user hvanhovell commented on a diff in the pull request:
https://github.com/apache/spark/pull/14712#discussion_r76248301
--- Diff: sql/core/src/main/scala/org/apache/spark/sql/execution/command/AnalyzeTableCommand.scala ---
@@ -88,14 +89,70 @@ case class AnalyzeTableCommand(tableName: String) extends RunnableCommand {
}
}.getOrElse(0L)
- // Update the Hive metastore if the total size of the table is different than the size
- // recorded in the Hive metastore.
- // This logic is based on org.apache.hadoop.hive.ql.exec.StatsTask.aggregateStats().
- if (newTotalSize > 0 && newTotalSize != oldTotalSize) {
+ var needUpdate = false
+ val totalSize = if (newTotalSize > 0 && newTotalSize != oldTotalSize) {
+ needUpdate = true
+ newTotalSize
+ } else {
+ oldTotalSize
+ }
+ var numRows: Option[BigInt] = None
+ if (!noscan) {
+ val oldRowCount: Long = if (catalogTable.catalogStats.isDefined) {
--- End diff --
`catalogTable.catalogStats.flatMap(_.rowCount.map(_.toLong)).getOrElse(-1L)` is shorter. It would also a bit shorted if you put `catalogStats` in its own val.
---
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 infrastructure@apache.org or file a JIRA ticket
with INFRA.
---
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org
[GitHub] spark pull request #14712: [SPARK-17072] [SQL] support table-level statistic...
Posted by gatorsmile <gi...@git.apache.org>.
Github user gatorsmile commented on a diff in the pull request:
https://github.com/apache/spark/pull/14712#discussion_r75512772
--- Diff: sql/core/src/main/scala/org/apache/spark/sql/execution/command/AnalyzeTableCommand.scala ---
@@ -88,14 +90,30 @@ case class AnalyzeTableCommand(tableName: String) extends RunnableCommand {
}
}.getOrElse(0L)
- // Update the Hive metastore if the total size of the table is different than the size
+ val needUpdate = new mutable.HashMap[String, String]()
+ if (newTotalSize > 0 && newTotalSize != oldTotalSize) {
+ needUpdate += (AnalyzeTableCommand.TOTAL_SIZE_FIELD -> newTotalSize.toString)
+ }
+ if (!noscan) {
+ val oldRowCount = tableParameters.get(AnalyzeTableCommand.ROW_COUNT).map(_.toLong)
+ .getOrElse(-1L)
+ val newRowCount = sparkSession.table(tableName).count()
+
+ if (newRowCount >= 0 && newRowCount != oldRowCount) {
+ needUpdate += (AnalyzeTableCommand.ROW_COUNT -> newRowCount.toString)
+ }
+ }
+ // Update the Hive metastore if the above parameters of the table is different than those
// recorded in the Hive metastore.
// This logic is based on org.apache.hadoop.hive.ql.exec.StatsTask.aggregateStats().
- if (newTotalSize > 0 && newTotalSize != oldTotalSize) {
+ if (needUpdate.nonEmpty) {
+ // need to set this parameter so that we can store other parameters like "numRows" into
+ // Hive metastore
+ needUpdate.put(AnalyzeTableCommand.STATS_GENERATED_VIA_STATS_TASK,
--- End diff --
I think we might need more code comments to explain these new concepts. This is a good example.
---
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 infrastructure@apache.org or file a JIRA ticket
with INFRA.
---
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org
[GitHub] spark pull request #14712: [SPARK-17072] [SQL] support table-level statistic...
Posted by wzhfy <gi...@git.apache.org>.
Github user wzhfy commented on a diff in the pull request:
https://github.com/apache/spark/pull/14712#discussion_r77318694
--- Diff: sql/hive/src/main/scala/org/apache/spark/sql/hive/HiveExternalCatalog.scala ---
@@ -610,6 +637,14 @@ object HiveExternalCatalog {
val DATASOURCE_SCHEMA_BUCKETCOL_PREFIX = DATASOURCE_SCHEMA_PREFIX + "bucketCol."
val DATASOURCE_SCHEMA_SORTCOL_PREFIX = DATASOURCE_SCHEMA_PREFIX + "sortCol."
+ val STATISTICS_PREFIX = "spark.sql.statistics."
--- End diff --
@cloud-fan just updated the pr and also added a test in HiveDDLSuite for this.
waiting for jenkins to run tests
---
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 infrastructure@apache.org or file a JIRA ticket
with INFRA.
---
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org
[GitHub] spark pull request #14712: [SPARK-17072] [SQL] support table-level statistic...
Posted by wzhfy <gi...@git.apache.org>.
Github user wzhfy commented on a diff in the pull request:
https://github.com/apache/spark/pull/14712#discussion_r75569715
--- Diff: sql/hive/src/test/scala/org/apache/spark/sql/hive/StatisticsSuite.scala ---
@@ -168,6 +170,57 @@ class StatisticsSuite extends QueryTest with TestHiveSingleton with SQLTestUtils
TableIdentifier("tempTable"), ignoreIfNotExists = true, purge = false)
}
+ test("generate table-level statistics") {
+ def checkTableStats(
+ statsSeq: Seq[Statistics],
+ sizeInBytes: Int,
+ estimatedSize: Int,
+ rowCount: Int): Unit = {
+ assert(statsSeq.size === 1)
+ assert(statsSeq.head.sizeInBytes === BigInt(sizeInBytes))
+ assert(statsSeq.head.estimatedSize === Some(BigInt(estimatedSize)))
+ assert(statsSeq.head.rowCount === Some(BigInt(rowCount)))
+ }
+
+ sql("CREATE TABLE analyzeTable (key STRING, value STRING)").collect()
--- End diff --
I'll modify unit tests based on your comments, thanks!
---
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 infrastructure@apache.org or file a JIRA ticket
with INFRA.
---
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org
[GitHub] spark issue #14712: [SPARK-17072] [SQL] support table-level statistics gener...
Posted by AmplabJenkins <gi...@git.apache.org>.
Github user AmplabJenkins commented on the issue:
https://github.com/apache/spark/pull/14712
Test PASSed.
Refer to this link for build results (access rights to CI server needed):
https://amplab.cs.berkeley.edu/jenkins//job/SparkPullRequestBuilder/64750/
Test PASSed.
---
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 infrastructure@apache.org or file a JIRA ticket
with INFRA.
---
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org
[GitHub] spark pull request #14712: [SPARK-17072] [SQL] support table-level statistic...
Posted by gatorsmile <gi...@git.apache.org>.
Github user gatorsmile commented on a diff in the pull request:
https://github.com/apache/spark/pull/14712#discussion_r75571695
--- Diff: sql/core/src/main/scala/org/apache/spark/sql/execution/command/AnalyzeTableCommand.scala ---
@@ -88,14 +90,30 @@ case class AnalyzeTableCommand(tableName: String) extends RunnableCommand {
}
}.getOrElse(0L)
- // Update the Hive metastore if the total size of the table is different than the size
+ val needUpdate = new mutable.HashMap[String, String]()
+ if (newTotalSize > 0 && newTotalSize != oldTotalSize) {
+ needUpdate += (AnalyzeTableCommand.TOTAL_SIZE_FIELD -> newTotalSize.toString)
+ }
+ if (!noscan) {
+ val oldRowCount = tableParameters.get(AnalyzeTableCommand.ROW_COUNT).map(_.toLong)
+ .getOrElse(-1L)
+ val newRowCount = sparkSession.table(tableName).count()
+
+ if (newRowCount >= 0 && newRowCount != oldRowCount) {
+ needUpdate += (AnalyzeTableCommand.ROW_COUNT -> newRowCount.toString)
+ }
+ }
+ // Update the Hive metastore if the above parameters of the table is different than those
// recorded in the Hive metastore.
// This logic is based on org.apache.hadoop.hive.ql.exec.StatsTask.aggregateStats().
- if (newTotalSize > 0 && newTotalSize != oldTotalSize) {
+ if (needUpdate.nonEmpty) {
+ // need to set this parameter so that we can store other parameters like "numRows" into
+ // Hive metastore
+ needUpdate.put(AnalyzeTableCommand.STATS_GENERATED_VIA_STATS_TASK,
--- End diff --
I saw it. The value of `numRows` is `-1`, as shown in https://github.com/apache/spark/pull/14712#discussion_r75540560
---
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 infrastructure@apache.org or file a JIRA ticket
with INFRA.
---
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org
[GitHub] spark issue #14712: [SPARK-17072] [SQL] support table-level statistics gener...
Posted by AmplabJenkins <gi...@git.apache.org>.
Github user AmplabJenkins commented on the issue:
https://github.com/apache/spark/pull/14712
Test FAILed.
Refer to this link for build results (access rights to CI server needed):
https://amplab.cs.berkeley.edu/jenkins//job/SparkPullRequestBuilder/64567/
Test FAILed.
---
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 infrastructure@apache.org or file a JIRA ticket
with INFRA.
---
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org
[GitHub] spark issue #14712: [SPARK-17072] [SQL] support table-level statistics gener...
Posted by wzhfy <gi...@git.apache.org>.
Github user wzhfy commented on the issue:
https://github.com/apache/spark/pull/14712
@gatorsmile Thank you for the good test cases!
---
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 infrastructure@apache.org or file a JIRA ticket
with INFRA.
---
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org
[GitHub] spark issue #14712: [SPARK-17072] [SQL] support table-level statistics gener...
Posted by wzhfy <gi...@git.apache.org>.
Github user wzhfy commented on the issue:
https://github.com/apache/spark/pull/14712
@cloud-fan @hvanhovell Could you launch a test for this pr? Thank you!
---
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 infrastructure@apache.org or file a JIRA ticket
with INFRA.
---
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org
[GitHub] spark issue #14712: [SPARK-17072] [SQL] support table-level statistics gener...
Posted by AmplabJenkins <gi...@git.apache.org>.
Github user AmplabJenkins commented on the issue:
https://github.com/apache/spark/pull/14712
Test PASSed.
Refer to this link for build results (access rights to CI server needed):
https://amplab.cs.berkeley.edu/jenkins//job/SparkPullRequestBuilder/64789/
Test PASSed.
---
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 infrastructure@apache.org or file a JIRA ticket
with INFRA.
---
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org
[GitHub] spark issue #14712: [SPARK-17072] [SQL] support table-level statistics gener...
Posted by cloud-fan <gi...@git.apache.org>.
Github user cloud-fan commented on the issue:
https://github.com/apache/spark/pull/14712
My proposal is: Like data source table metadata, we store the table statistics using different names from hive, if the statistics is hive compatible, like row count, we also store the corresponding hive entries. In this way, we won't be affected by possible hive metastore bugs, and hive can also recognize table statistics generated by spark.
When we read in a hive table, if its statistics already exists but in hive format, we can generate the corresponding spark sql entries. Then spark sql can also recognize table statistics generated by hive.
---
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 infrastructure@apache.org or file a JIRA ticket
with INFRA.
---
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org
[GitHub] spark pull request #14712: [SPARK-17072] [SQL] support table-level statistic...
Posted by cloud-fan <gi...@git.apache.org>.
Github user cloud-fan commented on a diff in the pull request:
https://github.com/apache/spark/pull/14712#discussion_r75481689
--- Diff: sql/core/src/main/scala/org/apache/spark/sql/execution/command/AnalyzeTableCommand.scala ---
@@ -33,7 +34,7 @@ import org.apache.spark.sql.catalyst.catalog.{CatalogRelation, CatalogTable}
* Right now, it only supports Hive tables and it only updates the size of a Hive table
* in the Hive metastore.
*/
-case class AnalyzeTableCommand(tableName: String) extends RunnableCommand {
+case class AnalyzeTableCommand(tableName: String, noscan: Boolean = true) extends RunnableCommand {
--- End diff --
When we insert data into table, should we recalculate/invalidate the statistics for this table?
---
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 infrastructure@apache.org or file a JIRA ticket
with INFRA.
---
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org
[GitHub] spark issue #14712: [SPARK-17072] [SQL] support table-level statistics gener...
Posted by scwf <gi...@git.apache.org>.
Github user scwf commented on the issue:
https://github.com/apache/spark/pull/14712
/cc @cloud-fan @rxin
---
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 infrastructure@apache.org or file a JIRA ticket
with INFRA.
---
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org
[GitHub] spark pull request #14712: [SPARK-17072] [SQL] support table-level statistic...
Posted by gatorsmile <gi...@git.apache.org>.
Github user gatorsmile commented on a diff in the pull request:
https://github.com/apache/spark/pull/14712#discussion_r75515751
--- Diff: sql/core/src/main/scala/org/apache/spark/sql/execution/command/AnalyzeTableCommand.scala ---
@@ -88,14 +90,30 @@ case class AnalyzeTableCommand(tableName: String) extends RunnableCommand {
}
}.getOrElse(0L)
- // Update the Hive metastore if the total size of the table is different than the size
+ val needUpdate = new mutable.HashMap[String, String]()
+ if (newTotalSize > 0 && newTotalSize != oldTotalSize) {
+ needUpdate += (AnalyzeTableCommand.TOTAL_SIZE_FIELD -> newTotalSize.toString)
+ }
+ if (!noscan) {
+ val oldRowCount = tableParameters.get(AnalyzeTableCommand.ROW_COUNT).map(_.toLong)
+ .getOrElse(-1L)
+ val newRowCount = sparkSession.table(tableName).count()
+
+ if (newRowCount >= 0 && newRowCount != oldRowCount) {
+ needUpdate += (AnalyzeTableCommand.ROW_COUNT -> newRowCount.toString)
+ }
+ }
+ // Update the Hive metastore if the above parameters of the table is different than those
// recorded in the Hive metastore.
// This logic is based on org.apache.hadoop.hive.ql.exec.StatsTask.aggregateStats().
- if (newTotalSize > 0 && newTotalSize != oldTotalSize) {
+ if (needUpdate.nonEmpty) {
+ // need to set this parameter so that we can store other parameters like "numRows" into
+ // Hive metastore
+ needUpdate.put(AnalyzeTableCommand.STATS_GENERATED_VIA_STATS_TASK,
--- End diff --
https://issues.apache.org/jira/browse/HIVE-8648 This is the related Hive PR for `STATS_GENERATED_VIA_STATS_TASK`
---
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 infrastructure@apache.org or file a JIRA ticket
with INFRA.
---
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org
[GitHub] spark pull request #14712: [SPARK-17072] [SQL] support table-level statistic...
Posted by gatorsmile <gi...@git.apache.org>.
Github user gatorsmile commented on a diff in the pull request:
https://github.com/apache/spark/pull/14712#discussion_r76921850
--- Diff: sql/core/src/main/scala/org/apache/spark/sql/execution/command/AnalyzeTableCommand.scala ---
@@ -88,15 +116,21 @@ case class AnalyzeTableCommand(tableName: String) extends RunnableCommand {
}
}.getOrElse(0L)
- // Update the Hive metastore if the total size of the table is different than the size
- // recorded in the Hive metastore.
- // This logic is based on org.apache.hadoop.hive.ql.exec.StatsTask.aggregateStats().
- if (newTotalSize > 0 && newTotalSize != oldTotalSize) {
- sessionState.catalog.alterTable(
- catalogTable.copy(
- properties = relation.catalogTable.properties +
- (AnalyzeTableCommand.TOTAL_SIZE_FIELD -> newTotalSize.toString)))
- }
+ updateTableStats(
+ catalogTable,
+ oldTotalSize = catalogTable.catalogStats.map(_.sizeInBytes.toLong).getOrElse(0L),
+ oldRowCount = catalogTable.catalogStats.flatMap(_.rowCount.map(_.toLong)).getOrElse(-1L),
+ newTotalSize = newTotalSize)
+
+ // data source tables have been converted into LogicalRelations
+ case logicalRel: LogicalRelation if logicalRel.metastoreTableIdentifier.isDefined =>
+ val tableIdentifier = logicalRel.metastoreTableIdentifier.get
+ val catalogTable = sessionState.catalog.getTableMetadata(tableIdentifier)
+ updateTableStats(
+ catalogTable,
+ oldTotalSize = logicalRel.statistics.sizeInBytes.toLong,
+ oldRowCount = logicalRel.statistics.rowCount.map(_.toLong).getOrElse(-1L),
+ newTotalSize = logicalRel.relation.sizeInBytes)
case otherRelation =>
throw new AnalysisException(s"ANALYZE TABLE is only supported for Hive tables, " +
--- End diff --
This message is out of dated.
---
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 infrastructure@apache.org or file a JIRA ticket
with INFRA.
---
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org
[GitHub] spark issue #14712: [SPARK-17072] [SQL] support table-level statistics gener...
Posted by cloud-fan <gi...@git.apache.org>.
Github user cloud-fan commented on the issue:
https://github.com/apache/spark/pull/14712
@wzhfy do you know how hive deal with the `STATS_GENERATED_VIA_STATS_TASK` flag and `COLUMN_STATS_ACCURATE` flag?
---
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 infrastructure@apache.org or file a JIRA ticket
with INFRA.
---
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org
[GitHub] spark pull request #14712: [SPARK-17072] [SQL] support table-level statistic...
Posted by wzhfy <gi...@git.apache.org>.
Github user wzhfy commented on a diff in the pull request:
https://github.com/apache/spark/pull/14712#discussion_r75569609
--- Diff: sql/hive/src/main/scala/org/apache/spark/sql/hive/MetastoreRelation.scala ---
@@ -141,7 +142,16 @@ private[hive] case class MetastoreRelation(
sparkSession.sessionState.conf.defaultSizeInBytes
})
}
- )
+ val tableParams = hiveQlTable.getParameters
+ val rowCount = tableParams.get(AnalyzeTableCommand.ROW_COUNT)
+ if (rowCount != null && rowCount.toLong >=0) {
--- End diff --
ok, thx, i'll fix this
---
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 infrastructure@apache.org or file a JIRA ticket
with INFRA.
---
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org
[GitHub] spark pull request #14712: [SPARK-17072] [SQL] support table-level statistic...
Posted by viirya <gi...@git.apache.org>.
Github user viirya commented on a diff in the pull request:
https://github.com/apache/spark/pull/14712#discussion_r76918174
--- Diff: sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/catalog/SessionCatalog.scala ---
@@ -235,14 +235,18 @@ class SessionCatalog(
* Note: If the underlying implementation does not support altering a certain field,
* this becomes a no-op.
*/
- def alterTable(tableDefinition: CatalogTable): Unit = {
+ def alterTable(tableDefinition: CatalogTable, fromAnalyze: Boolean = false): Unit = {
--- End diff --
The additional flag parameter `fromAnalyze` looks weird for me. Why would we need to have two APIs for alter table and use a flag like this to choose among them?
---
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 infrastructure@apache.org or file a JIRA ticket
with INFRA.
---
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org
[GitHub] spark pull request #14712: [SPARK-17072] [SQL] support table-level statistic...
Posted by hvanhovell <gi...@git.apache.org>.
Github user hvanhovell commented on a diff in the pull request:
https://github.com/apache/spark/pull/14712#discussion_r76533896
--- Diff: sql/hive/src/main/scala/org/apache/spark/sql/hive/HiveExternalCatalog.scala ---
@@ -401,6 +401,13 @@ private[spark] class HiveExternalCatalog(conf: SparkConf, hadoopConf: Configurat
}
}
+ override def alterTableStats(tableDefinition: CatalogTable): Unit = withClient {
--- End diff --
See my previous comment. Lets first get this right on the Spark SQL side, and then work towards Hive compatibility.
---
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 infrastructure@apache.org or file a JIRA ticket
with INFRA.
---
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org
[GitHub] spark pull request #14712: [SPARK-17072] [SQL] support table-level statistic...
Posted by viirya <gi...@git.apache.org>.
Github user viirya commented on a diff in the pull request:
https://github.com/apache/spark/pull/14712#discussion_r75571686
--- Diff: sql/core/src/main/scala/org/apache/spark/sql/execution/command/AnalyzeTableCommand.scala ---
@@ -88,14 +90,30 @@ case class AnalyzeTableCommand(tableName: String) extends RunnableCommand {
}
}.getOrElse(0L)
- // Update the Hive metastore if the total size of the table is different than the size
+ val needUpdate = new mutable.HashMap[String, String]()
+ if (newTotalSize > 0 && newTotalSize != oldTotalSize) {
+ needUpdate += (AnalyzeTableCommand.TOTAL_SIZE_FIELD -> newTotalSize.toString)
+ }
+ if (!noscan) {
+ val oldRowCount = tableParameters.get(AnalyzeTableCommand.ROW_COUNT).map(_.toLong)
+ .getOrElse(-1L)
+ val newRowCount = sparkSession.table(tableName).count()
+
+ if (newRowCount >= 0 && newRowCount != oldRowCount) {
+ needUpdate += (AnalyzeTableCommand.ROW_COUNT -> newRowCount.toString)
+ }
+ }
+ // Update the Hive metastore if the above parameters of the table is different than those
// recorded in the Hive metastore.
// This logic is based on org.apache.hadoop.hive.ql.exec.StatsTask.aggregateStats().
- if (newTotalSize > 0 && newTotalSize != oldTotalSize) {
+ if (needUpdate.nonEmpty) {
+ // need to set this parameter so that we can store other parameters like "numRows" into
+ // Hive metastore
+ needUpdate.put(AnalyzeTableCommand.STATS_GENERATED_VIA_STATS_TASK,
--- End diff --
The code comment can be improved a little. Above comment looks better than the one in current code change.
---
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 infrastructure@apache.org or file a JIRA ticket
with INFRA.
---
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org
[GitHub] spark issue #14712: [SPARK-17072] [SQL] support table-level statistics gener...
Posted by wzhfy <gi...@git.apache.org>.
Github user wzhfy commented on the issue:
https://github.com/apache/spark/pull/14712
@cloud-fan @hvanhovell @gatorsmile Please review again, thanks!
---
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 infrastructure@apache.org or file a JIRA ticket
with INFRA.
---
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org
[GitHub] spark issue #14712: [SPARK-17072] [SQL] support table-level statistics gener...
Posted by cloud-fan <gi...@git.apache.org>.
Github user cloud-fan commented on the issue:
https://github.com/apache/spark/pull/14712
@gatorsmial, do you mean `COLUMN_STATS_ACCURATE` exists in any table's properties?
---
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 infrastructure@apache.org or file a JIRA ticket
with INFRA.
---
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org
[GitHub] spark issue #14712: [SPARK-17072] [SQL] support table-level statistics gener...
Posted by SparkQA <gi...@git.apache.org>.
Github user SparkQA commented on the issue:
https://github.com/apache/spark/pull/14712
**[Test build #64625 has started](https://amplab.cs.berkeley.edu/jenkins/job/SparkPullRequestBuilder/64625/consoleFull)** for PR 14712 at commit [`9c27071`](https://github.com/apache/spark/commit/9c27071c05da5f285726381dff7eff3dfab7eda9).
---
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 infrastructure@apache.org or file a JIRA ticket
with INFRA.
---
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org
[GitHub] spark issue #14712: [SPARK-17072] [SQL] support table-level statistics gener...
Posted by AmplabJenkins <gi...@git.apache.org>.
Github user AmplabJenkins commented on the issue:
https://github.com/apache/spark/pull/14712
Can one of the admins verify this patch?
---
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 infrastructure@apache.org or file a JIRA ticket
with INFRA.
---
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org
[GitHub] spark pull request #14712: [SPARK-17072] [SQL] support table-level statistic...
Posted by hvanhovell <gi...@git.apache.org>.
Github user hvanhovell commented on a diff in the pull request:
https://github.com/apache/spark/pull/14712#discussion_r76248746
--- Diff: sql/core/src/main/scala/org/apache/spark/sql/execution/command/AnalyzeTableCommand.scala ---
@@ -88,14 +89,70 @@ case class AnalyzeTableCommand(tableName: String) extends RunnableCommand {
}
}.getOrElse(0L)
- // Update the Hive metastore if the total size of the table is different than the size
- // recorded in the Hive metastore.
- // This logic is based on org.apache.hadoop.hive.ql.exec.StatsTask.aggregateStats().
- if (newTotalSize > 0 && newTotalSize != oldTotalSize) {
+ var needUpdate = false
+ val totalSize = if (newTotalSize > 0 && newTotalSize != oldTotalSize) {
+ needUpdate = true
+ newTotalSize
+ } else {
+ oldTotalSize
+ }
+ var numRows: Option[BigInt] = None
+ if (!noscan) {
+ val oldRowCount: Long = if (catalogTable.catalogStats.isDefined) {
+ catalogTable.catalogStats.get.rowCount.map(_.toLong).getOrElse(-1L)
+ } else {
+ -1L
+ }
+ val newRowCount = sparkSession.table(tableName).count()
+ if (newRowCount >= 0 && newRowCount != oldRowCount) {
--- End diff --
`newRowCount` can be 0 right? What is the reason to keep the old statistic if the table is empty?
---
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 infrastructure@apache.org or file a JIRA ticket
with INFRA.
---
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org
[GitHub] spark pull request #14712: [SPARK-17072] [SQL] support table-level statistic...
Posted by hvanhovell <gi...@git.apache.org>.
Github user hvanhovell commented on a diff in the pull request:
https://github.com/apache/spark/pull/14712#discussion_r75515983
--- Diff: sql/core/src/main/scala/org/apache/spark/sql/execution/command/AnalyzeTableCommand.scala ---
@@ -88,14 +90,30 @@ case class AnalyzeTableCommand(tableName: String) extends RunnableCommand {
}
}.getOrElse(0L)
- // Update the Hive metastore if the total size of the table is different than the size
+ val needUpdate = new mutable.HashMap[String, String]()
+ if (newTotalSize > 0 && newTotalSize != oldTotalSize) {
+ needUpdate += (AnalyzeTableCommand.TOTAL_SIZE_FIELD -> newTotalSize.toString)
+ }
+ if (!noscan) {
+ val oldRowCount = tableParameters.get(AnalyzeTableCommand.ROW_COUNT).map(_.toLong)
+ .getOrElse(-1L)
+ val newRowCount = sparkSession.table(tableName).count()
+
+ if (newRowCount >= 0 && newRowCount != oldRowCount) {
+ needUpdate += (AnalyzeTableCommand.ROW_COUNT -> newRowCount.toString)
+ }
+ }
+ // Update the Hive metastore if the above parameters of the table is different than those
// recorded in the Hive metastore.
// This logic is based on org.apache.hadoop.hive.ql.exec.StatsTask.aggregateStats().
- if (newTotalSize > 0 && newTotalSize != oldTotalSize) {
+ if (needUpdate.nonEmpty) {
+ // need to set this parameter so that we can store other parameters like "numRows" into
+ // Hive metastore
+ needUpdate.put(AnalyzeTableCommand.STATS_GENERATED_VIA_STATS_TASK,
+ AnalyzeTableCommand.TRUE)
sessionState.catalog.alterTable(
catalogTable.copy(
- properties = relation.catalogTable.properties +
- (AnalyzeTableCommand.TOTAL_SIZE_FIELD -> newTotalSize.toString)))
+ properties = relation.catalogTable.properties ++ needUpdate))
--- End diff --
Yeah, we would. It is just a property. Exposing this also has the benefit that we have another way of providing statistics. We could, for instance, piggy back statistics collection on top of a full table scan.
---
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 infrastructure@apache.org or file a JIRA ticket
with INFRA.
---
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org
[GitHub] spark pull request #14712: [SPARK-17072] [SQL] support table-level statistic...
Posted by gatorsmile <gi...@git.apache.org>.
Github user gatorsmile commented on a diff in the pull request:
https://github.com/apache/spark/pull/14712#discussion_r75516944
--- Diff: sql/core/src/main/scala/org/apache/spark/sql/execution/command/AnalyzeTableCommand.scala ---
@@ -88,14 +90,30 @@ case class AnalyzeTableCommand(tableName: String) extends RunnableCommand {
}
}.getOrElse(0L)
- // Update the Hive metastore if the total size of the table is different than the size
+ val needUpdate = new mutable.HashMap[String, String]()
+ if (newTotalSize > 0 && newTotalSize != oldTotalSize) {
+ needUpdate += (AnalyzeTableCommand.TOTAL_SIZE_FIELD -> newTotalSize.toString)
+ }
+ if (!noscan) {
+ val oldRowCount = tableParameters.get(AnalyzeTableCommand.ROW_COUNT).map(_.toLong)
+ .getOrElse(-1L)
+ val newRowCount = sparkSession.table(tableName).count()
+
+ if (newRowCount >= 0 && newRowCount != oldRowCount) {
+ needUpdate += (AnalyzeTableCommand.ROW_COUNT -> newRowCount.toString)
+ }
+ }
+ // Update the Hive metastore if the above parameters of the table is different than those
// recorded in the Hive metastore.
// This logic is based on org.apache.hadoop.hive.ql.exec.StatsTask.aggregateStats().
- if (newTotalSize > 0 && newTotalSize != oldTotalSize) {
+ if (needUpdate.nonEmpty) {
+ // need to set this parameter so that we can store other parameters like "numRows" into
+ // Hive metastore
+ needUpdate.put(AnalyzeTableCommand.STATS_GENERATED_VIA_STATS_TASK,
+ AnalyzeTableCommand.TRUE)
sessionState.catalog.alterTable(
catalogTable.copy(
- properties = relation.catalogTable.properties +
- (AnalyzeTableCommand.TOTAL_SIZE_FIELD -> newTotalSize.toString)))
+ properties = relation.catalogTable.properties ++ needUpdate))
--- End diff --
If the external users update these statistics using `ALTER TABLE` commands, we will set `STATS_GENERATED_VIA_STATS_TASK` to `false`? Then, do you know how Hive is using this flag?
---
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 infrastructure@apache.org or file a JIRA ticket
with INFRA.
---
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org
[GitHub] spark pull request #14712: [SPARK-17072] [SQL] support table-level statistic...
Posted by gatorsmile <gi...@git.apache.org>.
Github user gatorsmile commented on a diff in the pull request:
https://github.com/apache/spark/pull/14712#discussion_r76923392
--- Diff: sql/core/src/main/scala/org/apache/spark/sql/execution/command/AnalyzeTableCommand.scala ---
@@ -21,25 +21,55 @@ import scala.util.control.NonFatal
import org.apache.hadoop.fs.{FileSystem, Path}
-import org.apache.spark.sql.{AnalysisException, Row, SparkSession}
+import org.apache.spark.sql.{AnalysisException, Dataset, Row, SparkSession}
import org.apache.spark.sql.catalyst.analysis.EliminateSubqueryAliases
import org.apache.spark.sql.catalyst.catalog.{CatalogRelation, CatalogTable}
+import org.apache.spark.sql.catalyst.plans.logical.Statistics
+import org.apache.spark.sql.execution.datasources.LogicalRelation
/**
* Analyzes the given table in the current database to generate statistics, which will be
* used in query optimizations.
- *
- * Right now, it only supports Hive tables and it only updates the size of a Hive table
- * in the Hive metastore.
*/
-case class AnalyzeTableCommand(tableName: String) extends RunnableCommand {
+case class AnalyzeTableCommand(tableName: String, noscan: Boolean = true) extends RunnableCommand {
override def run(sparkSession: SparkSession): Seq[Row] = {
val sessionState = sparkSession.sessionState
val tableIdent = sessionState.sqlParser.parseTableIdentifier(tableName)
val relation = EliminateSubqueryAliases(sessionState.catalog.lookupRelation(tableIdent))
+ def updateTableStats(
--- End diff --
uh, this function interrupts the whole flow. Maybe you can move it out of this run function?
---
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 infrastructure@apache.org or file a JIRA ticket
with INFRA.
---
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org
[GitHub] spark issue #14712: [SPARK-17072] [SQL] support table-level statistics gener...
Posted by SparkQA <gi...@git.apache.org>.
Github user SparkQA commented on the issue:
https://github.com/apache/spark/pull/14712
**[Test build #64726 has started](https://amplab.cs.berkeley.edu/jenkins/job/SparkPullRequestBuilder/64726/consoleFull)** for PR 14712 at commit [`9715770`](https://github.com/apache/spark/commit/971577086ff4a61824034f7f04b4eba0f6de7e95).
---
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 infrastructure@apache.org or file a JIRA ticket
with INFRA.
---
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org
[GitHub] spark issue #14712: [SPARK-17072] [SQL] support table-level statistics gener...
Posted by wzhfy <gi...@git.apache.org>.
Github user wzhfy commented on the issue:
https://github.com/apache/spark/pull/14712
@cloud-fan did you see the [comment](https://github.com/apache/spark/pull/14712#discussion_r75540560) by @gatorsmile ?
---
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 infrastructure@apache.org or file a JIRA ticket
with INFRA.
---
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org
[GitHub] spark pull request #14712: [SPARK-17072] [SQL] support table-level statistic...
Posted by wzhfy <gi...@git.apache.org>.
Github user wzhfy commented on a diff in the pull request:
https://github.com/apache/spark/pull/14712#discussion_r76921588
--- Diff: sql/hive/src/test/scala/org/apache/spark/sql/hive/StatisticsSuite.scala ---
@@ -168,6 +169,81 @@ class StatisticsSuite extends QueryTest with TestHiveSingleton with SQLTestUtils
TableIdentifier("tempTable"), ignoreIfNotExists = true, purge = false)
}
+ private def checkMetastoreRelationStats(
+ tableName: String,
+ totalSize: Long,
+ rowCount: Option[BigInt]): Unit = {
+ val df = sql(s"SELECT * FROM $tableName")
+ val relations = df.queryExecution.analyzed.collect { case rel: MetastoreRelation =>
+ rel.statistics
+ assert(rel.statistics.sizeInBytes === totalSize)
+ assert(rel.statistics.rowCount === rowCount)
+ }
+ assert(relations.size === 1)
+ }
+
+ private def checkLogicalRelationStats(tableName: String, rowCount: Option[BigInt]): Unit = {
+ val df = sql(s"SELECT * FROM $tableName")
+ val relations = df.queryExecution.analyzed.collect { case rel: LogicalRelation =>
+ assert(rel.statistics.sizeInBytes === rel.relation.sizeInBytes)
--- End diff --
seems that parquet size is different in Windows and Linux. I set an expected value initially, it worked on Windows but it went wrong in Spark CI.
---
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 infrastructure@apache.org or file a JIRA ticket
with INFRA.
---
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org
[GitHub] spark pull request #14712: [SPARK-17072] [SQL] support table-level statistic...
Posted by wzhfy <gi...@git.apache.org>.
Github user wzhfy commented on a diff in the pull request:
https://github.com/apache/spark/pull/14712#discussion_r75573442
--- Diff: sql/core/src/main/scala/org/apache/spark/sql/execution/datasources/LogicalRelation.scala ---
@@ -72,9 +72,12 @@ case class LogicalRelation(
// expId can be different but the relation is still the same.
override lazy val cleanArgs: Seq[Any] = Seq(relation)
- @transient override lazy val statistics: Statistics = Statistics(
- sizeInBytes = BigInt(relation.sizeInBytes)
- )
+ // statistics inherited from a MetastoreRelation
+ @transient var inheritedStats: Option[Statistics] = None
--- End diff --
Can you explain more about this comment? By "block it", do you mean don't compute stats for In-memory cataloged tables? Do they correspond to InMemoryRelation?
---
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 infrastructure@apache.org or file a JIRA ticket
with INFRA.
---
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org
[GitHub] spark pull request #14712: [SPARK-17072] [SQL] support table-level statistic...
Posted by gatorsmile <gi...@git.apache.org>.
Github user gatorsmile commented on a diff in the pull request:
https://github.com/apache/spark/pull/14712#discussion_r76921020
--- Diff: sql/hive/src/test/scala/org/apache/spark/sql/hive/StatisticsSuite.scala ---
@@ -168,6 +169,81 @@ class StatisticsSuite extends QueryTest with TestHiveSingleton with SQLTestUtils
TableIdentifier("tempTable"), ignoreIfNotExists = true, purge = false)
}
+ private def checkMetastoreRelationStats(
+ tableName: String,
+ totalSize: Long,
+ rowCount: Option[BigInt]): Unit = {
+ val df = sql(s"SELECT * FROM $tableName")
+ val relations = df.queryExecution.analyzed.collect { case rel: MetastoreRelation =>
+ rel.statistics
+ assert(rel.statistics.sizeInBytes === totalSize)
+ assert(rel.statistics.rowCount === rowCount)
+ }
+ assert(relations.size === 1)
+ }
+
+ private def checkLogicalRelationStats(tableName: String, rowCount: Option[BigInt]): Unit = {
+ val df = sql(s"SELECT * FROM $tableName")
+ val relations = df.queryExecution.analyzed.collect { case rel: LogicalRelation =>
+ assert(rel.statistics.sizeInBytes === rel.relation.sizeInBytes)
--- End diff --
Can you put a comment to explain why you just compare these two values, instead of comparing them with the expected values?
---
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 infrastructure@apache.org or file a JIRA ticket
with INFRA.
---
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org
[GitHub] spark pull request #14712: [SPARK-17072] [SQL] support table-level statistic...
Posted by gatorsmile <gi...@git.apache.org>.
Github user gatorsmile commented on a diff in the pull request:
https://github.com/apache/spark/pull/14712#discussion_r76920817
--- Diff: sql/hive/src/test/scala/org/apache/spark/sql/hive/StatisticsSuite.scala ---
@@ -168,6 +169,81 @@ class StatisticsSuite extends QueryTest with TestHiveSingleton with SQLTestUtils
TableIdentifier("tempTable"), ignoreIfNotExists = true, purge = false)
}
+ private def checkMetastoreRelationStats(
+ tableName: String,
+ totalSize: Long,
+ rowCount: Option[BigInt]): Unit = {
+ val df = sql(s"SELECT * FROM $tableName")
+ val relations = df.queryExecution.analyzed.collect { case rel: MetastoreRelation =>
+ rel.statistics
+ assert(rel.statistics.sizeInBytes === totalSize)
+ assert(rel.statistics.rowCount === rowCount)
+ }
+ assert(relations.size === 1)
+ }
+
+ private def checkLogicalRelationStats(tableName: String, rowCount: Option[BigInt]): Unit = {
+ val df = sql(s"SELECT * FROM $tableName")
+ val relations = df.queryExecution.analyzed.collect { case rel: LogicalRelation =>
+ assert(rel.statistics.sizeInBytes === rel.relation.sizeInBytes)
+ assert(rel.statistics.rowCount === rowCount)
+ }
+ assert(relations.size === 1)
+ }
+
+ test("test table-level statistics for hive tables created in HiveExternalCatalog") {
+ val textTable = "textTable"
+ val parquetTable = "parquetTable"
+ val orcTable = "orcTable"
+ withTable(textTable, parquetTable, orcTable) {
+ sql(s"CREATE TABLE $textTable (key STRING, value STRING) STORED AS TEXTFILE")
+ sql(s"INSERT INTO TABLE $textTable SELECT * FROM src")
+
+ // noscan won't count the number of rows
+ sql(s"ANALYZE TABLE $textTable COMPUTE STATISTICS noscan")
+ checkMetastoreRelationStats(textTable, 5812, None)
+
+ // without noscan, we count the number of rows
+ sql(s"ANALYZE TABLE $textTable COMPUTE STATISTICS")
+ checkMetastoreRelationStats(textTable, 5812, Some(500))
+
+ // test whether the old stats are removed
+ sql(s"INSERT INTO TABLE $textTable SELECT * FROM src")
+ sql(s"ANALYZE TABLE $textTable COMPUTE STATISTICS noscan")
+ checkMetastoreRelationStats(textTable, 11624, None)
+
+ // test statistics of LogicalRelation inherited from MetastoreRelation
+ 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")
+ sql(s"ANALYZE TABLE $parquetTable COMPUTE STATISTICS")
+ sql(s"ANALYZE TABLE $orcTable COMPUTE STATISTICS")
+
+ checkLogicalRelationStats(parquetTable, Some(500))
+
+ withSQLConf("spark.sql.hive.convertMetastoreOrc" -> "true") {
+ checkLogicalRelationStats(orcTable, Some(500))
+ }
+ }
+ }
+
+ test("test table-level statistics for data source table created in HiveExternalCatalog") {
+ val parquetTable = "parquetTable"
+ withTable(parquetTable) {
+ sql(s"CREATE TABLE $parquetTable (key STRING, value STRING) USING PARQUET")
--- End diff --
Maybe you can check its `CatalogTable` and confirm it is a datasource table thought `DDLUtils.isDatasourceTable(table)`
---
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 infrastructure@apache.org or file a JIRA ticket
with INFRA.
---
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org
[GitHub] spark issue #14712: [SPARK-17072] [SQL] support table-level statistics gener...
Posted by wzhfy <gi...@git.apache.org>.
Github user wzhfy commented on the issue:
https://github.com/apache/spark/pull/14712
@gatorsmile yes, we will support it in this pr
---
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 infrastructure@apache.org or file a JIRA ticket
with INFRA.
---
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org
[GitHub] spark issue #14712: [SPARK-17072] [SQL] support table-level statistics gener...
Posted by cloud-fan <gi...@git.apache.org>.
Github user cloud-fan commented on the issue:
https://github.com/apache/spark/pull/14712
Ok let's focus on this PR. You use the same table property names of Hive for the new statistics, then what if they are changed by Hive unexpectedly? Are they supported by all versions of Hive?
I think it's good to not mix the target 1 and 2 mentioned in my last comment together, and what do you think about my proposal in https://github.com/apache/spark/pull/14712#issuecomment-241207069? We can hide the hive-compatible logic in `HiveExternalCatalog`, so that `InMemoryCatalog` can support it too.
BTW in the view of API, `InMemoryCatalog` is also a persistent level, table statistics should also work in `InMemoryCatalog`.
> Of course we can put everything into properties, but it's not elegant.
But sometimes we have to, like data source table metadata. I think it's ok if we can hide the logic in `HiveExternalCatalog`.
---
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 infrastructure@apache.org or file a JIRA ticket
with INFRA.
---
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org
[GitHub] spark issue #14712: [SPARK-17072] [SQL] support table-level statistics gener...
Posted by AmplabJenkins <gi...@git.apache.org>.
Github user AmplabJenkins commented on the issue:
https://github.com/apache/spark/pull/14712
Merged build finished. Test FAILed.
---
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 infrastructure@apache.org or file a JIRA ticket
with INFRA.
---
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org
[GitHub] spark pull request #14712: [SPARK-17072] [SQL] support table-level statistic...
Posted by cloud-fan <gi...@git.apache.org>.
Github user cloud-fan commented on a diff in the pull request:
https://github.com/apache/spark/pull/14712#discussion_r77113222
--- Diff: sql/core/src/main/scala/org/apache/spark/sql/execution/command/AnalyzeTableCommand.scala ---
@@ -88,24 +85,53 @@ case class AnalyzeTableCommand(tableName: String) extends RunnableCommand {
}
}.getOrElse(0L)
- // Update the Hive metastore if the total size of the table is different than the size
- // recorded in the Hive metastore.
- // This logic is based on org.apache.hadoop.hive.ql.exec.StatsTask.aggregateStats().
- if (newTotalSize > 0 && newTotalSize != oldTotalSize) {
- sessionState.catalog.alterTable(
- catalogTable.copy(
- properties = relation.catalogTable.properties +
- (AnalyzeTableCommand.TOTAL_SIZE_FIELD -> newTotalSize.toString)))
- }
+ updateTableStats(
+ catalogTable,
+ oldTotalSize = catalogTable.stats.map(_.sizeInBytes.toLong).getOrElse(0L),
+ oldRowCount = catalogTable.stats.flatMap(_.rowCount.map(_.toLong)).getOrElse(-1L),
+ newTotalSize = newTotalSize)
+
+ // data source tables have been converted into LogicalRelations
+ case logicalRel: LogicalRelation if logicalRel.catalogTable.isDefined =>
+ updateTableStats(
+ logicalRel.catalogTable.get,
+ oldTotalSize = logicalRel.statistics.sizeInBytes.toLong,
+ oldRowCount = logicalRel.statistics.rowCount.map(_.toLong).getOrElse(-1L),
+ newTotalSize = logicalRel.relation.sizeInBytes)
--- End diff --
looks like `logicalRel.relation.sizeInBytes` is always equal to `logicalRel.statistics.sizeInBytes.toLong`?
```
@transient override lazy val statistics: Statistics = {
catalogTable.flatMap(_.stats.map(_.copy(sizeInBytes = relation.sizeInBytes))).getOrElse(
Statistics(sizeInBytes = relation.sizeInBytes))
}
```
---
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 infrastructure@apache.org or file a JIRA ticket
with INFRA.
---
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org
[GitHub] spark issue #14712: [SPARK-17072] [SQL] support table-level statistics gener...
Posted by wzhfy <gi...@git.apache.org>.
Github user wzhfy commented on the issue:
https://github.com/apache/spark/pull/14712
> What if we use different property names to store statistics?
this may cause some consistency issues when both names exist in the metastore, we can't tell which one is the latest.
---
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 infrastructure@apache.org or file a JIRA ticket
with INFRA.
---
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org
[GitHub] spark issue #14712: [SPARK-17072] [SQL] support table-level statistics gener...
Posted by SparkQA <gi...@git.apache.org>.
Github user SparkQA commented on the issue:
https://github.com/apache/spark/pull/14712
**[Test build #64709 has started](https://amplab.cs.berkeley.edu/jenkins/job/SparkPullRequestBuilder/64709/consoleFull)** for PR 14712 at commit [`c7cc55f`](https://github.com/apache/spark/commit/c7cc55fe2a42f5af3ffd2c9a81f58a608b636320).
---
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 infrastructure@apache.org or file a JIRA ticket
with INFRA.
---
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org
[GitHub] spark pull request #14712: [SPARK-17072] [SQL] support table-level statistic...
Posted by hvanhovell <gi...@git.apache.org>.
Github user hvanhovell commented on a diff in the pull request:
https://github.com/apache/spark/pull/14712#discussion_r75502235
--- Diff: sql/core/src/main/scala/org/apache/spark/sql/execution/command/AnalyzeTableCommand.scala ---
@@ -33,7 +34,7 @@ import org.apache.spark.sql.catalyst.catalog.{CatalogRelation, CatalogTable}
* Right now, it only supports Hive tables and it only updates the size of a Hive table
* in the Hive metastore.
*/
-case class AnalyzeTableCommand(tableName: String) extends RunnableCommand {
+case class AnalyzeTableCommand(tableName: String, noscan: Boolean = true) extends RunnableCommand {
--- End diff --
Collecting statistics has a cost, so you would normally do this every once in a while, and not on every change to your data. The underlying idea is that the distribution of data typically doesn't change to much.
If we were to store the input statistics aggregation buffers somewhere, you could actually update statistics easily after an insert (you only need to scan the inserted data).
---
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 infrastructure@apache.org or file a JIRA ticket
with INFRA.
---
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org
[GitHub] spark pull request #14712: [SPARK-17072] [SQL] support table-level statistic...
Posted by hvanhovell <gi...@git.apache.org>.
Github user hvanhovell commented on a diff in the pull request:
https://github.com/apache/spark/pull/14712#discussion_r76533586
--- Diff: sql/core/src/main/scala/org/apache/spark/sql/execution/command/AnalyzeTableCommand.scala ---
@@ -88,14 +87,66 @@ case class AnalyzeTableCommand(tableName: String) extends RunnableCommand {
}
}.getOrElse(0L)
- // Update the Hive metastore if the total size of the table is different than the size
- // recorded in the Hive metastore.
- // This logic is based on org.apache.hadoop.hive.ql.exec.StatsTask.aggregateStats().
- if (newTotalSize > 0 && newTotalSize != oldTotalSize) {
+ var needUpdate = false
+ val totalSize = if (newTotalSize > 0 && newTotalSize != oldTotalSize) {
+ needUpdate = true
+ newTotalSize
+ } else {
+ oldTotalSize
+ }
+ var numRows: Option[BigInt] = None
+ if (!noscan) {
+ val oldRowCount = catalogStats.flatMap(_.rowCount.map(_.toLong)).getOrElse(-1L)
+ val newRowCount = sparkSession.table(tableName).count()
--- End diff --
We can also use the passed plan, and skip a lookup in the spark session. `Dataset.ofRows(sparkSession, relation).count`
---
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 infrastructure@apache.org or file a JIRA ticket
with INFRA.
---
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org
[GitHub] spark issue #14712: [SPARK-17072] [SQL] support table-level statistics gener...
Posted by hvanhovell <gi...@git.apache.org>.
Github user hvanhovell commented on the issue:
https://github.com/apache/spark/pull/14712
@gatorsmile lets also create another ticket for the explicit statistics updates. I do like the `alter table s update statistics set ...` option.
---
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 infrastructure@apache.org or file a JIRA ticket
with INFRA.
---
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org
[GitHub] spark pull request #14712: [SPARK-17072] [SQL] support table-level statistic...
Posted by gatorsmile <gi...@git.apache.org>.
Github user gatorsmile commented on a diff in the pull request:
https://github.com/apache/spark/pull/14712#discussion_r77124744
--- Diff: sql/core/src/main/scala/org/apache/spark/sql/catalyst/SQLBuilder.scala ---
@@ -590,8 +590,12 @@ class SQLBuilder private (
object ExtractSQLTable {
def unapply(plan: LogicalPlan): Option[SQLTable] = plan match {
- case l @ LogicalRelation(_, _, Some(TableIdentifier(table, Some(database)))) =>
- Some(SQLTable(database, table, l.output.map(_.withQualifier(None))))
+ case l @ LogicalRelation(_, _, Some(catalogTable))
+ if catalogTable.identifier.database.isDefined =>
--- End diff --
please add two more space before `if`
---
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 infrastructure@apache.org or file a JIRA ticket
with INFRA.
---
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org
[GitHub] spark pull request #14712: [SPARK-17072] [SQL] support table-level statistic...
Posted by hvanhovell <gi...@git.apache.org>.
Github user hvanhovell commented on a diff in the pull request:
https://github.com/apache/spark/pull/14712#discussion_r75524484
--- Diff: sql/core/src/main/scala/org/apache/spark/sql/execution/command/AnalyzeTableCommand.scala ---
@@ -88,14 +90,30 @@ case class AnalyzeTableCommand(tableName: String) extends RunnableCommand {
}
}.getOrElse(0L)
- // Update the Hive metastore if the total size of the table is different than the size
+ val needUpdate = new mutable.HashMap[String, String]()
+ if (newTotalSize > 0 && newTotalSize != oldTotalSize) {
+ needUpdate += (AnalyzeTableCommand.TOTAL_SIZE_FIELD -> newTotalSize.toString)
+ }
+ if (!noscan) {
+ val oldRowCount = tableParameters.get(AnalyzeTableCommand.ROW_COUNT).map(_.toLong)
+ .getOrElse(-1L)
+ val newRowCount = sparkSession.table(tableName).count()
+
+ if (newRowCount >= 0 && newRowCount != oldRowCount) {
+ needUpdate += (AnalyzeTableCommand.ROW_COUNT -> newRowCount.toString)
+ }
+ }
+ // Update the Hive metastore if the above parameters of the table is different than those
// recorded in the Hive metastore.
// This logic is based on org.apache.hadoop.hive.ql.exec.StatsTask.aggregateStats().
- if (newTotalSize > 0 && newTotalSize != oldTotalSize) {
+ if (needUpdate.nonEmpty) {
+ // need to set this parameter so that we can store other parameters like "numRows" into
+ // Hive metastore
+ needUpdate.put(AnalyzeTableCommand.STATS_GENERATED_VIA_STATS_TASK,
+ AnalyzeTableCommand.TRUE)
sessionState.catalog.alterTable(
catalogTable.copy(
- properties = relation.catalogTable.properties +
- (AnalyzeTableCommand.TOTAL_SIZE_FIELD -> newTotalSize.toString)))
+ properties = relation.catalogTable.properties ++ needUpdate))
--- End diff --
I do not know how Hive is using this. I just like being able to set statistics myself (with another tool).
---
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 infrastructure@apache.org or file a JIRA ticket
with INFRA.
---
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org
[GitHub] spark issue #14712: [SPARK-17072] [SQL] support table-level statistics gener...
Posted by hvanhovell <gi...@git.apache.org>.
Github user hvanhovell commented on the issue:
https://github.com/apache/spark/pull/14712
LGTM. Merging to master. Thanks!
---
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 infrastructure@apache.org or file a JIRA ticket
with INFRA.
---
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org
[GitHub] spark pull request #14712: [SPARK-17072] [SQL] support table-level statistic...
Posted by gatorsmile <gi...@git.apache.org>.
Github user gatorsmile commented on a diff in the pull request:
https://github.com/apache/spark/pull/14712#discussion_r75512379
--- Diff: sql/core/src/main/scala/org/apache/spark/sql/execution/command/AnalyzeTableCommand.scala ---
@@ -88,14 +90,30 @@ case class AnalyzeTableCommand(tableName: String) extends RunnableCommand {
}
}.getOrElse(0L)
- // Update the Hive metastore if the total size of the table is different than the size
+ val needUpdate = new mutable.HashMap[String, String]()
+ if (newTotalSize > 0 && newTotalSize != oldTotalSize) {
+ needUpdate += (AnalyzeTableCommand.TOTAL_SIZE_FIELD -> newTotalSize.toString)
+ }
+ if (!noscan) {
+ val oldRowCount = tableParameters.get(AnalyzeTableCommand.ROW_COUNT).map(_.toLong)
+ .getOrElse(-1L)
+ val newRowCount = sparkSession.table(tableName).count()
+
+ if (newRowCount >= 0 && newRowCount != oldRowCount) {
+ needUpdate += (AnalyzeTableCommand.ROW_COUNT -> newRowCount.toString)
+ }
+ }
+ // Update the Hive metastore if the above parameters of the table is different than those
// recorded in the Hive metastore.
// This logic is based on org.apache.hadoop.hive.ql.exec.StatsTask.aggregateStats().
- if (newTotalSize > 0 && newTotalSize != oldTotalSize) {
+ if (needUpdate.nonEmpty) {
+ // need to set this parameter so that we can store other parameters like "numRows" into
+ // Hive metastore
+ needUpdate.put(AnalyzeTableCommand.STATS_GENERATED_VIA_STATS_TASK,
+ AnalyzeTableCommand.TRUE)
sessionState.catalog.alterTable(
catalogTable.copy(
- properties = relation.catalogTable.properties +
- (AnalyzeTableCommand.TOTAL_SIZE_FIELD -> newTotalSize.toString)))
+ properties = relation.catalogTable.properties ++ needUpdate))
--- End diff --
Do we allow external users to update these attributes using `ATLER TABLE` commands?
---
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 infrastructure@apache.org or file a JIRA ticket
with INFRA.
---
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org
[GitHub] spark issue #14712: [SPARK-17072] [SQL] support table-level statistics gener...
Posted by gatorsmile <gi...@git.apache.org>.
Github user gatorsmile commented on the issue:
https://github.com/apache/spark/pull/14712
Very recently, Hive 2.0.0 fixed a serious bug. See the JIRA: https://issues.apache.org/jira/browse/HIVE-12661
We can get a wrong result when the statistics are out of dated (i.e., wrong). I can easily reproduce it.
Hive made a few changes in `COLUMN_STATS_ACCURATE`. Before Hive 2.0.0, it is like
```
COLUMN_STATS_ACCURATE true
```
After the fix, this becomes different.
```
COLUMN_STATS_ACCURATE {"COLUMN_STATS":{"key":"true","value":"true"},"BASIC_STATS":"true"}
```
I start worrying about the statistics value we populate might affect the query results through Hive interface, especially when we set `STATS_GENERATED_VIA_STATS_TASK`.
We are unable to implement a concurrency control between Hive and Spark. If we use the same names, `statistics` is like a shared memory space. Both Hive and Spark can modify it without notice. I have not found the bug, but it sounds risky.
Conceptually, setting `STATS_GENERATED_VIA_STATS_TASK` is wrong. As @wzhfy pointed out, `numRows` is always `-1` if we do not set it. That also indicates `numRows` is not allowed external users to set it, right?
I am not very confident that we can implement a very stable solution for sharing Spark-generated statistics with Hive, since Hive is out of our control. However, Spark should be able to leverage Hive-generated statistics and the statistics we generated in this CBO work.
---
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 infrastructure@apache.org or file a JIRA ticket
with INFRA.
---
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org
[GitHub] spark issue #14712: [SPARK-17072] [SQL] support table-level statistics gener...
Posted by SparkQA <gi...@git.apache.org>.
Github user SparkQA commented on the issue:
https://github.com/apache/spark/pull/14712
**[Test build #64848 has finished](https://amplab.cs.berkeley.edu/jenkins/job/SparkPullRequestBuilder/64848/consoleFull)** for PR 14712 at commit [`b946df0`](https://github.com/apache/spark/commit/b946df0928da061ca67b93d2587c1e258fd5d63b).
* This patch **fails Spark unit tests**.
* This patch merges cleanly.
* This patch adds no public classes.
---
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 infrastructure@apache.org or file a JIRA ticket
with INFRA.
---
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org
[GitHub] spark pull request #14712: [SPARK-17072] [SQL] support table-level statistic...
Posted by wzhfy <gi...@git.apache.org>.
Github user wzhfy commented on a diff in the pull request:
https://github.com/apache/spark/pull/14712#discussion_r77104213
--- Diff: sql/core/src/main/scala/org/apache/spark/sql/execution/datasources/LogicalRelation.scala ---
@@ -33,7 +33,8 @@ import org.apache.spark.util.Utils
case class LogicalRelation(
relation: BaseRelation,
expectedOutputAttributes: Option[Seq[Attribute]] = None,
- metastoreTableIdentifier: Option[TableIdentifier] = None)
+ metastoreTableIdentifier: Option[TableIdentifier] = None,
+ inheritedStats: Option[Statistics] = None)
--- End diff --
@hvanhovell @cloud-fan @gatorsmile Agree. I've updated the code based on this. Tests are passed, please review.
---
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 infrastructure@apache.org or file a JIRA ticket
with INFRA.
---
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org
[GitHub] spark pull request #14712: [SPARK-17072] [SQL] support table-level statistic...
Posted by rxin <gi...@git.apache.org>.
Github user rxin commented on a diff in the pull request:
https://github.com/apache/spark/pull/14712#discussion_r75436746
--- Diff: sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/plans/logical/Statistics.scala ---
@@ -32,5 +32,11 @@ package org.apache.spark.sql.catalyst.plans.logical
* @param sizeInBytes Physical size in bytes. For leaf operators this defaults to 1, otherwise it
* defaults to the product of children's `sizeInBytes`.
* @param isBroadcastable If true, output is small enough to be used in a broadcast join.
+ * @param estimatedSize Estimated size in bytes.
+ * @param rowCount Estimated number of rows.
*/
-case class Statistics(sizeInBytes: BigInt, isBroadcastable: Boolean = false)
+case class Statistics(
+ sizeInBytes: BigInt,
+ isBroadcastable: Boolean = false,
+ var estimatedSize: Option[BigInt] = None,
--- End diff --
can we make these immutable?
---
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 infrastructure@apache.org or file a JIRA ticket
with INFRA.
---
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org
[GitHub] spark pull request #14712: [SPARK-17072] [SQL] support table-level statistic...
Posted by wzhfy <gi...@git.apache.org>.
Github user wzhfy commented on a diff in the pull request:
https://github.com/apache/spark/pull/14712#discussion_r76949035
--- Diff: sql/hive/src/test/scala/org/apache/spark/sql/hive/StatisticsSuite.scala ---
@@ -168,6 +169,81 @@ class StatisticsSuite extends QueryTest with TestHiveSingleton with SQLTestUtils
TableIdentifier("tempTable"), ignoreIfNotExists = true, purge = false)
}
+ private def checkMetastoreRelationStats(
+ tableName: String,
+ totalSize: Long,
+ rowCount: Option[BigInt]): Unit = {
+ val df = sql(s"SELECT * FROM $tableName")
+ val relations = df.queryExecution.analyzed.collect { case rel: MetastoreRelation =>
+ rel.statistics
+ assert(rel.statistics.sizeInBytes === totalSize)
+ assert(rel.statistics.rowCount === rowCount)
+ }
+ assert(relations.size === 1)
+ }
+
+ private def checkLogicalRelationStats(tableName: String, rowCount: Option[BigInt]): Unit = {
+ val df = sql(s"SELECT * FROM $tableName")
+ val relations = df.queryExecution.analyzed.collect { case rel: LogicalRelation =>
+ assert(rel.statistics.sizeInBytes === rel.relation.sizeInBytes)
+ assert(rel.statistics.rowCount === rowCount)
+ }
+ assert(relations.size === 1)
+ }
+
+ test("test table-level statistics for hive tables created in HiveExternalCatalog") {
--- End diff --
Yes, I've split it in the latest code.
---
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 infrastructure@apache.org or file a JIRA ticket
with INFRA.
---
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org
[GitHub] spark pull request #14712: [SPARK-17072] [SQL] support table-level statistic...
Posted by hvanhovell <gi...@git.apache.org>.
Github user hvanhovell commented on a diff in the pull request:
https://github.com/apache/spark/pull/14712#discussion_r76533400
--- Diff: sql/core/src/main/scala/org/apache/spark/sql/execution/command/AnalyzeTableCommand.scala ---
@@ -88,14 +89,70 @@ case class AnalyzeTableCommand(tableName: String) extends RunnableCommand {
}
}.getOrElse(0L)
- // Update the Hive metastore if the total size of the table is different than the size
- // recorded in the Hive metastore.
- // This logic is based on org.apache.hadoop.hive.ql.exec.StatsTask.aggregateStats().
- if (newTotalSize > 0 && newTotalSize != oldTotalSize) {
+ var needUpdate = false
+ val totalSize = if (newTotalSize > 0 && newTotalSize != oldTotalSize) {
+ needUpdate = true
+ newTotalSize
+ } else {
+ oldTotalSize
+ }
+ var numRows: Option[BigInt] = None
+ if (!noscan) {
+ val oldRowCount: Long = if (catalogTable.catalogStats.isDefined) {
+ catalogTable.catalogStats.get.rowCount.map(_.toLong).getOrElse(-1L)
+ } else {
+ -1L
+ }
+ val newRowCount = sparkSession.table(tableName).count()
+ if (newRowCount >= 0 && newRowCount != oldRowCount) {
+ numRows = Some(BigInt(newRowCount))
+ needUpdate = true
+ }
+ }
+ // Update the metastore if the above statistics of the table are different from those
+ // recorded in the metastore.
+ if (needUpdate) {
+ sessionState.catalog.alterTable(
+ catalogTable.copy(
+ catalogStats = Some(Statistics(
+ sizeInBytes = totalSize, rowCount = numRows))),
+ fromAnalyze = true)
+
+ // Refresh the cache of the table in the catalog.
+ sessionState.catalog.refreshTable(tableIdent)
+ }
+
+ // data source tables have been converted into LogicalRelations
+ case logicalRel: LogicalRelation if logicalRel.metastoreTableIdentifier.isDefined =>
--- End diff --
Ok, that is fair. Could you get rid of the duplicated code though?
---
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 infrastructure@apache.org or file a JIRA ticket
with INFRA.
---
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org
[GitHub] spark issue #14712: [SPARK-17072] [SQL] support table-level statistics gener...
Posted by SparkQA <gi...@git.apache.org>.
Github user SparkQA commented on the issue:
https://github.com/apache/spark/pull/14712
**[Test build #64726 has finished](https://amplab.cs.berkeley.edu/jenkins/job/SparkPullRequestBuilder/64726/consoleFull)** for PR 14712 at commit [`9715770`](https://github.com/apache/spark/commit/971577086ff4a61824034f7f04b4eba0f6de7e95).
* This patch passes all tests.
* This patch merges cleanly.
* This patch adds no public classes.
---
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 infrastructure@apache.org or file a JIRA ticket
with INFRA.
---
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org
[GitHub] spark pull request #14712: [SPARK-17072] [SQL] support table-level statistic...
Posted by wzhfy <gi...@git.apache.org>.
Github user wzhfy commented on a diff in the pull request:
https://github.com/apache/spark/pull/14712#discussion_r75569605
--- Diff: sql/core/src/main/scala/org/apache/spark/sql/execution/command/AnalyzeTableCommand.scala ---
@@ -108,4 +126,8 @@ case class AnalyzeTableCommand(tableName: String) extends RunnableCommand {
object AnalyzeTableCommand {
val TOTAL_SIZE_FIELD = "totalSize"
+ // same as org.apache.hadoop.hive.common.StatsSetupConst
+ val ROW_COUNT = "numRows"
+ val STATS_GENERATED_VIA_STATS_TASK = "STATS_GENERATED_VIA_STATS_TASK"
+ val TRUE = "true"
--- End diff --
ok, i'll remove this. I just copied it from StatsSetupConst :)
---
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 infrastructure@apache.org or file a JIRA ticket
with INFRA.
---
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org
[GitHub] spark pull request #14712: [SPARK-17072] [SQL] support table-level statistic...
Posted by gatorsmile <gi...@git.apache.org>.
Github user gatorsmile commented on a diff in the pull request:
https://github.com/apache/spark/pull/14712#discussion_r76923549
--- Diff: sql/core/src/main/scala/org/apache/spark/sql/execution/command/AnalyzeTableCommand.scala ---
@@ -21,25 +21,55 @@ import scala.util.control.NonFatal
import org.apache.hadoop.fs.{FileSystem, Path}
-import org.apache.spark.sql.{AnalysisException, Row, SparkSession}
+import org.apache.spark.sql.{AnalysisException, Dataset, Row, SparkSession}
import org.apache.spark.sql.catalyst.analysis.EliminateSubqueryAliases
import org.apache.spark.sql.catalyst.catalog.{CatalogRelation, CatalogTable}
+import org.apache.spark.sql.catalyst.plans.logical.Statistics
+import org.apache.spark.sql.execution.datasources.LogicalRelation
/**
* Analyzes the given table in the current database to generate statistics, which will be
* used in query optimizations.
- *
- * Right now, it only supports Hive tables and it only updates the size of a Hive table
- * in the Hive metastore.
*/
-case class AnalyzeTableCommand(tableName: String) extends RunnableCommand {
+case class AnalyzeTableCommand(tableName: String, noscan: Boolean = true) extends RunnableCommand {
override def run(sparkSession: SparkSession): Seq[Row] = {
val sessionState = sparkSession.sessionState
val tableIdent = sessionState.sqlParser.parseTableIdentifier(tableName)
val relation = EliminateSubqueryAliases(sessionState.catalog.lookupRelation(tableIdent))
+ def updateTableStats(
+ catalogTable: CatalogTable,
+ oldTotalSize: Long,
+ oldRowCount: Long,
+ newTotalSize: Long): Unit = {
+
+ var newStats: Option[Statistics] = None
+ if (newTotalSize > 0 && newTotalSize != oldTotalSize) {
+ newStats = Some(Statistics(sizeInBytes = newTotalSize))
+ }
+ if (!noscan) {
+ val newRowCount = Dataset.ofRows(sparkSession, relation).count()
+ if (newRowCount >= 0 && newRowCount != oldRowCount) {
+ newStats = if (newStats.isDefined) {
+ newStats.map(_.copy(rowCount = Some(BigInt(newRowCount))))
+ } else {
+ Some(Statistics(sizeInBytes = oldTotalSize, rowCount = Some(BigInt(newRowCount))))
+ }
+ }
+ }
+ // Update the metastore if the above statistics of the table are different from those
+ // recorded in the metastore.
+ if (newStats.isDefined) {
+ sessionState.catalog.alterTable(
+ catalogTable.copy(catalogStats = newStats), fromAnalyze = true)
+
+ // Refresh the cache of the table in the catalog.
--- End diff --
This comment is confusing. We have two caches. One is the data cache, another is logical plan cache for data source tables.
---
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 infrastructure@apache.org or file a JIRA ticket
with INFRA.
---
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org
[GitHub] spark pull request #14712: [SPARK-17072] [SQL] support table-level statistic...
Posted by asfgit <gi...@git.apache.org>.
Github user asfgit closed the pull request at:
https://github.com/apache/spark/pull/14712
---
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 infrastructure@apache.org or file a JIRA ticket
with INFRA.
---
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org
[GitHub] spark issue #14712: [SPARK-17072] [SQL] support table-level statistics gener...
Posted by cloud-fan <gi...@git.apache.org>.
Github user cloud-fan commented on the issue:
https://github.com/apache/spark/pull/14712
add to whitelist
---
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 infrastructure@apache.org or file a JIRA ticket
with INFRA.
---
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org
[GitHub] spark pull request #14712: [SPARK-17072] [SQL] support table-level statistic...
Posted by wzhfy <gi...@git.apache.org>.
Github user wzhfy commented on a diff in the pull request:
https://github.com/apache/spark/pull/14712#discussion_r76354055
--- Diff: sql/core/src/main/scala/org/apache/spark/sql/execution/command/AnalyzeTableCommand.scala ---
@@ -88,14 +89,70 @@ case class AnalyzeTableCommand(tableName: String) extends RunnableCommand {
}
}.getOrElse(0L)
- // Update the Hive metastore if the total size of the table is different than the size
- // recorded in the Hive metastore.
- // This logic is based on org.apache.hadoop.hive.ql.exec.StatsTask.aggregateStats().
- if (newTotalSize > 0 && newTotalSize != oldTotalSize) {
+ var needUpdate = false
+ val totalSize = if (newTotalSize > 0 && newTotalSize != oldTotalSize) {
+ needUpdate = true
+ newTotalSize
+ } else {
+ oldTotalSize
+ }
+ var numRows: Option[BigInt] = None
+ if (!noscan) {
+ val oldRowCount: Long = if (catalogTable.catalogStats.isDefined) {
+ catalogTable.catalogStats.get.rowCount.map(_.toLong).getOrElse(-1L)
+ } else {
+ -1L
+ }
+ val newRowCount = sparkSession.table(tableName).count()
+ if (newRowCount >= 0 && newRowCount != oldRowCount) {
+ numRows = Some(BigInt(newRowCount))
+ needUpdate = true
+ }
+ }
+ // Update the metastore if the above statistics of the table are different from those
+ // recorded in the metastore.
+ if (needUpdate) {
+ sessionState.catalog.alterTable(
+ catalogTable.copy(
+ catalogStats = Some(Statistics(
+ sizeInBytes = totalSize, rowCount = numRows))),
+ fromAnalyze = true)
+
+ // Refresh the cache of the table in the catalog.
+ sessionState.catalog.refreshTable(tableIdent)
+ }
+
+ // data source tables have been converted into LogicalRelations
+ case logicalRel: LogicalRelation if logicalRel.metastoreTableIdentifier.isDefined =>
--- End diff --
We will reach here when analyzing data source table with hive, the table is in form of LogicalRelation maintained in "cachedDataSourceTables" in HiveMetastoreCatalog.
---
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 infrastructure@apache.org or file a JIRA ticket
with INFRA.
---
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org
[GitHub] spark issue #14712: [SPARK-17072] [SQL] support table-level statistics gener...
Posted by wzhfy <gi...@git.apache.org>.
Github user wzhfy commented on the issue:
https://github.com/apache/spark/pull/14712
I suggest in the current stage, we still follow hive's convention. When spark sql has its own metastore, we can bridge between these two metastores by a mapping between two different sets of names/data structures, and then provide a config for users to declare their preference.
---
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 infrastructure@apache.org or file a JIRA ticket
with INFRA.
---
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org
[GitHub] spark issue #14712: [SPARK-17072] [SQL] support table-level statistics gener...
Posted by AmplabJenkins <gi...@git.apache.org>.
Github user AmplabJenkins commented on the issue:
https://github.com/apache/spark/pull/14712
Test FAILed.
Refer to this link for build results (access rights to CI server needed):
https://amplab.cs.berkeley.edu/jenkins//job/SparkPullRequestBuilder/64713/
Test FAILed.
---
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 infrastructure@apache.org or file a JIRA ticket
with INFRA.
---
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org
[GitHub] spark pull request #14712: [SPARK-17072] [SQL] support table-level statistic...
Posted by cloud-fan <gi...@git.apache.org>.
Github user cloud-fan commented on a diff in the pull request:
https://github.com/apache/spark/pull/14712#discussion_r76374096
--- Diff: sql/hive/src/main/scala/org/apache/spark/sql/hive/client/HiveClientImpl.scala ---
@@ -427,6 +430,44 @@ private[hive] class HiveClientImpl(
client.alterTable(qualifiedTableName, hiveTable)
}
+ override def alterTableStats(table: CatalogTable): Unit = withHiveState {
--- End diff --
I think these logic should go into `HiveExternalCatalog`
---
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 infrastructure@apache.org or file a JIRA ticket
with INFRA.
---
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org
[GitHub] spark pull request #14712: [SPARK-17072] [SQL] support table-level statistic...
Posted by gatorsmile <gi...@git.apache.org>.
Github user gatorsmile commented on a diff in the pull request:
https://github.com/apache/spark/pull/14712#discussion_r76920300
--- Diff: sql/hive/src/test/scala/org/apache/spark/sql/hive/StatisticsSuite.scala ---
@@ -168,6 +169,81 @@ class StatisticsSuite extends QueryTest with TestHiveSingleton with SQLTestUtils
TableIdentifier("tempTable"), ignoreIfNotExists = true, purge = false)
}
+ private def checkMetastoreRelationStats(
+ tableName: String,
+ totalSize: Long,
+ rowCount: Option[BigInt]): Unit = {
+ val df = sql(s"SELECT * FROM $tableName")
+ val relations = df.queryExecution.analyzed.collect { case rel: MetastoreRelation =>
+ rel.statistics
+ assert(rel.statistics.sizeInBytes === totalSize)
+ assert(rel.statistics.rowCount === rowCount)
+ }
+ assert(relations.size === 1)
+ }
+
+ private def checkLogicalRelationStats(tableName: String, rowCount: Option[BigInt]): Unit = {
+ val df = sql(s"SELECT * FROM $tableName")
+ val relations = df.queryExecution.analyzed.collect { case rel: LogicalRelation =>
+ assert(rel.statistics.sizeInBytes === rel.relation.sizeInBytes)
+ assert(rel.statistics.rowCount === rowCount)
+ }
+ assert(relations.size === 1)
+ }
+
+ test("test table-level statistics for hive tables created in HiveExternalCatalog") {
+ val textTable = "textTable"
+ val parquetTable = "parquetTable"
+ val orcTable = "orcTable"
+ withTable(textTable, parquetTable, orcTable) {
+ sql(s"CREATE TABLE $textTable (key STRING, value STRING) STORED AS TEXTFILE")
+ sql(s"INSERT INTO TABLE $textTable SELECT * FROM src")
+
+ // noscan won't count the number of rows
+ sql(s"ANALYZE TABLE $textTable COMPUTE STATISTICS noscan")
+ checkMetastoreRelationStats(textTable, 5812, None)
--- End diff --
`checkMetastoreRelationStats(textTable, 5812, None)`
=> `checkMetastoreRelationStats(textTable, expectedTotalSize =5812, expectedRowCount = None)`
---
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 infrastructure@apache.org or file a JIRA ticket
with INFRA.
---
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org
[GitHub] spark issue #14712: [SPARK-17072] [SQL] support table-level statistics gener...
Posted by AmplabJenkins <gi...@git.apache.org>.
Github user AmplabJenkins commented on the issue:
https://github.com/apache/spark/pull/14712
Merged build finished. Test PASSed.
---
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 infrastructure@apache.org or file a JIRA ticket
with INFRA.
---
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org
[GitHub] spark issue #14712: [SPARK-17072] [SQL] support table-level statistics gener...
Posted by wzhfy <gi...@git.apache.org>.
Github user wzhfy commented on the issue:
https://github.com/apache/spark/pull/14712
this pr is updated and passed all tests, please review @cloud-fan @hvanhovell @gatorsmile @viirya
---
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 infrastructure@apache.org or file a JIRA ticket
with INFRA.
---
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org
[GitHub] spark pull request #14712: [SPARK-17072] [SQL] support table-level statistic...
Posted by hvanhovell <gi...@git.apache.org>.
Github user hvanhovell commented on a diff in the pull request:
https://github.com/apache/spark/pull/14712#discussion_r75603123
--- Diff: sql/core/src/main/scala/org/apache/spark/sql/execution/datasources/LogicalRelation.scala ---
@@ -72,9 +72,12 @@ case class LogicalRelation(
// expId can be different but the relation is still the same.
override lazy val cleanArgs: Seq[Any] = Seq(relation)
- @transient override lazy val statistics: Statistics = Statistics(
- sizeInBytes = BigInt(relation.sizeInBytes)
- )
+ // statistics inherited from a MetastoreRelation
+ @transient var inheritedStats: Option[Statistics] = None
--- End diff --
@cloud-fan should `BaseRelation` in a perfect world contain a statistics object? That would have my preference, if we can maintain binary compatibility (mainly for the many connectors that use this API).
+1 for moving table conversion into the planner.
---
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 infrastructure@apache.org or file a JIRA ticket
with INFRA.
---
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org
[GitHub] spark issue #14712: [SPARK-17072] [SQL] support table-level statistics gener...
Posted by gatorsmile <gi...@git.apache.org>.
Github user gatorsmile commented on the issue:
https://github.com/apache/spark/pull/14712
LGTM except two minor comments about test cases.
---
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 infrastructure@apache.org or file a JIRA ticket
with INFRA.
---
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org
[GitHub] spark issue #14712: [SPARK-17072] [SQL] support table-level statistics gener...
Posted by wzhfy <gi...@git.apache.org>.
Github user wzhfy commented on the issue:
https://github.com/apache/spark/pull/14712
@cloud-fan @gatorsmile Actually, we desperately need spark sql to have its own metastore, because we need to persist statistics like histograms which AFAIK hive metastore doesn't support.
---
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 infrastructure@apache.org or file a JIRA ticket
with INFRA.
---
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org
[GitHub] spark issue #14712: [SPARK-17072] [SQL] support table-level statistics gener...
Posted by AmplabJenkins <gi...@git.apache.org>.
Github user AmplabJenkins commented on the issue:
https://github.com/apache/spark/pull/14712
Merged build finished. Test FAILed.
---
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 infrastructure@apache.org or file a JIRA ticket
with INFRA.
---
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org
[GitHub] spark issue #14712: [SPARK-17072] [SQL] support table-level statistics gener...
Posted by SparkQA <gi...@git.apache.org>.
Github user SparkQA commented on the issue:
https://github.com/apache/spark/pull/14712
**[Test build #64848 has started](https://amplab.cs.berkeley.edu/jenkins/job/SparkPullRequestBuilder/64848/consoleFull)** for PR 14712 at commit [`b946df0`](https://github.com/apache/spark/commit/b946df0928da061ca67b93d2587c1e258fd5d63b).
---
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 infrastructure@apache.org or file a JIRA ticket
with INFRA.
---
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org
[GitHub] spark pull request #14712: [SPARK-17072] [SQL] support table-level statistic...
Posted by cloud-fan <gi...@git.apache.org>.
Github user cloud-fan commented on a diff in the pull request:
https://github.com/apache/spark/pull/14712#discussion_r77303607
--- Diff: sql/hive/src/main/scala/org/apache/spark/sql/hive/HiveExternalCatalog.scala ---
@@ -610,6 +637,14 @@ object HiveExternalCatalog {
val DATASOURCE_SCHEMA_BUCKETCOL_PREFIX = DATASOURCE_SCHEMA_PREFIX + "bucketCol."
val DATASOURCE_SCHEMA_SORTCOL_PREFIX = DATASOURCE_SCHEMA_PREFIX + "sortCol."
+ val STATISTICS_PREFIX = "spark.sql.statistics."
--- End diff --
in `verifyTableProperties` we should also check `STATISTICS_PREFIX` to forbid users to alter stats properties in ALTER TABLE directly.
---
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 infrastructure@apache.org or file a JIRA ticket
with INFRA.
---
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org
[GitHub] spark issue #14712: [SPARK-17072] [SQL] support table-level statistics gener...
Posted by SparkQA <gi...@git.apache.org>.
Github user SparkQA commented on the issue:
https://github.com/apache/spark/pull/14712
**[Test build #3227 has finished](https://amplab.cs.berkeley.edu/jenkins/job/NewSparkPullRequestBuilder/3227/consoleFull)** for PR 14712 at commit [`4375e76`](https://github.com/apache/spark/commit/4375e76c7ef4dd68e91f2bc5d5aa1cd31c4d3989).
* This patch passes all tests.
* This patch merges cleanly.
* This patch adds the following public classes _(experimental)_:
* `case class Statistics(`
* `case class AnalyzeTableCommand(tableName: String, noscan: Boolean = true) extends RunnableCommand `
---
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 infrastructure@apache.org or file a JIRA ticket
with INFRA.
---
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org
[GitHub] spark issue #14712: [SPARK-17072] [SQL] support table-level statistics gener...
Posted by viirya <gi...@git.apache.org>.
Github user viirya commented on the issue:
https://github.com/apache/spark/pull/14712
Looks much better now.
---
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 infrastructure@apache.org or file a JIRA ticket
with INFRA.
---
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org
[GitHub] spark pull request #14712: [SPARK-17072] [SQL] support table-level statistic...
Posted by wzhfy <gi...@git.apache.org>.
Github user wzhfy commented on a diff in the pull request:
https://github.com/apache/spark/pull/14712#discussion_r76356157
--- Diff: sql/core/src/main/scala/org/apache/spark/sql/execution/command/AnalyzeTableCommand.scala ---
@@ -88,14 +89,70 @@ case class AnalyzeTableCommand(tableName: String) extends RunnableCommand {
}
}.getOrElse(0L)
- // Update the Hive metastore if the total size of the table is different than the size
- // recorded in the Hive metastore.
- // This logic is based on org.apache.hadoop.hive.ql.exec.StatsTask.aggregateStats().
- if (newTotalSize > 0 && newTotalSize != oldTotalSize) {
+ var needUpdate = false
+ val totalSize = if (newTotalSize > 0 && newTotalSize != oldTotalSize) {
+ needUpdate = true
+ newTotalSize
+ } else {
+ oldTotalSize
+ }
+ var numRows: Option[BigInt] = None
+ if (!noscan) {
+ val oldRowCount: Long = if (catalogTable.catalogStats.isDefined) {
+ catalogTable.catalogStats.get.rowCount.map(_.toLong).getOrElse(-1L)
+ } else {
+ -1L
+ }
+ val newRowCount = sparkSession.table(tableName).count()
+ if (newRowCount >= 0 && newRowCount != oldRowCount) {
--- End diff --
If we delete the statistics, we can't tell whether we don't collect stats or the table is empty.
---
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 infrastructure@apache.org or file a JIRA ticket
with INFRA.
---
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org
[GitHub] spark issue #14712: [SPARK-17072] [SQL] support table-level statistics gener...
Posted by gatorsmile <gi...@git.apache.org>.
Github user gatorsmile commented on the issue:
https://github.com/apache/spark/pull/14712
@cloud-fan let me do more investigation and will reply your question later.
---
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 infrastructure@apache.org or file a JIRA ticket
with INFRA.
---
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org
[GitHub] spark pull request #14712: [SPARK-17072] [SQL] support table-level statistic...
Posted by viirya <gi...@git.apache.org>.
Github user viirya commented on a diff in the pull request:
https://github.com/apache/spark/pull/14712#discussion_r76932253
--- Diff: sql/hive/src/main/scala/org/apache/spark/sql/hive/MetastoreRelation.scala ---
@@ -140,7 +145,12 @@ private[hive] case class MetastoreRelation(
sparkSession.sessionState.conf.defaultSizeInBytes
})
}
- )
+ if (catalogTable.catalogStats.isDefined) {
--- End diff --
Actually the `catalogStats` here is already obtained from Hive's number in `constructStatsFromHive` below.
---
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 infrastructure@apache.org or file a JIRA ticket
with INFRA.
---
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org
[GitHub] spark issue #14712: [SPARK-17072] [SQL] support table-level statistics gener...
Posted by SparkQA <gi...@git.apache.org>.
Github user SparkQA commented on the issue:
https://github.com/apache/spark/pull/14712
**[Test build #64850 has finished](https://amplab.cs.berkeley.edu/jenkins/job/SparkPullRequestBuilder/64850/consoleFull)** for PR 14712 at commit [`b946df0`](https://github.com/apache/spark/commit/b946df0928da061ca67b93d2587c1e258fd5d63b).
* This patch passes all tests.
* This patch merges cleanly.
* This patch adds no public classes.
---
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 infrastructure@apache.org or file a JIRA ticket
with INFRA.
---
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org
[GitHub] spark pull request #14712: [SPARK-17072] [SQL] support table-level statistic...
Posted by viirya <gi...@git.apache.org>.
Github user viirya commented on a diff in the pull request:
https://github.com/apache/spark/pull/14712#discussion_r75588230
--- Diff: sql/core/src/main/scala/org/apache/spark/sql/execution/command/AnalyzeTableCommand.scala ---
@@ -33,7 +34,7 @@ import org.apache.spark.sql.catalyst.catalog.{CatalogRelation, CatalogTable}
* Right now, it only supports Hive tables and it only updates the size of a Hive table
* in the Hive metastore.
*/
-case class AnalyzeTableCommand(tableName: String) extends RunnableCommand {
+case class AnalyzeTableCommand(tableName: String, noscan: Boolean = true) extends RunnableCommand {
override def run(sparkSession: SparkSession): Seq[Row] = {
--- End diff --
Not related to this PR, but looks like `AnalyzeTableCommand` doesn't handle the possible `NoSuchTableException` caused by `sessionState.catalog.lookupRelation`. It should be better to handle it and provide error message.
---
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 infrastructure@apache.org or file a JIRA ticket
with INFRA.
---
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org
[GitHub] spark pull request #14712: [SPARK-17072] [SQL] support table-level statistic...
Posted by gatorsmile <gi...@git.apache.org>.
Github user gatorsmile commented on a diff in the pull request:
https://github.com/apache/spark/pull/14712#discussion_r75574009
--- Diff: sql/core/src/main/scala/org/apache/spark/sql/execution/datasources/LogicalRelation.scala ---
@@ -72,9 +72,12 @@ case class LogicalRelation(
// expId can be different but the relation is still the same.
override lazy val cleanArgs: Seq[Any] = Seq(relation)
- @transient override lazy val statistics: Statistics = Statistics(
- sizeInBytes = BigInt(relation.sizeInBytes)
- )
+ // statistics inherited from a MetastoreRelation
+ @transient var inheritedStats: Option[Statistics] = None
--- End diff --
Submitted a PR https://github.com/apache/spark/pull/14729 to fix the issue.
---
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 infrastructure@apache.org or file a JIRA ticket
with INFRA.
---
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org
[GitHub] spark issue #14712: [SPARK-17072] [SQL] support table-level statistics gener...
Posted by gatorsmile <gi...@git.apache.org>.
Github user gatorsmile commented on the issue:
https://github.com/apache/spark/pull/14712
One minor comment about the current PR and the future PRs in statistics. When we adding new statistics-specific properties, we should exclude them in the DDL command, like `SHOW CREATE TABLE`.
BTW, now, we have a bug in this part. Hive-generated statistics should not be shown too. I will fix it in a separate PR.
---
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 infrastructure@apache.org or file a JIRA ticket
with INFRA.
---
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org
[GitHub] spark pull request #14712: [SPARK-17072] [SQL] support table-level statistic...
Posted by gatorsmile <gi...@git.apache.org>.
Github user gatorsmile commented on a diff in the pull request:
https://github.com/apache/spark/pull/14712#discussion_r75548186
--- Diff: sql/hive/src/test/scala/org/apache/spark/sql/hive/StatisticsSuite.scala ---
@@ -168,6 +170,57 @@ class StatisticsSuite extends QueryTest with TestHiveSingleton with SQLTestUtils
TableIdentifier("tempTable"), ignoreIfNotExists = true, purge = false)
}
+ test("generate table-level statistics") {
+ def checkTableStats(
+ statsSeq: Seq[Statistics],
+ sizeInBytes: Int,
+ estimatedSize: Int,
+ rowCount: Int): Unit = {
+ assert(statsSeq.size === 1)
+ assert(statsSeq.head.sizeInBytes === BigInt(sizeInBytes))
+ assert(statsSeq.head.estimatedSize === Some(BigInt(estimatedSize)))
+ assert(statsSeq.head.rowCount === Some(BigInt(rowCount)))
+ }
+
+ sql("CREATE TABLE analyzeTable (key STRING, value STRING)").collect()
+ sql("CREATE TABLE parquetTable (key STRING, value STRING) STORED AS PARQUET").collect()
+ sql("CREATE TABLE orcTable (key STRING, value STRING) STORED AS ORC").collect()
+
+ sql("INSERT INTO TABLE analyzeTable SELECT * FROM src").collect()
+ sql("INSERT INTO TABLE parquetTable SELECT * FROM src").collect()
+ sql("INSERT INTO TABLE orcTable SELECT * FROM src").collect()
+ sql("INSERT INTO TABLE orcTable SELECT * FROM src").collect()
+
+ sql("ANALYZE TABLE analyzeTable COMPUTE STATISTICS")
--- End diff --
Before calling `ANALYZE TABLE`, table properties already have the latest values of `numFiles` and `totalSize`. Thus, `totalSize` is not added/updated by `ANALYZE TABLE`.
---
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 infrastructure@apache.org or file a JIRA ticket
with INFRA.
---
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org
[GitHub] spark issue #14712: [SPARK-17072] [SQL] support table-level statistics gener...
Posted by hvanhovell <gi...@git.apache.org>.
Github user hvanhovell commented on the issue:
https://github.com/apache/spark/pull/14712
How about we use our own property names for now, and provide a Hive translation layer in a different PR. IMO it is fine to break a little bit of the behavior in master as long as we fix it (or make a well founded choice not to) before 2.1.
---
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 infrastructure@apache.org or file a JIRA ticket
with INFRA.
---
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org
[GitHub] spark pull request #14712: [SPARK-17072] [SQL] support table-level statistic...
Posted by gatorsmile <gi...@git.apache.org>.
Github user gatorsmile commented on a diff in the pull request:
https://github.com/apache/spark/pull/14712#discussion_r77016228
--- Diff: sql/hive/src/test/scala/org/apache/spark/sql/hive/StatisticsSuite.scala ---
@@ -168,6 +169,107 @@ class StatisticsSuite extends QueryTest with TestHiveSingleton with SQLTestUtils
TableIdentifier("tempTable"), ignoreIfNotExists = true, purge = false)
}
+ private def checkMetastoreRelationStats(
+ tableName: String,
+ expectedTotalSize: Long,
+ expectedRowCount: Option[BigInt]): Unit = {
+ val df = sql(s"SELECT * FROM $tableName")
+ val relations = df.queryExecution.analyzed.collect { case rel: MetastoreRelation =>
+ assert(rel.statistics.sizeInBytes === expectedTotalSize)
+ assert(rel.statistics.rowCount === expectedRowCount)
+ rel
+ }
+ assert(relations.size === 1)
+ }
+
+ test("test table-level statistics for hive tables created in HiveExternalCatalog") {
+ val textTable = "textTable"
+ withTable(textTable) {
+ sql(s"CREATE TABLE $textTable (key STRING, value STRING) STORED AS TEXTFILE")
+ checkMetastoreRelationStats(textTable,
+ expectedTotalSize = spark.sessionState.conf.defaultSizeInBytes, expectedRowCount = None)
+
+ sql(s"INSERT INTO TABLE $textTable SELECT * FROM src")
+ // don't have our statistics, MetastoreRelation uses hive's `totalSize`
+ checkMetastoreRelationStats(textTable, expectedTotalSize = 5812, expectedRowCount = None)
+
+ // noscan won't count the number of rows
+ sql(s"ANALYZE TABLE $textTable COMPUTE STATISTICS noscan")
+ checkMetastoreRelationStats(textTable, expectedTotalSize = 5812, expectedRowCount = None)
+
+ // without noscan, we count the number of rows
+ sql(s"ANALYZE TABLE $textTable COMPUTE STATISTICS")
+ checkMetastoreRelationStats(textTable, expectedTotalSize = 5812, expectedRowCount = Some(500))
+ }
+ }
+
+ test("test whether the old stats are removed") {
+ val textTable = "textTable"
+ withTable(textTable) {
+ sql(s"CREATE TABLE $textTable (key STRING, value STRING) STORED AS TEXTFILE")
+ sql(s"INSERT INTO TABLE $textTable SELECT * FROM src")
+ sql(s"ANALYZE TABLE $textTable COMPUTE STATISTICS")
+ checkMetastoreRelationStats(textTable, expectedTotalSize = 5812, expectedRowCount = Some(500))
+
+ sql(s"INSERT INTO TABLE $textTable SELECT * FROM src")
+ sql(s"ANALYZE TABLE $textTable COMPUTE STATISTICS noscan")
+ // update total size and remove the old and invalid row count
+ checkMetastoreRelationStats(textTable, expectedTotalSize = 11624, expectedRowCount = None)
+ }
+ }
+
+ private def checkLogicalRelationStats(
+ tableName: String,
+ expectedRowCount: Option[BigInt]): Unit = {
+ val df = sql(s"SELECT * FROM $tableName")
+ val relations = df.queryExecution.analyzed.collect { case rel: LogicalRelation =>
+ // TODO: We don't have an expected value here because parquet size is different on Windows
+ // and Linux, we need to find the reason and fix this.
+ assert(rel.statistics.sizeInBytes === rel.relation.sizeInBytes)
+ assert(rel.statistics.rowCount === expectedRowCount)
+ rel
+ }
+ assert(relations.size === 1)
+ }
+
+ test("test statistics of LogicalRelation inherited from MetastoreRelation") {
+ 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")
+ sql(s"ANALYZE TABLE $parquetTable COMPUTE STATISTICS")
+ sql(s"ANALYZE TABLE $orcTable COMPUTE STATISTICS")
+
+ checkLogicalRelationStats(parquetTable, expectedRowCount = Some(500))
--- End diff --
Failure could be also caused by the changes of default conf values.
---
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 infrastructure@apache.org or file a JIRA ticket
with INFRA.
---
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org
[GitHub] spark issue #14712: [SPARK-17072] [SQL] support table-level statistics gener...
Posted by wzhfy <gi...@git.apache.org>.
Github user wzhfy commented on the issue:
https://github.com/apache/spark/pull/14712
I like @hvanhovell 's proposal, since providing a perfect Hive translation layer is not trivial based on @gatorsmile 's investigation - we need to deal with different versions of Hive. It is better to be decoupled from this pr. What do you think? @gatorsmile @cloud-fan
---
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 infrastructure@apache.org or file a JIRA ticket
with INFRA.
---
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org
[GitHub] spark pull request #14712: [SPARK-17072] [SQL] support table-level statistic...
Posted by gatorsmile <gi...@git.apache.org>.
Github user gatorsmile commented on a diff in the pull request:
https://github.com/apache/spark/pull/14712#discussion_r75513984
--- Diff: sql/core/src/main/scala/org/apache/spark/sql/execution/command/AnalyzeTableCommand.scala ---
@@ -88,14 +90,30 @@ case class AnalyzeTableCommand(tableName: String) extends RunnableCommand {
}
}.getOrElse(0L)
- // Update the Hive metastore if the total size of the table is different than the size
+ val needUpdate = new mutable.HashMap[String, String]()
+ if (newTotalSize > 0 && newTotalSize != oldTotalSize) {
+ needUpdate += (AnalyzeTableCommand.TOTAL_SIZE_FIELD -> newTotalSize.toString)
+ }
+ if (!noscan) {
+ val oldRowCount = tableParameters.get(AnalyzeTableCommand.ROW_COUNT).map(_.toLong)
+ .getOrElse(-1L)
+ val newRowCount = sparkSession.table(tableName).count()
+
+ if (newRowCount >= 0 && newRowCount != oldRowCount) {
+ needUpdate += (AnalyzeTableCommand.ROW_COUNT -> newRowCount.toString)
+ }
+ }
+ // Update the Hive metastore if the above parameters of the table is different than those
// recorded in the Hive metastore.
// This logic is based on org.apache.hadoop.hive.ql.exec.StatsTask.aggregateStats().
- if (newTotalSize > 0 && newTotalSize != oldTotalSize) {
+ if (needUpdate.nonEmpty) {
+ // need to set this parameter so that we can store other parameters like "numRows" into
+ // Hive metastore
+ needUpdate.put(AnalyzeTableCommand.STATS_GENERATED_VIA_STATS_TASK,
--- End diff --
This is read by Hive? Based on the existing code changes, it looks useless to Spark.
---
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 infrastructure@apache.org or file a JIRA ticket
with INFRA.
---
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org
[GitHub] spark pull request #14712: [SPARK-17072] [SQL] support table-level statistic...
Posted by cloud-fan <gi...@git.apache.org>.
Github user cloud-fan commented on a diff in the pull request:
https://github.com/apache/spark/pull/14712#discussion_r75480152
--- Diff: sql/core/src/main/scala/org/apache/spark/sql/execution/command/AnalyzeTableCommand.scala ---
@@ -88,14 +90,30 @@ case class AnalyzeTableCommand(tableName: String) extends RunnableCommand {
}
}.getOrElse(0L)
- // Update the Hive metastore if the total size of the table is different than the size
+ val needUpdate = new mutable.HashMap[String, String]()
+ if (newTotalSize > 0 && newTotalSize != oldTotalSize) {
+ needUpdate += (AnalyzeTableCommand.TOTAL_SIZE_FIELD -> newTotalSize.toString)
+ }
+ if (!noscan) {
+ val oldRowCount = tableParameters.get(AnalyzeTableCommand.ROW_COUNT).map(_.toLong)
+ .getOrElse(-1L)
+ val newRowCount = sparkSession.table(tableName).count()
+
+ if (newRowCount >= 0 && newRowCount != oldRowCount) {
+ needUpdate += (AnalyzeTableCommand.ROW_COUNT -> newRowCount.toString)
+ }
+ }
+ // Update the Hive metastore if the above parameters of the table is different than those
// recorded in the Hive metastore.
// This logic is based on org.apache.hadoop.hive.ql.exec.StatsTask.aggregateStats().
- if (newTotalSize > 0 && newTotalSize != oldTotalSize) {
+ if (needUpdate.nonEmpty) {
+ // need to set this parameter so that we can store other parameters like "numRows" into
+ // Hive metastore
+ needUpdate.put(AnalyzeTableCommand.STATS_GENERATED_VIA_STATS_TASK,
--- End diff --
can you explain a bit more about this? When will read this field?
---
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 infrastructure@apache.org or file a JIRA ticket
with INFRA.
---
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org
[GitHub] spark issue #14712: [SPARK-17072] [SQL] support table-level statistics gener...
Posted by AmplabJenkins <gi...@git.apache.org>.
Github user AmplabJenkins commented on the issue:
https://github.com/apache/spark/pull/14712
Test PASSed.
Refer to this link for build results (access rights to CI server needed):
https://amplab.cs.berkeley.edu/jenkins//job/SparkPullRequestBuilder/64641/
Test PASSed.
---
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 infrastructure@apache.org or file a JIRA ticket
with INFRA.
---
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org
[GitHub] spark pull request #14712: [SPARK-17072] [SQL] support table-level statistic...
Posted by gatorsmile <gi...@git.apache.org>.
Github user gatorsmile commented on a diff in the pull request:
https://github.com/apache/spark/pull/14712#discussion_r75519101
--- Diff: sql/core/src/main/scala/org/apache/spark/sql/execution/datasources/LogicalRelation.scala ---
@@ -72,9 +72,12 @@ case class LogicalRelation(
// expId can be different but the relation is still the same.
override lazy val cleanArgs: Seq[Any] = Seq(relation)
- @transient override lazy val statistics: Statistics = Statistics(
- sizeInBytes = BigInt(relation.sizeInBytes)
- )
+ // statistics inherited from a MetastoreRelation
+ @transient var inheritedStats: Option[Statistics] = None
--- End diff --
It sounds like `ANALYZE TABLE` can also be used for HiveMetastore/In-Memory cataloged data source tables. If we do not support it, we need to block it.
---
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 infrastructure@apache.org or file a JIRA ticket
with INFRA.
---
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org
[GitHub] spark issue #14712: [SPARK-17072] [SQL] support table-level statistics gener...
Posted by wzhfy <gi...@git.apache.org>.
Github user wzhfy commented on the issue:
https://github.com/apache/spark/pull/14712
@yhuai @hvanhovell @cloud-fan Sorry for the late response, I'm out of office for two days.
@gatorsmile Thanks to fix it!
---
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 infrastructure@apache.org or file a JIRA ticket
with INFRA.
---
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org
[GitHub] spark issue #14712: [SPARK-17072] [SQL] support table-level statistics gener...
Posted by wzhfy <gi...@git.apache.org>.
Github user wzhfy commented on the issue:
https://github.com/apache/spark/pull/14712
@cloud-fan I think the current implementation is ok and can support three level priorities. The logic is encapsulated in two methods for storing/retrieving stats. When the interaction behavior with hive is changed in the future, its influence range is controlled and we just need to modify these two methods.
---
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 infrastructure@apache.org or file a JIRA ticket
with INFRA.
---
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org
[GitHub] spark issue #14712: [SPARK-17072] [SQL] support table-level statistics gener...
Posted by yhuai <gi...@git.apache.org>.
Github user yhuai commented on the issue:
https://github.com/apache/spark/pull/14712
Can you take a look at the test at https://amplab.cs.berkeley.edu/jenkins/job/SparkPullRequestBuilder/64956/testReport/junit/org.apache.spark.sql.hive/StatisticsSuite/test_statistics_of_LogicalRelation_converted_from_MetastoreRelation/? It is flaky.
---
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 infrastructure@apache.org or file a JIRA ticket
with INFRA.
---
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org
[GitHub] spark issue #14712: [SPARK-17072] [SQL] support table-level statistics gener...
Posted by gatorsmile <gi...@git.apache.org>.
Github user gatorsmile commented on the issue:
https://github.com/apache/spark/pull/14712
I like @cloud-fan 's proposal. : )
When the values of these two copies are different, which one is preferred? a) **Hive**: if we prefer Hive's version, we might be affected by Hive. b) **Spark**: if we choose Spark's copy, we might lose the benefit of Hive-generated statistics. Adding a new configuration parameter? The default is Option a? (I also do not like adding any extra parameter)
---
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 infrastructure@apache.org or file a JIRA ticket
with INFRA.
---
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org
[GitHub] spark issue #14712: [SPARK-17072] [SQL] support table-level statistics gener...
Posted by cloud-fan <gi...@git.apache.org>.
Github user cloud-fan commented on the issue:
https://github.com/apache/spark/pull/14712
Spark SQL already has its own metastore: `InMemoryCatalog`. And we do have an abstraction for metasotre: `ExternalCatalog`. We have 2 targets here:
1. add table statistics in Spark SQL
2. Spark SQL and Hive should recognize table statistics from each other.
I think target 1 is more important, and we do need an implementation that not depend on hive features.
> Actually, we desperately need spark sql to have its own metastore, because we need to persist statistics like histograms which AFAIK hive metastore doesn't support.
We store table statistics in table properties, why would hive metastore not support it? Do you mean Hive can't recognize it? But I think it's ok, we should not limit our table statistics by what Hive supports.
---
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 infrastructure@apache.org or file a JIRA ticket
with INFRA.
---
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org
[GitHub] spark issue #14712: [SPARK-17072] [SQL] support table-level statistics gener...
Posted by gatorsmile <gi...@git.apache.org>.
Github user gatorsmile commented on the issue:
https://github.com/apache/spark/pull/14712
Below is a test case for a table with empty column. Could you also add it here?
```Scala
test("statistics collection of a table with zero column") {
val table_no_cols = "table_no_cols"
withTable(table_no_cols) {
val rddNoCols = sparkContext.parallelize(1 to 10).map(_ => Row.empty)
val dfNoCols = spark.createDataFrame(rddNoCols, StructType(Seq.empty))
dfNoCols.write.format("json").saveAsTable(table_no_cols)
sql(s"ANALYZE TABLE $table_no_cols COMPUTE STATISTICS")
checkLogicalRelationStats(table_no_cols, expectedStats =
Some(Statistics(sizeInBytes = 30, rowCount = Some(10))))
}
}
```
In the future, we will do column-level statistics collection. This might help you when you implement collection of column-level statistics.
---
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 infrastructure@apache.org or file a JIRA ticket
with INFRA.
---
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org
[GitHub] spark issue #14712: [SPARK-17072] [SQL] support table-level statistics gener...
Posted by cloud-fan <gi...@git.apache.org>.
Github user cloud-fan commented on the issue:
https://github.com/apache/spark/pull/14712
a high-level question: Looks like the current design depends on some features of hive metastore, e.g. the `STATS_GENERATED_VIA_STATS_TASK` flag. Is it possible that we just treat hive metastore as a persistent level? So that the statistics can still work if Spark SQL has its own metastore in the future.
---
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 infrastructure@apache.org or file a JIRA ticket
with INFRA.
---
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org
[GitHub] spark pull request #14712: [SPARK-17072] [SQL] support table-level statistic...
Posted by wzhfy <gi...@git.apache.org>.
Github user wzhfy commented on a diff in the pull request:
https://github.com/apache/spark/pull/14712#discussion_r75572799
--- Diff: sql/core/src/main/scala/org/apache/spark/sql/execution/command/AnalyzeTableCommand.scala ---
@@ -88,14 +90,30 @@ case class AnalyzeTableCommand(tableName: String) extends RunnableCommand {
}
}.getOrElse(0L)
- // Update the Hive metastore if the total size of the table is different than the size
+ val needUpdate = new mutable.HashMap[String, String]()
+ if (newTotalSize > 0 && newTotalSize != oldTotalSize) {
+ needUpdate += (AnalyzeTableCommand.TOTAL_SIZE_FIELD -> newTotalSize.toString)
+ }
+ if (!noscan) {
+ val oldRowCount = tableParameters.get(AnalyzeTableCommand.ROW_COUNT).map(_.toLong)
+ .getOrElse(-1L)
+ val newRowCount = sparkSession.table(tableName).count()
+
+ if (newRowCount >= 0 && newRowCount != oldRowCount) {
+ needUpdate += (AnalyzeTableCommand.ROW_COUNT -> newRowCount.toString)
+ }
+ }
+ // Update the Hive metastore if the above parameters of the table is different than those
// recorded in the Hive metastore.
// This logic is based on org.apache.hadoop.hive.ql.exec.StatsTask.aggregateStats().
- if (newTotalSize > 0 && newTotalSize != oldTotalSize) {
+ if (needUpdate.nonEmpty) {
+ // need to set this parameter so that we can store other parameters like "numRows" into
+ // Hive metastore
+ needUpdate.put(AnalyzeTableCommand.STATS_GENERATED_VIA_STATS_TASK,
--- End diff --
@viirya yeah, thanks for the advice
---
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 infrastructure@apache.org or file a JIRA ticket
with INFRA.
---
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org
[GitHub] spark pull request #14712: [SPARK-17072] [SQL] support table-level statistic...
Posted by cloud-fan <gi...@git.apache.org>.
Github user cloud-fan commented on a diff in the pull request:
https://github.com/apache/spark/pull/14712#discussion_r77113054
--- Diff: sql/core/src/main/scala/org/apache/spark/sql/execution/command/AnalyzeTableCommand.scala ---
@@ -88,24 +85,53 @@ case class AnalyzeTableCommand(tableName: String) extends RunnableCommand {
}
}.getOrElse(0L)
- // Update the Hive metastore if the total size of the table is different than the size
- // recorded in the Hive metastore.
- // This logic is based on org.apache.hadoop.hive.ql.exec.StatsTask.aggregateStats().
- if (newTotalSize > 0 && newTotalSize != oldTotalSize) {
- sessionState.catalog.alterTable(
- catalogTable.copy(
- properties = relation.catalogTable.properties +
- (AnalyzeTableCommand.TOTAL_SIZE_FIELD -> newTotalSize.toString)))
- }
+ updateTableStats(
+ catalogTable,
+ oldTotalSize = catalogTable.stats.map(_.sizeInBytes.toLong).getOrElse(0L),
+ oldRowCount = catalogTable.stats.flatMap(_.rowCount.map(_.toLong)).getOrElse(-1L),
+ newTotalSize = newTotalSize)
+
+ // data source tables have been converted into LogicalRelations
+ case logicalRel: LogicalRelation if logicalRel.catalogTable.isDefined =>
+ updateTableStats(
+ logicalRel.catalogTable.get,
+ oldTotalSize = logicalRel.statistics.sizeInBytes.toLong,
+ oldRowCount = logicalRel.statistics.rowCount.map(_.toLong).getOrElse(-1L),
+ newTotalSize = logicalRel.relation.sizeInBytes)
--- End diff --
looks like `logicalRel.relation.sizeInBytes` is always equal to `logicalRel.statistics.sizeInBytes.toLong`?
```
@transient override lazy val statistics: Statistics = Statistics(
sizeInBytes = BigInt(relation.sizeInBytes)
)
```
---
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 infrastructure@apache.org or file a JIRA ticket
with INFRA.
---
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org
[GitHub] spark issue #14712: [SPARK-17072] [SQL] support table-level statistics gener...
Posted by SparkQA <gi...@git.apache.org>.
Github user SparkQA commented on the issue:
https://github.com/apache/spark/pull/14712
**[Test build #64750 has started](https://amplab.cs.berkeley.edu/jenkins/job/SparkPullRequestBuilder/64750/consoleFull)** for PR 14712 at commit [`aa438c4`](https://github.com/apache/spark/commit/aa438c43f78d5edd679fd3e6294d953181a40268).
---
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 infrastructure@apache.org or file a JIRA ticket
with INFRA.
---
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org
[GitHub] spark pull request #14712: [SPARK-17072] [SQL] support table-level statistic...
Posted by wzhfy <gi...@git.apache.org>.
Github user wzhfy commented on a diff in the pull request:
https://github.com/apache/spark/pull/14712#discussion_r76920328
--- Diff: sql/core/src/main/scala/org/apache/spark/sql/execution/datasources/LogicalRelation.scala ---
@@ -33,7 +33,8 @@ import org.apache.spark.util.Utils
case class LogicalRelation(
relation: BaseRelation,
expectedOutputAttributes: Option[Seq[Attribute]] = None,
- metastoreTableIdentifier: Option[TableIdentifier] = None)
+ metastoreTableIdentifier: Option[TableIdentifier] = None,
+ inheritedStats: Option[Statistics] = None)
--- End diff --
Since LogicalRelation is converted from Parquet/Orc MetastoreRelation or SimpleCatalogRelation, I think the current name is more indicative
---
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 infrastructure@apache.org or file a JIRA ticket
with INFRA.
---
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org
[GitHub] spark pull request #14712: [SPARK-17072] [SQL] support table-level statistic...
Posted by cloud-fan <gi...@git.apache.org>.
Github user cloud-fan commented on a diff in the pull request:
https://github.com/apache/spark/pull/14712#discussion_r77309971
--- Diff: sql/hive/src/main/scala/org/apache/spark/sql/hive/HiveExternalCatalog.scala ---
@@ -383,21 +384,34 @@ private[spark] class HiveExternalCatalog(conf: SparkConf, hadoopConf: Configurat
requireTableExists(db, tableDefinition.identifier.table)
verifyTableProperties(tableDefinition)
- if (DDLUtils.isDatasourceTable(tableDefinition)) {
- val oldDef = client.getTable(db, tableDefinition.identifier.table)
+ // convert table statistics to properties so that we can persist them through hive api
+ val catalogTable = if (tableDefinition.stats.isDefined) {
--- End diff --
I don't think an unnecessary copy matters here, but let's keep it as it was.
How about renaming `catalogTable` to `withStatsProps`?
---
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 infrastructure@apache.org or file a JIRA ticket
with INFRA.
---
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org
[GitHub] spark issue #14712: [SPARK-17072] [SQL] support table-level statistics gener...
Posted by AmplabJenkins <gi...@git.apache.org>.
Github user AmplabJenkins commented on the issue:
https://github.com/apache/spark/pull/14712
Test FAILed.
Refer to this link for build results (access rights to CI server needed):
https://amplab.cs.berkeley.edu/jenkins//job/SparkPullRequestBuilder/64459/
Test FAILed.
---
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 infrastructure@apache.org or file a JIRA ticket
with INFRA.
---
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org
[GitHub] spark pull request #14712: [SPARK-17072] [SQL] support table-level statistic...
Posted by hvanhovell <gi...@git.apache.org>.
Github user hvanhovell commented on a diff in the pull request:
https://github.com/apache/spark/pull/14712#discussion_r76966560
--- Diff: sql/core/src/main/scala/org/apache/spark/sql/execution/datasources/LogicalRelation.scala ---
@@ -33,7 +33,8 @@ import org.apache.spark.util.Utils
case class LogicalRelation(
relation: BaseRelation,
expectedOutputAttributes: Option[Seq[Attribute]] = None,
- metastoreTableIdentifier: Option[TableIdentifier] = None)
+ metastoreTableIdentifier: Option[TableIdentifier] = None,
+ inheritedStats: Option[Statistics] = None)
--- End diff --
Shouldn't we just add the CatalogTable instead of adding both an identifier and statistics?
---
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 infrastructure@apache.org or file a JIRA ticket
with INFRA.
---
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org
[GitHub] spark pull request #14712: [SPARK-17072] [SQL] support table-level statistic...
Posted by viirya <gi...@git.apache.org>.
Github user viirya commented on a diff in the pull request:
https://github.com/apache/spark/pull/14712#discussion_r75571934
--- Diff: sql/hive/src/main/scala/org/apache/spark/sql/hive/HiveMetastoreCatalog.scala ---
@@ -342,7 +342,9 @@ private[hive] class HiveMetastoreCatalog(sparkSession: SparkSession) extends Log
logicalRelation
}
- result.copy(expectedOutputAttributes = Some(metastoreRelation.output))
+ val logicalRel = result.copy(expectedOutputAttributes = Some(metastoreRelation.output))
+ logicalRel.inheritedStats = Some(metastoreRelation.statistics)
--- End diff --
I agreed with @cloud-fan. This looks hacky.
---
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 infrastructure@apache.org or file a JIRA ticket
with INFRA.
---
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org
[GitHub] spark issue #14712: [SPARK-17072] [SQL] support table-level statistics gener...
Posted by SparkQA <gi...@git.apache.org>.
Github user SparkQA commented on the issue:
https://github.com/apache/spark/pull/14712
**[Test build #64713 has started](https://amplab.cs.berkeley.edu/jenkins/job/SparkPullRequestBuilder/64713/consoleFull)** for PR 14712 at commit [`56ec68e`](https://github.com/apache/spark/commit/56ec68e455cefcc589db0336a580754662d8257c).
---
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 infrastructure@apache.org or file a JIRA ticket
with INFRA.
---
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org
[GitHub] spark issue #14712: [SPARK-17072] [SQL] support table-level statistics gener...
Posted by wzhfy <gi...@git.apache.org>.
Github user wzhfy commented on the issue:
https://github.com/apache/spark/pull/14712
I think the problem lies in the dependence on hive metastore. As long as we use hive metastore to persist/retrieve statistics, we need to deal with these flags.
- If we analyze the table in spark and want to persist stats in Hive metastore (and retrieve them when we do queries), we must set STATS_GENERATED_VIA_STATS_TASK, otherwise the stats won't be stored. - this is in top priority
- If users alter table's properties (without setting STATS_GENERATED_VIA_STATS_TASK) in Spark or Hive, then COLUMN_STATS_ACCURATE will be false and stats be set to invalid, so it's unnecessary to read the stats in Spark. - this is in second priority
---
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 infrastructure@apache.org or file a JIRA ticket
with INFRA.
---
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org
[GitHub] spark pull request #14712: [SPARK-17072] [SQL] support table-level statistic...
Posted by wzhfy <gi...@git.apache.org>.
Github user wzhfy commented on a diff in the pull request:
https://github.com/apache/spark/pull/14712#discussion_r77137539
--- Diff: sql/core/src/main/scala/org/apache/spark/sql/execution/datasources/LogicalRelation.scala ---
@@ -52,7 +52,8 @@ case class LogicalRelation(
// Logical Relations are distinct if they have different output for the sake of transformations.
override def equals(other: Any): Boolean = other match {
- case l @ LogicalRelation(otherRelation, _, _) => relation == otherRelation && output == l.output
+ case l @ LogicalRelation(otherRelation, _, _) =>
+ relation == otherRelation && output == l.output
--- End diff --
I'll recover it
---
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 infrastructure@apache.org or file a JIRA ticket
with INFRA.
---
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org
[GitHub] spark issue #14712: [SPARK-17072] [SQL] support table-level statistics gener...
Posted by AmplabJenkins <gi...@git.apache.org>.
Github user AmplabJenkins commented on the issue:
https://github.com/apache/spark/pull/14712
Test FAILed.
Refer to this link for build results (access rights to CI server needed):
https://amplab.cs.berkeley.edu/jenkins//job/SparkPullRequestBuilder/64626/
Test FAILed.
---
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 infrastructure@apache.org or file a JIRA ticket
with INFRA.
---
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org
[GitHub] spark pull request #14712: [SPARK-17072] [SQL] support table-level statistic...
Posted by cloud-fan <gi...@git.apache.org>.
Github user cloud-fan commented on a diff in the pull request:
https://github.com/apache/spark/pull/14712#discussion_r77301653
--- Diff: sql/core/src/main/scala/org/apache/spark/sql/execution/command/AnalyzeTableCommand.scala ---
@@ -88,24 +85,54 @@ case class AnalyzeTableCommand(tableName: String) extends RunnableCommand {
}
}.getOrElse(0L)
- // Update the Hive metastore if the total size of the table is different than the size
- // recorded in the Hive metastore.
- // This logic is based on org.apache.hadoop.hive.ql.exec.StatsTask.aggregateStats().
- if (newTotalSize > 0 && newTotalSize != oldTotalSize) {
- sessionState.catalog.alterTable(
- catalogTable.copy(
- properties = relation.catalogTable.properties +
- (AnalyzeTableCommand.TOTAL_SIZE_FIELD -> newTotalSize.toString)))
- }
+ updateTableStats(
+ catalogTable,
+ oldTotalSize = catalogTable.stats.map(_.sizeInBytes.toLong).getOrElse(0L),
+ oldRowCount = catalogTable.stats.flatMap(_.rowCount.map(_.toLong)).getOrElse(-1L),
+ newTotalSize = newTotalSize)
+
+ // data source tables have been converted into LogicalRelations
+ case logicalRel: LogicalRelation if logicalRel.catalogTable.isDefined =>
+ val table = logicalRel.catalogTable.get
+ updateTableStats(
+ table,
+ oldTotalSize = table.stats.map(_.sizeInBytes.toLong).getOrElse(0L),
+ oldRowCount = table.stats.flatMap(_.rowCount.map(_.toLong)).getOrElse(-1L),
+ newTotalSize = logicalRel.relation.sizeInBytes)
case otherRelation =>
- throw new AnalysisException(s"ANALYZE TABLE is only supported for Hive tables, " +
- s"but '${tableIdent.unquotedString}' is a ${otherRelation.nodeName}.")
+ throw new AnalysisException(s"ANALYZE TABLE is not supported for " +
+ s"${otherRelation.nodeName}.")
}
+
+ def updateTableStats(
+ catalogTable: CatalogTable,
+ oldTotalSize: Long,
+ oldRowCount: Long,
+ newTotalSize: Long): Unit = {
+ var newStats: Option[Statistics] = None
--- End diff --
how about:
```
val newRowCount = if (noscan) {
oldRowCount
} else {
Dataset.ofRows(sparkSession, relation).count()
}
val updateTotalSize = newTotalSize > 0 && newTotalSize != oldTotalSize
val updateRowCount = newRowCount >= 0 && newRowCount != oldRowCount
if (updateTotalSize || updateRowCount) {
val newStats = Statistics(sizeInBytes = newTotalSize, rowCount = Some(BigInt(newRowCount)))
sessionState.catalog.alterTable(catalogTable.copy(stats = Some(newStats)))
// Refresh the cached data source table in the catalog.
sessionState.catalog.refreshTable(tableIdent)
}
```
---
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 infrastructure@apache.org or file a JIRA ticket
with INFRA.
---
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org
[GitHub] spark pull request #14712: [SPARK-17072] [SQL] support table-level statistic...
Posted by wzhfy <gi...@git.apache.org>.
Github user wzhfy commented on a diff in the pull request:
https://github.com/apache/spark/pull/14712#discussion_r77313069
--- Diff: sql/hive/src/main/scala/org/apache/spark/sql/hive/HiveExternalCatalog.scala ---
@@ -383,21 +384,34 @@ private[spark] class HiveExternalCatalog(conf: SparkConf, hadoopConf: Configurat
requireTableExists(db, tableDefinition.identifier.table)
verifyTableProperties(tableDefinition)
- if (DDLUtils.isDatasourceTable(tableDefinition)) {
- val oldDef = client.getTable(db, tableDefinition.identifier.table)
+ // convert table statistics to properties so that we can persist them through hive api
+ val catalogTable = if (tableDefinition.stats.isDefined) {
--- End diff --
@cloud-fan ok, withStatsProps is better
---
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 infrastructure@apache.org or file a JIRA ticket
with INFRA.
---
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org
[GitHub] spark issue #14712: [SPARK-17072] [SQL] support table-level statistics gener...
Posted by gatorsmile <gi...@git.apache.org>.
Github user gatorsmile commented on the issue:
https://github.com/apache/spark/pull/14712
Great! Will review the new changes when it is ready. Thanks!
---
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 infrastructure@apache.org or file a JIRA ticket
with INFRA.
---
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org
[GitHub] spark pull request #14712: [SPARK-17072] [SQL] support table-level statistic...
Posted by wzhfy <gi...@git.apache.org>.
Github user wzhfy commented on a diff in the pull request:
https://github.com/apache/spark/pull/14712#discussion_r75569351
--- Diff: sql/core/src/main/scala/org/apache/spark/sql/execution/command/AnalyzeTableCommand.scala ---
@@ -33,7 +34,7 @@ import org.apache.spark.sql.catalyst.catalog.{CatalogRelation, CatalogTable}
* Right now, it only supports Hive tables and it only updates the size of a Hive table
* in the Hive metastore.
*/
-case class AnalyzeTableCommand(tableName: String) extends RunnableCommand {
+case class AnalyzeTableCommand(tableName: String, noscan: Boolean = true) extends RunnableCommand {
--- End diff --
Recalculation incurs high cost, it should be triggered by uses like DBAs. We can have an mechanism to incrementally update the stats in the future, but that will need some well designed algorithms (especially for histograms) and definition of confidence interval.
---
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 infrastructure@apache.org or file a JIRA ticket
with INFRA.
---
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org
[GitHub] spark issue #14712: [SPARK-17072] [SQL] support table-level statistics gener...
Posted by SparkQA <gi...@git.apache.org>.
Github user SparkQA commented on the issue:
https://github.com/apache/spark/pull/14712
**[Test build #64626 has started](https://amplab.cs.berkeley.edu/jenkins/job/SparkPullRequestBuilder/64626/consoleFull)** for PR 14712 at commit [`7e39a86`](https://github.com/apache/spark/commit/7e39a86030e45f10ae0c171a475c054b7c208d20).
---
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 infrastructure@apache.org or file a JIRA ticket
with INFRA.
---
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org
[GitHub] spark pull request #14712: [SPARK-17072] [SQL] support table-level statistic...
Posted by cloud-fan <gi...@git.apache.org>.
Github user cloud-fan commented on a diff in the pull request:
https://github.com/apache/spark/pull/14712#discussion_r76967205
--- Diff: sql/core/src/main/scala/org/apache/spark/sql/execution/datasources/LogicalRelation.scala ---
@@ -33,7 +33,8 @@ import org.apache.spark.util.Utils
case class LogicalRelation(
relation: BaseRelation,
expectedOutputAttributes: Option[Seq[Attribute]] = None,
- metastoreTableIdentifier: Option[TableIdentifier] = None)
+ metastoreTableIdentifier: Option[TableIdentifier] = None,
+ inheritedStats: Option[Statistics] = None)
--- End diff --
having `metastoreTableIdentifier` inside `LogicalRelation` means we already hack the table concept into `LogicalRelation`, how about we go further and put `CatalogTable` in `LogicalRelation`? I think it's better than taking a `TableIdentifier` and a `Statistics` object.
---
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 infrastructure@apache.org or file a JIRA ticket
with INFRA.
---
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org
[GitHub] spark pull request #14712: [SPARK-17072] [SQL] support table-level statistic...
Posted by gatorsmile <gi...@git.apache.org>.
Github user gatorsmile commented on a diff in the pull request:
https://github.com/apache/spark/pull/14712#discussion_r77009503
--- Diff: sql/core/src/main/scala/org/apache/spark/sql/execution/datasources/LogicalRelation.scala ---
@@ -33,7 +33,8 @@ import org.apache.spark.util.Utils
case class LogicalRelation(
relation: BaseRelation,
expectedOutputAttributes: Option[Seq[Attribute]] = None,
- metastoreTableIdentifier: Option[TableIdentifier] = None)
+ metastoreTableIdentifier: Option[TableIdentifier] = None,
+ inheritedStats: Option[Statistics] = None)
--- End diff --
I like this idea! Adding `CatalogTable` also makes us easier to replace `MetastoreRelation` by `LogicalRelation`.
---
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 infrastructure@apache.org or file a JIRA ticket
with INFRA.
---
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org
[GitHub] spark pull request #14712: [SPARK-17072] [SQL] support table-level statistic...
Posted by viirya <gi...@git.apache.org>.
Github user viirya commented on a diff in the pull request:
https://github.com/apache/spark/pull/14712#discussion_r75571723
--- Diff: sql/core/src/main/scala/org/apache/spark/sql/execution/command/AnalyzeTableCommand.scala ---
@@ -88,14 +90,30 @@ case class AnalyzeTableCommand(tableName: String) extends RunnableCommand {
}
}.getOrElse(0L)
- // Update the Hive metastore if the total size of the table is different than the size
+ val needUpdate = new mutable.HashMap[String, String]()
+ if (newTotalSize > 0 && newTotalSize != oldTotalSize) {
+ needUpdate += (AnalyzeTableCommand.TOTAL_SIZE_FIELD -> newTotalSize.toString)
+ }
+ if (!noscan) {
+ val oldRowCount = tableParameters.get(AnalyzeTableCommand.ROW_COUNT).map(_.toLong)
+ .getOrElse(-1L)
+ val newRowCount = sparkSession.table(tableName).count()
+
+ if (newRowCount >= 0 && newRowCount != oldRowCount) {
+ needUpdate += (AnalyzeTableCommand.ROW_COUNT -> newRowCount.toString)
+ }
+ }
+ // Update the Hive metastore if the above parameters of the table is different than those
// recorded in the Hive metastore.
// This logic is based on org.apache.hadoop.hive.ql.exec.StatsTask.aggregateStats().
- if (newTotalSize > 0 && newTotalSize != oldTotalSize) {
+ if (needUpdate.nonEmpty) {
+ // need to set this parameter so that we can store other parameters like "numRows" into
+ // Hive metastore
+ needUpdate.put(AnalyzeTableCommand.STATS_GENERATED_VIA_STATS_TASK,
--- End diff --
Looks `STATS_GENERATED_VIA_STATS_TASK` is only needed to set when `noscan` is `false`. So is it better to move this to above block `if (!noscan)`?
---
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 infrastructure@apache.org or file a JIRA ticket
with INFRA.
---
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org
[GitHub] spark issue #14712: [SPARK-17072] [SQL] support table-level statistics gener...
Posted by gatorsmile <gi...@git.apache.org>.
Github user gatorsmile commented on the issue:
https://github.com/apache/spark/pull/14712
@wzhfy Yeah, it sounds good to me to split the whole problem into multiple PRs.
@hvanhovell Sure, let me create the JIRA and I can work on this when the other dependent JIRAs are resolved.
---
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 infrastructure@apache.org or file a JIRA ticket
with INFRA.
---
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org
[GitHub] spark issue #14712: [SPARK-17072] [SQL] support table-level statistics gener...
Posted by AmplabJenkins <gi...@git.apache.org>.
Github user AmplabJenkins commented on the issue:
https://github.com/apache/spark/pull/14712
Merged build finished. Test PASSed.
---
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 infrastructure@apache.org or file a JIRA ticket
with INFRA.
---
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org
[GitHub] spark issue #14712: [SPARK-17072] [SQL] support table-level statistics gener...
Posted by SparkQA <gi...@git.apache.org>.
Github user SparkQA commented on the issue:
https://github.com/apache/spark/pull/14712
**[Test build #64850 has started](https://amplab.cs.berkeley.edu/jenkins/job/SparkPullRequestBuilder/64850/consoleFull)** for PR 14712 at commit [`b946df0`](https://github.com/apache/spark/commit/b946df0928da061ca67b93d2587c1e258fd5d63b).
---
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 infrastructure@apache.org or file a JIRA ticket
with INFRA.
---
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org
[GitHub] spark issue #14712: [SPARK-17072] [SQL] support table-level statistics gener...
Posted by wzhfy <gi...@git.apache.org>.
Github user wzhfy commented on the issue:
https://github.com/apache/spark/pull/14712
@cloud-fan @hvanhovell Oh, sorry, it's already been lauched. There's latency for about 5 mins.
---
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 infrastructure@apache.org or file a JIRA ticket
with INFRA.
---
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org
[GitHub] spark pull request #14712: [SPARK-17072] [SQL] support table-level statistic...
Posted by gatorsmile <gi...@git.apache.org>.
Github user gatorsmile commented on a diff in the pull request:
https://github.com/apache/spark/pull/14712#discussion_r77373066
--- Diff: sql/hive/src/test/scala/org/apache/spark/sql/hive/StatisticsSuite.scala ---
@@ -168,6 +170,137 @@ class StatisticsSuite extends QueryTest with TestHiveSingleton with SQLTestUtils
TableIdentifier("tempTable"), ignoreIfNotExists = true, purge = false)
}
+ private def checkMetastoreRelationStats(
+ tableName: String,
+ expectedStats: Option[Statistics]): Unit = {
+ val df = sql(s"SELECT * FROM $tableName")
+ val relations = df.queryExecution.analyzed.collect { case rel: MetastoreRelation =>
+ expectedStats match {
+ case Some(es) =>
+ assert(rel.catalogTable.stats.isDefined)
+ val stats = rel.catalogTable.stats.get
+ assert(stats.sizeInBytes === es.sizeInBytes)
+ assert(stats.rowCount === es.rowCount)
+ case None =>
+ assert(rel.catalogTable.stats.isEmpty)
+ }
+ rel
+ }
+ assert(relations.size === 1)
+ }
+
+ test("test table-level statistics for hive tables created in HiveExternalCatalog") {
+ val textTable = "textTable"
+ withTable(textTable) {
+ // Currently Spark's statistics are self-contained, we don't have statistics until we use
+ // the `ANALYZE TABLE` command.
+ sql(s"CREATE TABLE $textTable (key STRING, value STRING) STORED AS TEXTFILE")
+ checkMetastoreRelationStats(textTable, expectedStats = None)
+ sql(s"INSERT INTO TABLE $textTable SELECT * FROM src")
+ checkMetastoreRelationStats(textTable, expectedStats = None)
+
+ // noscan won't count the number of rows
+ sql(s"ANALYZE TABLE $textTable COMPUTE STATISTICS noscan")
+ checkMetastoreRelationStats(textTable, expectedStats =
+ Some(Statistics(sizeInBytes = 5812, rowCount = None)))
+
+ // without noscan, we count the number of rows
+ sql(s"ANALYZE TABLE $textTable COMPUTE STATISTICS")
+ checkMetastoreRelationStats(textTable, expectedStats =
+ Some(Statistics(sizeInBytes = 5812, rowCount = Some(500))))
+ }
+ }
+
+ test("test elimination of the influences of the old stats") {
+ val textTable = "textTable"
+ withTable(textTable) {
+ sql(s"CREATE TABLE $textTable (key STRING, value STRING) STORED AS TEXTFILE")
+ sql(s"INSERT INTO TABLE $textTable SELECT * FROM src")
+ sql(s"ANALYZE TABLE $textTable COMPUTE STATISTICS")
+ checkMetastoreRelationStats(textTable, expectedStats =
+ Some(Statistics(sizeInBytes = 5812, rowCount = Some(500))))
+
--- End diff --
Just here, could you add a few lines?
```
sql(s"ANALYZE TABLE $textTable COMPUTE STATISTICS noscan")
// when the total size is not changed, the old row count is kept
checkMetastoreRelationStats(textTable, expectedStats =
Some(Statistics(sizeInBytes = 5812, rowCount = Some(500))))
```
---
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 infrastructure@apache.org or file a JIRA ticket
with INFRA.
---
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org
[GitHub] spark issue #14712: [SPARK-17072] [SQL] support table-level statistics gener...
Posted by viirya <gi...@git.apache.org>.
Github user viirya commented on the issue:
https://github.com/apache/spark/pull/14712
If it is a hive table, I think we should respect hive's statistics.
---
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 infrastructure@apache.org or file a JIRA ticket
with INFRA.
---
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org
[GitHub] spark issue #14712: [SPARK-17072] [SQL] support table-level statistics gener...
Posted by SparkQA <gi...@git.apache.org>.
Github user SparkQA commented on the issue:
https://github.com/apache/spark/pull/14712
**[Test build #3244 has started](https://amplab.cs.berkeley.edu/jenkins/job/NewSparkPullRequestBuilder/3244/consoleFull)** for PR 14712 at commit [`b946df0`](https://github.com/apache/spark/commit/b946df0928da061ca67b93d2587c1e258fd5d63b).
---
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 infrastructure@apache.org or file a JIRA ticket
with INFRA.
---
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org
[GitHub] spark pull request #14712: [SPARK-17072] [SQL] support table-level statistic...
Posted by wzhfy <gi...@git.apache.org>.
Github user wzhfy commented on a diff in the pull request:
https://github.com/apache/spark/pull/14712#discussion_r76354802
--- Diff: sql/core/src/main/scala/org/apache/spark/sql/execution/command/AnalyzeTableCommand.scala ---
@@ -88,14 +89,70 @@ case class AnalyzeTableCommand(tableName: String) extends RunnableCommand {
}
}.getOrElse(0L)
- // Update the Hive metastore if the total size of the table is different than the size
- // recorded in the Hive metastore.
- // This logic is based on org.apache.hadoop.hive.ql.exec.StatsTask.aggregateStats().
- if (newTotalSize > 0 && newTotalSize != oldTotalSize) {
+ var needUpdate = false
+ val totalSize = if (newTotalSize > 0 && newTotalSize != oldTotalSize) {
+ needUpdate = true
+ newTotalSize
+ } else {
+ oldTotalSize
+ }
+ var numRows: Option[BigInt] = None
+ if (!noscan) {
+ val oldRowCount: Long = if (catalogTable.catalogStats.isDefined) {
--- End diff --
thanks, this looks more concise!
---
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 infrastructure@apache.org or file a JIRA ticket
with INFRA.
---
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org
[GitHub] spark issue #14712: [SPARK-17072] [SQL] support table-level statistics gener...
Posted by wzhfy <gi...@git.apache.org>.
Github user wzhfy commented on the issue:
https://github.com/apache/spark/pull/14712
@gatorsmile Thank you for the information!
---
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 infrastructure@apache.org or file a JIRA ticket
with INFRA.
---
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org
[GitHub] spark issue #14712: [SPARK-17072] [SQL] support table-level statistics gener...
Posted by wzhfy <gi...@git.apache.org>.
Github user wzhfy commented on the issue:
https://github.com/apache/spark/pull/14712
@cloud-fan what i was saying is out of the range of this pr.
Table property is a string-string map, which means we need to transform every statistic into/from a string. This is ok for simple table statistics like "numRows", but not a good choice for complicated column statistics like histograms.
InMemoryCatalog is "in memory", we can have our own properties or data structures, but currently we still need Hive metastore api to \u201cpersist\u201d these statistics. Hive has APIs for storing/loading table properties and ColumnStats, but no api for histograms.
What I'm trying to say is, we can use hive as a persistent level, but what we can store/load is still limited by its api. Of course we can put everything into properties, but it's not elegant.
---
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 infrastructure@apache.org or file a JIRA ticket
with INFRA.
---
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org
[GitHub] spark issue #14712: [SPARK-17072] [SQL] support table-level statistics gener...
Posted by gatorsmile <gi...@git.apache.org>.
Github user gatorsmile commented on the issue:
https://github.com/apache/spark/pull/14712
Maybe I found another bug in the master branch?
When calculating statistics for data source tables, we do not exclude the staging directory. However, we exclude them when `AnalyzeTableCommand` calculating the size. Since we convert Hive serde tables to data source tables, it sounds like we should also exclude Hive staging directory, 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 infrastructure@apache.org or file a JIRA ticket
with INFRA.
---
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org
[GitHub] spark issue #14712: [SPARK-17072] [SQL] support table-level statistics gener...
Posted by SparkQA <gi...@git.apache.org>.
Github user SparkQA commented on the issue:
https://github.com/apache/spark/pull/14712
**[Test build #3227 has started](https://amplab.cs.berkeley.edu/jenkins/job/NewSparkPullRequestBuilder/3227/consoleFull)** for PR 14712 at commit [`4375e76`](https://github.com/apache/spark/commit/4375e76c7ef4dd68e91f2bc5d5aa1cd31c4d3989).
---
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 infrastructure@apache.org or file a JIRA ticket
with INFRA.
---
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org
[GitHub] spark pull request #14712: [SPARK-17072] [SQL] support table-level statistic...
Posted by wzhfy <gi...@git.apache.org>.
Github user wzhfy commented on a diff in the pull request:
https://github.com/apache/spark/pull/14712#discussion_r76380631
--- Diff: sql/hive/src/main/scala/org/apache/spark/sql/hive/client/HiveClientImpl.scala ---
@@ -427,6 +430,44 @@ private[hive] class HiveClientImpl(
client.alterTable(qualifiedTableName, hiveTable)
}
+ override def alterTableStats(table: CatalogTable): Unit = withHiveState {
--- End diff --
what's the boundary between HiveExternalCatalog and HiveClientImpl?
---
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 infrastructure@apache.org or file a JIRA ticket
with INFRA.
---
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org
[GitHub] spark pull request #14712: [SPARK-17072] [SQL] support table-level statistic...
Posted by wzhfy <gi...@git.apache.org>.
Github user wzhfy commented on a diff in the pull request:
https://github.com/apache/spark/pull/14712#discussion_r77139470
--- Diff: sql/core/src/main/scala/org/apache/spark/sql/execution/command/AnalyzeTableCommand.scala ---
@@ -88,24 +85,53 @@ case class AnalyzeTableCommand(tableName: String) extends RunnableCommand {
}
}.getOrElse(0L)
- // Update the Hive metastore if the total size of the table is different than the size
- // recorded in the Hive metastore.
- // This logic is based on org.apache.hadoop.hive.ql.exec.StatsTask.aggregateStats().
- if (newTotalSize > 0 && newTotalSize != oldTotalSize) {
- sessionState.catalog.alterTable(
- catalogTable.copy(
- properties = relation.catalogTable.properties +
- (AnalyzeTableCommand.TOTAL_SIZE_FIELD -> newTotalSize.toString)))
- }
+ updateTableStats(
+ catalogTable,
+ oldTotalSize = catalogTable.stats.map(_.sizeInBytes.toLong).getOrElse(0L),
+ oldRowCount = catalogTable.stats.flatMap(_.rowCount.map(_.toLong)).getOrElse(-1L),
+ newTotalSize = newTotalSize)
+
+ // data source tables have been converted into LogicalRelations
+ case logicalRel: LogicalRelation if logicalRel.catalogTable.isDefined =>
+ updateTableStats(
+ logicalRel.catalogTable.get,
+ oldTotalSize = logicalRel.statistics.sizeInBytes.toLong,
+ oldRowCount = logicalRel.statistics.rowCount.map(_.toLong).getOrElse(-1L),
+ newTotalSize = logicalRel.relation.sizeInBytes)
--- End diff --
Yes, for the first analyze they are equal. But if there's a second analyze, they are not equal, since logicalRel is in the cachedDataSourceTables, its statistics is the original one.
Anyway, there's a bug here. I think we can use catalogTable's statistics as the old one and I'll restore the test case to check size.
---
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 infrastructure@apache.org or file a JIRA ticket
with INFRA.
---
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org
[GitHub] spark pull request #14712: [SPARK-17072] [SQL] support table-level statistic...
Posted by gatorsmile <gi...@git.apache.org>.
Github user gatorsmile commented on a diff in the pull request:
https://github.com/apache/spark/pull/14712#discussion_r75549270
--- Diff: sql/hive/src/test/scala/org/apache/spark/sql/hive/StatisticsSuite.scala ---
@@ -168,6 +170,57 @@ class StatisticsSuite extends QueryTest with TestHiveSingleton with SQLTestUtils
TableIdentifier("tempTable"), ignoreIfNotExists = true, purge = false)
}
+ test("generate table-level statistics") {
+ def checkTableStats(
+ statsSeq: Seq[Statistics],
+ sizeInBytes: Int,
+ estimatedSize: Int,
+ rowCount: Int): Unit = {
+ assert(statsSeq.size === 1)
+ assert(statsSeq.head.sizeInBytes === BigInt(sizeInBytes))
+ assert(statsSeq.head.estimatedSize === Some(BigInt(estimatedSize)))
+ assert(statsSeq.head.rowCount === Some(BigInt(rowCount)))
+ }
+
+ sql("CREATE TABLE analyzeTable (key STRING, value STRING)").collect()
--- End diff --
All the `.collect()` can be removed.
---
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 infrastructure@apache.org or file a JIRA ticket
with INFRA.
---
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org
[GitHub] spark pull request #14712: [SPARK-17072] [SQL] support table-level statistic...
Posted by gatorsmile <gi...@git.apache.org>.
Github user gatorsmile commented on a diff in the pull request:
https://github.com/apache/spark/pull/14712#discussion_r75573529
--- Diff: sql/core/src/main/scala/org/apache/spark/sql/execution/datasources/LogicalRelation.scala ---
@@ -72,9 +72,12 @@ case class LogicalRelation(
// expId can be different but the relation is still the same.
override lazy val cleanArgs: Seq[Any] = Seq(relation)
- @transient override lazy val statistics: Statistics = Statistics(
- sizeInBytes = BigInt(relation.sizeInBytes)
- )
+ // statistics inherited from a MetastoreRelation
+ @transient var inheritedStats: Option[Statistics] = None
--- End diff --
The `ExternalCatalog` APIs define the methods to interacts with the external catalog. Spark 2.0 provides two implementations, including `HiveExternalCatalog` and `InMemoryCatalog`. The default is `InMemoryCatalog` if the build is not with the Hive profile. Users are able to run `ANALYZE TABLE` against the tables when we using `InMemoryCatalog`.
You can try this command when you using `InMemoryCatalog`. You might understand what I said above.
---
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 infrastructure@apache.org or file a JIRA ticket
with INFRA.
---
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org
[GitHub] spark issue #14712: [SPARK-17072] [SQL] support table-level statistics gener...
Posted by AmplabJenkins <gi...@git.apache.org>.
Github user AmplabJenkins commented on the issue:
https://github.com/apache/spark/pull/14712
Merged build finished. Test PASSed.
---
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 infrastructure@apache.org or file a JIRA ticket
with INFRA.
---
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org
[GitHub] spark issue #14712: [SPARK-17072] [SQL] support table-level statistics gener...
Posted by SparkQA <gi...@git.apache.org>.
Github user SparkQA commented on the issue:
https://github.com/apache/spark/pull/14712
**[Test build #64459 has finished](https://amplab.cs.berkeley.edu/jenkins/job/SparkPullRequestBuilder/64459/consoleFull)** for PR 14712 at commit [`aee4139`](https://github.com/apache/spark/commit/aee4139031b283e95bf0ef9ae6488c3396909ec4).
* This patch **fails Spark unit tests**.
* This patch merges cleanly.
* This patch adds no public classes.
---
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 infrastructure@apache.org or file a JIRA ticket
with INFRA.
---
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org
[GitHub] spark pull request #14712: [SPARK-17072] [SQL] support table-level statistic...
Posted by hvanhovell <gi...@git.apache.org>.
Github user hvanhovell commented on a diff in the pull request:
https://github.com/apache/spark/pull/14712#discussion_r76533832
--- Diff: sql/core/src/main/scala/org/apache/spark/sql/execution/datasources/DataSourceStrategy.scala ---
@@ -207,9 +207,11 @@ class FindDataSourceTable(sparkSession: SparkSession) extends Rule[LogicalPlan]
className = table.provider.get,
options = table.storage.properties)
- LogicalRelation(
+ val logicalRel = LogicalRelation(
dataSource.resolveRelation(),
metastoreTableIdentifier = Some(table.identifier))
+ logicalRel.inheritedStats = table.catalogStats
--- End diff --
Shouldn't we just add all the table metadata to the LogicalRelation? Then we don't have to assign a statistics.
---
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 infrastructure@apache.org or file a JIRA ticket
with INFRA.
---
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org
[GitHub] spark issue #14712: [SPARK-17072] [SQL] support table-level statistics gener...
Posted by cloud-fan <gi...@git.apache.org>.
Github user cloud-fan commented on the issue:
https://github.com/apache/spark/pull/14712
@wzhfy sounds good to me, let's focus on the top priority in this PR :)
---
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 infrastructure@apache.org or file a JIRA ticket
with INFRA.
---
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org
[GitHub] spark issue #14712: [SPARK-17072] [SQL] support table-level statistics gener...
Posted by cloud-fan <gi...@git.apache.org>.
Github user cloud-fan commented on the issue:
https://github.com/apache/spark/pull/14712
retest this please
---
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 infrastructure@apache.org or file a JIRA ticket
with INFRA.
---
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org
[GitHub] spark pull request #14712: [SPARK-17072] [SQL] support table-level statistic...
Posted by wzhfy <gi...@git.apache.org>.
Github user wzhfy commented on a diff in the pull request:
https://github.com/apache/spark/pull/14712#discussion_r75438629
--- Diff: sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/plans/logical/LogicalPlan.scala ---
@@ -95,6 +95,12 @@ abstract class LogicalPlan extends QueryPlan[LogicalPlan] with Logging {
}
/**
+ * Estimate complete [[Statistics]] for this plan. Each plan need to override this to get
+ * complete statistics.
+ */
+ def completeStats: Statistics = statistics
--- End diff --
In this way, we can separate cbo path from the original path when we add a conf for cbo in following tasks. If cbo is open, we use completeStats, if it is off, we still use the original statistics.
When cbo is mature in the future, we can remove the original statistics and use the new completeStats instead.
---
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 infrastructure@apache.org or file a JIRA ticket
with INFRA.
---
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org
[GitHub] spark pull request #14712: [SPARK-17072] [SQL] support table-level statistic...
Posted by gatorsmile <gi...@git.apache.org>.
Github user gatorsmile commented on a diff in the pull request:
https://github.com/apache/spark/pull/14712#discussion_r76920593
--- Diff: sql/hive/src/test/scala/org/apache/spark/sql/hive/StatisticsSuite.scala ---
@@ -168,6 +169,81 @@ class StatisticsSuite extends QueryTest with TestHiveSingleton with SQLTestUtils
TableIdentifier("tempTable"), ignoreIfNotExists = true, purge = false)
}
+ private def checkMetastoreRelationStats(
+ tableName: String,
+ totalSize: Long,
+ rowCount: Option[BigInt]): Unit = {
+ val df = sql(s"SELECT * FROM $tableName")
+ val relations = df.queryExecution.analyzed.collect { case rel: MetastoreRelation =>
+ rel.statistics
+ assert(rel.statistics.sizeInBytes === totalSize)
+ assert(rel.statistics.rowCount === rowCount)
+ }
+ assert(relations.size === 1)
+ }
+
+ private def checkLogicalRelationStats(tableName: String, rowCount: Option[BigInt]): Unit = {
+ val df = sql(s"SELECT * FROM $tableName")
+ val relations = df.queryExecution.analyzed.collect { case rel: LogicalRelation =>
+ assert(rel.statistics.sizeInBytes === rel.relation.sizeInBytes)
+ assert(rel.statistics.rowCount === rowCount)
+ }
+ assert(relations.size === 1)
+ }
+
+ test("test table-level statistics for hive tables created in HiveExternalCatalog") {
+ val textTable = "textTable"
+ val parquetTable = "parquetTable"
+ val orcTable = "orcTable"
+ withTable(textTable, parquetTable, orcTable) {
+ sql(s"CREATE TABLE $textTable (key STRING, value STRING) STORED AS TEXTFILE")
+ sql(s"INSERT INTO TABLE $textTable SELECT * FROM src")
--- End diff --
To ensure the correctness, we also `checkMetastoreRelationStats` before data changes (`INSERT`) and before statistics collection (`ANALYZE`)
---
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 infrastructure@apache.org or file a JIRA ticket
with INFRA.
---
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org
[GitHub] spark issue #14712: [SPARK-17072] [SQL] support table-level statistics gener...
Posted by viirya <gi...@git.apache.org>.
Github user viirya commented on the issue:
https://github.com/apache/spark/pull/14712
Looks like Jenkins doesn't work for a while.
---
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 infrastructure@apache.org or file a JIRA ticket
with INFRA.
---
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org
[GitHub] spark issue #14712: [SPARK-17072] [SQL] support table-level statistics gener...
Posted by SparkQA <gi...@git.apache.org>.
Github user SparkQA commented on the issue:
https://github.com/apache/spark/pull/14712
**[Test build #3244 has finished](https://amplab.cs.berkeley.edu/jenkins/job/NewSparkPullRequestBuilder/3244/consoleFull)** for PR 14712 at commit [`b946df0`](https://github.com/apache/spark/commit/b946df0928da061ca67b93d2587c1e258fd5d63b).
* This patch passes all tests.
* This patch merges cleanly.
* This patch adds no public classes.
---
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 infrastructure@apache.org or file a JIRA ticket
with INFRA.
---
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org
[GitHub] spark pull request #14712: [SPARK-17072] [SQL] support table-level statistic...
Posted by hvanhovell <gi...@git.apache.org>.
Github user hvanhovell commented on a diff in the pull request:
https://github.com/apache/spark/pull/14712#discussion_r75602017
--- Diff: sql/core/src/main/scala/org/apache/spark/sql/execution/datasources/LogicalRelation.scala ---
@@ -72,9 +72,12 @@ case class LogicalRelation(
// expId can be different but the relation is still the same.
override lazy val cleanArgs: Seq[Any] = Seq(relation)
- @transient override lazy val statistics: Statistics = Statistics(
- sizeInBytes = BigInt(relation.sizeInBytes)
- )
+ // statistics inherited from a MetastoreRelation
+ @transient var inheritedStats: Option[Statistics] = None
--- End diff --
So I think we should support `ANALYZE TABLE` with the `InMemoryCatalog`. See my comment on your PR.
---
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 infrastructure@apache.org or file a JIRA ticket
with INFRA.
---
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org
[GitHub] spark pull request #14712: [SPARK-17072] [SQL] support table-level statistic...
Posted by wzhfy <gi...@git.apache.org>.
Github user wzhfy commented on a diff in the pull request:
https://github.com/apache/spark/pull/14712#discussion_r76386878
--- Diff: sql/hive/src/main/scala/org/apache/spark/sql/hive/HiveExternalCatalog.scala ---
@@ -401,6 +401,13 @@ private[spark] class HiveExternalCatalog(conf: SparkConf, hadoopConf: Configurat
}
}
+ override def alterTableStats(tableDefinition: CatalogTable): Unit = withClient {
--- End diff --
Now I remember why I add this method. If we've already run the analyze command, then we have Statistics having rowCount, say 100. Now we run alter table command to set "numRows" to 200 (without setting STATS_GENERATED_VIA_STATS_TASK to true). If we use the same alterTable method, since Statistics is defined, we will set numRows and STATS_GENERATED_VIA_STATS_TASK into properties, just like we do for analyze command.
Then, the parameters in Hive are numRows=100, STATS_GENERATED_VIA_STATS_TASK=true, COLUMN_STATS_ACCURATE=true, while the expected result would be numRows=200, STATS_GENERATED_VIA_STATS_TASK=false, COLUMN_STATS_ACCURATE=false
---
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 infrastructure@apache.org or file a JIRA ticket
with INFRA.
---
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org
[GitHub] spark issue #14712: [SPARK-17072] [SQL] support table-level statistics gener...
Posted by SparkQA <gi...@git.apache.org>.
Github user SparkQA commented on the issue:
https://github.com/apache/spark/pull/14712
**[Test build #64625 has finished](https://amplab.cs.berkeley.edu/jenkins/job/SparkPullRequestBuilder/64625/consoleFull)** for PR 14712 at commit [`9c27071`](https://github.com/apache/spark/commit/9c27071c05da5f285726381dff7eff3dfab7eda9).
* This patch **fails Scala style tests**.
* This patch merges cleanly.
* This patch adds no public classes.
---
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 infrastructure@apache.org or file a JIRA ticket
with INFRA.
---
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org
[GitHub] spark issue #14712: [SPARK-17072] [SQL] support table-level statistics gener...
Posted by AmplabJenkins <gi...@git.apache.org>.
Github user AmplabJenkins commented on the issue:
https://github.com/apache/spark/pull/14712
Merged build finished. Test PASSed.
---
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 infrastructure@apache.org or file a JIRA ticket
with INFRA.
---
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org
[GitHub] spark pull request #14712: [SPARK-17072] [SQL] support table-level statistic...
Posted by viirya <gi...@git.apache.org>.
Github user viirya commented on a diff in the pull request:
https://github.com/apache/spark/pull/14712#discussion_r76918381
--- Diff: sql/core/src/main/scala/org/apache/spark/sql/execution/datasources/LogicalRelation.scala ---
@@ -33,7 +33,8 @@ import org.apache.spark.util.Utils
case class LogicalRelation(
relation: BaseRelation,
expectedOutputAttributes: Option[Seq[Attribute]] = None,
- metastoreTableIdentifier: Option[TableIdentifier] = None)
+ metastoreTableIdentifier: Option[TableIdentifier] = None,
+ inheritedStats: Option[Statistics] = None)
--- End diff --
How about `expectedStatistics`, or `catalogStatistics`?
---
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 infrastructure@apache.org or file a JIRA ticket
with INFRA.
---
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org
[GitHub] spark pull request #14712: [SPARK-17072] [SQL] support table-level statistic...
Posted by cloud-fan <gi...@git.apache.org>.
Github user cloud-fan commented on a diff in the pull request:
https://github.com/apache/spark/pull/14712#discussion_r77313250
--- Diff: sql/core/src/main/scala/org/apache/spark/sql/execution/command/AnalyzeTableCommand.scala ---
@@ -88,24 +85,54 @@ case class AnalyzeTableCommand(tableName: String) extends RunnableCommand {
}
}.getOrElse(0L)
- // Update the Hive metastore if the total size of the table is different than the size
- // recorded in the Hive metastore.
- // This logic is based on org.apache.hadoop.hive.ql.exec.StatsTask.aggregateStats().
- if (newTotalSize > 0 && newTotalSize != oldTotalSize) {
- sessionState.catalog.alterTable(
- catalogTable.copy(
- properties = relation.catalogTable.properties +
- (AnalyzeTableCommand.TOTAL_SIZE_FIELD -> newTotalSize.toString)))
- }
+ updateTableStats(
+ catalogTable,
+ oldTotalSize = catalogTable.stats.map(_.sizeInBytes.toLong).getOrElse(0L),
+ oldRowCount = catalogTable.stats.flatMap(_.rowCount.map(_.toLong)).getOrElse(-1L),
+ newTotalSize = newTotalSize)
+
+ // data source tables have been converted into LogicalRelations
+ case logicalRel: LogicalRelation if logicalRel.catalogTable.isDefined =>
+ val table = logicalRel.catalogTable.get
+ updateTableStats(
+ table,
+ oldTotalSize = table.stats.map(_.sizeInBytes.toLong).getOrElse(0L),
+ oldRowCount = table.stats.flatMap(_.rowCount.map(_.toLong)).getOrElse(-1L),
+ newTotalSize = logicalRel.relation.sizeInBytes)
case otherRelation =>
- throw new AnalysisException(s"ANALYZE TABLE is only supported for Hive tables, " +
- s"but '${tableIdent.unquotedString}' is a ${otherRelation.nodeName}.")
+ throw new AnalysisException(s"ANALYZE TABLE is not supported for " +
+ s"${otherRelation.nodeName}.")
}
+
+ def updateTableStats(
+ catalogTable: CatalogTable,
+ oldTotalSize: Long,
+ oldRowCount: Long,
+ newTotalSize: Long): Unit = {
+ var newStats: Option[Statistics] = None
+ if (newTotalSize > 0 && newTotalSize != oldTotalSize) {
+ newStats = Some(Statistics(sizeInBytes = newTotalSize))
--- End diff --
ok makes sense, but we should document this behaviour explicitly.
---
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 infrastructure@apache.org or file a JIRA ticket
with INFRA.
---
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org
[GitHub] spark issue #14712: [SPARK-17072] [SQL] support table-level statistics gener...
Posted by cloud-fan <gi...@git.apache.org>.
Github user cloud-fan commented on the issue:
https://github.com/apache/spark/pull/14712
LGTM, @hvanhovell can you take another look?
---
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 infrastructure@apache.org or file a JIRA ticket
with INFRA.
---
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org
[GitHub] spark pull request #14712: [SPARK-17072] [SQL] support table-level statistic...
Posted by wzhfy <gi...@git.apache.org>.
Github user wzhfy commented on a diff in the pull request:
https://github.com/apache/spark/pull/14712#discussion_r77306895
--- Diff: sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/catalog/interface.scala ---
@@ -130,6 +130,7 @@ case class CatalogTable(
createTime: Long = System.currentTimeMillis,
lastAccessTime: Long = -1,
properties: Map[String, String] = Map.empty,
+ stats: Option[Statistics] = None,
--- End diff --
@cloud-fan and also `LogicalRelation`?
---
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 infrastructure@apache.org or file a JIRA ticket
with INFRA.
---
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org
[GitHub] spark issue #14712: [SPARK-17072] [SQL] support table-level statistics gener...
Posted by AmplabJenkins <gi...@git.apache.org>.
Github user AmplabJenkins commented on the issue:
https://github.com/apache/spark/pull/14712
Test FAILed.
Refer to this link for build results (access rights to CI server needed):
https://amplab.cs.berkeley.edu/jenkins//job/SparkPullRequestBuilder/64709/
Test FAILed.
---
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 infrastructure@apache.org or file a JIRA ticket
with INFRA.
---
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org
[GitHub] spark pull request #14712: [SPARK-17072] [SQL] support table-level statistic...
Posted by hvanhovell <gi...@git.apache.org>.
Github user hvanhovell commented on a diff in the pull request:
https://github.com/apache/spark/pull/14712#discussion_r76251185
--- Diff: sql/core/src/main/scala/org/apache/spark/sql/execution/command/AnalyzeTableCommand.scala ---
@@ -88,14 +89,70 @@ case class AnalyzeTableCommand(tableName: String) extends RunnableCommand {
}
}.getOrElse(0L)
- // Update the Hive metastore if the total size of the table is different than the size
- // recorded in the Hive metastore.
- // This logic is based on org.apache.hadoop.hive.ql.exec.StatsTask.aggregateStats().
- if (newTotalSize > 0 && newTotalSize != oldTotalSize) {
+ var needUpdate = false
+ val totalSize = if (newTotalSize > 0 && newTotalSize != oldTotalSize) {
+ needUpdate = true
+ newTotalSize
+ } else {
+ oldTotalSize
+ }
+ var numRows: Option[BigInt] = None
+ if (!noscan) {
+ val oldRowCount: Long = if (catalogTable.catalogStats.isDefined) {
+ catalogTable.catalogStats.get.rowCount.map(_.toLong).getOrElse(-1L)
+ } else {
+ -1L
+ }
+ val newRowCount = sparkSession.table(tableName).count()
+ if (newRowCount >= 0 && newRowCount != oldRowCount) {
+ numRows = Some(BigInt(newRowCount))
+ needUpdate = true
+ }
+ }
+ // Update the metastore if the above statistics of the table are different from those
+ // recorded in the metastore.
+ if (needUpdate) {
+ sessionState.catalog.alterTable(
+ catalogTable.copy(
+ catalogStats = Some(Statistics(
+ sizeInBytes = totalSize, rowCount = numRows))),
+ fromAnalyze = true)
+
+ // Refresh the cache of the table in the catalog.
+ sessionState.catalog.refreshTable(tableIdent)
+ }
+
+ // data source tables have been converted into LogicalRelations
+ case logicalRel: LogicalRelation if logicalRel.metastoreTableIdentifier.isDefined =>
--- End diff --
This code path is unreachable. The `SessionCatalog` either returns a `SimpleRelation` or a `MetastoreRelation`.
---
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 infrastructure@apache.org or file a JIRA ticket
with INFRA.
---
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org
[GitHub] spark pull request #14712: [SPARK-17072] [SQL] support table-level statistic...
Posted by cloud-fan <gi...@git.apache.org>.
Github user cloud-fan commented on a diff in the pull request:
https://github.com/apache/spark/pull/14712#discussion_r75485564
--- Diff: sql/core/src/main/scala/org/apache/spark/sql/execution/datasources/LogicalRelation.scala ---
@@ -72,9 +72,12 @@ case class LogicalRelation(
// expId can be different but the relation is still the same.
override lazy val cleanArgs: Seq[Any] = Seq(relation)
- @transient override lazy val statistics: Statistics = Statistics(
- sizeInBytes = BigInt(relation.sizeInBytes)
- )
+ // statistics inherited from a MetastoreRelation
+ @transient var inheritedStats: Option[Statistics] = None
--- End diff --
This looks a little hacky. We are trying to support parquet/orc hive tables right? In that case `MetastoreRelation` will be converted to `LogicalRelation` and we will lost the statistics.
I think it's more reasonable to convert table relation to `LogicalRelation` in the planner, so that when we see the logical plan tree it's clearer that we are reading a table, and it's easier to get the statistics. `LogicalRelation` should only be used when reading data source files. This is out of the scope and we can do it in another PR.
For now, I'm ok to not support this case, as parquet/orc conversion for hive serde tables will be refatored soon.
cc @yhuai @hvanhovell
---
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 infrastructure@apache.org or file a JIRA ticket
with INFRA.
---
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org
[GitHub] spark pull request #14712: [SPARK-17072] [SQL] support table-level statistic...
Posted by gatorsmile <gi...@git.apache.org>.
Github user gatorsmile commented on a diff in the pull request:
https://github.com/apache/spark/pull/14712#discussion_r75540560
--- Diff: sql/core/src/main/scala/org/apache/spark/sql/execution/command/AnalyzeTableCommand.scala ---
@@ -88,14 +90,30 @@ case class AnalyzeTableCommand(tableName: String) extends RunnableCommand {
}
}.getOrElse(0L)
- // Update the Hive metastore if the total size of the table is different than the size
+ val needUpdate = new mutable.HashMap[String, String]()
+ if (newTotalSize > 0 && newTotalSize != oldTotalSize) {
+ needUpdate += (AnalyzeTableCommand.TOTAL_SIZE_FIELD -> newTotalSize.toString)
+ }
+ if (!noscan) {
+ val oldRowCount = tableParameters.get(AnalyzeTableCommand.ROW_COUNT).map(_.toLong)
+ .getOrElse(-1L)
+ val newRowCount = sparkSession.table(tableName).count()
+
+ if (newRowCount >= 0 && newRowCount != oldRowCount) {
+ needUpdate += (AnalyzeTableCommand.ROW_COUNT -> newRowCount.toString)
+ }
+ }
+ // Update the Hive metastore if the above parameters of the table is different than those
// recorded in the Hive metastore.
// This logic is based on org.apache.hadoop.hive.ql.exec.StatsTask.aggregateStats().
- if (newTotalSize > 0 && newTotalSize != oldTotalSize) {
+ if (needUpdate.nonEmpty) {
+ // need to set this parameter so that we can store other parameters like "numRows" into
+ // Hive metastore
+ needUpdate.put(AnalyzeTableCommand.STATS_GENERATED_VIA_STATS_TASK,
+ AnalyzeTableCommand.TRUE)
sessionState.catalog.alterTable(
catalogTable.copy(
- properties = relation.catalogTable.properties +
- (AnalyzeTableCommand.TOTAL_SIZE_FIELD -> newTotalSize.toString)))
+ properties = relation.catalogTable.properties ++ needUpdate))
--- End diff --
Just tried it in `Hive`.
When the `ALTER TABLE` command does not set `STATS_GENERATED_VIA_STATS_TASK`, the `COLUMN_STATS_ACCURATE` is set to `false`. For example,
```SQL
alter table t1 set TBLPROPERTIES ('numRows'='2');
```
The table properties will be like
```
Table Parameters:
COLUMN_STATS_ACCURATE false
last_modified_by root
last_modified_time 1471635353
numFiles 1
numRows -1
rawDataSize -1
totalSize 2
transient_lastDdlTime 1471635353
```
If we set `STATS_GENERATED_VIA_STATS_TASK` to `true`, `COLUMN_STATS_ACCURATE` will be `true`. For example,
```SQL
alter table t1 set TBLPROPERTIES ('numRows'='2', 'STATS_GENERATED_VIA_STATS_TASK'='true');
```
The results will be like
```
Table Parameters:
COLUMN_STATS_ACCURATE true
last_modified_by root
last_modified_time 1471635407
numFiles 1
numRows 2
rawDataSize -1
totalSize 2
transient_lastDdlTime 1471635407
```
```
---
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 infrastructure@apache.org or file a JIRA ticket
with INFRA.
---
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org
[GitHub] spark issue #14712: [SPARK-17072] [SQL] support table-level statistics gener...
Posted by wzhfy <gi...@git.apache.org>.
Github user wzhfy commented on the issue:
https://github.com/apache/spark/pull/14712
@gatorsmile Yes, we should exclude the staging dir.
---
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 infrastructure@apache.org or file a JIRA ticket
with INFRA.
---
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org
[GitHub] spark pull request #14712: [SPARK-17072] [SQL] support table-level statistic...
Posted by cloud-fan <gi...@git.apache.org>.
Github user cloud-fan commented on a diff in the pull request:
https://github.com/apache/spark/pull/14712#discussion_r76374046
--- Diff: sql/hive/src/main/scala/org/apache/spark/sql/hive/HiveExternalCatalog.scala ---
@@ -401,6 +401,13 @@ private[spark] class HiveExternalCatalog(conf: SparkConf, hadoopConf: Configurat
}
}
+ override def alterTableStats(tableDefinition: CatalogTable): Unit = withClient {
--- End diff --
what's the actual difference between `alterTable` and `alertTableStats`?
---
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 infrastructure@apache.org or file a JIRA ticket
with INFRA.
---
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org
[GitHub] spark issue #14712: [SPARK-17072] [SQL] support table-level statistics gener...
Posted by SparkQA <gi...@git.apache.org>.
Github user SparkQA commented on the issue:
https://github.com/apache/spark/pull/14712
**[Test build #64626 has finished](https://amplab.cs.berkeley.edu/jenkins/job/SparkPullRequestBuilder/64626/consoleFull)** for PR 14712 at commit [`7e39a86`](https://github.com/apache/spark/commit/7e39a86030e45f10ae0c171a475c054b7c208d20).
* This patch **fails Spark unit tests**.
* This patch merges cleanly.
* This patch adds no public classes.
---
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 infrastructure@apache.org or file a JIRA ticket
with INFRA.
---
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org
[GitHub] spark issue #14712: [SPARK-17072] [SQL] support table-level statistics gener...
Posted by AmplabJenkins <gi...@git.apache.org>.
Github user AmplabJenkins commented on the issue:
https://github.com/apache/spark/pull/14712
Merged build finished. Test PASSed.
---
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 infrastructure@apache.org or file a JIRA ticket
with INFRA.
---
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org
[GitHub] spark pull request #14712: [SPARK-17072] [SQL] support table-level statistic...
Posted by cloud-fan <gi...@git.apache.org>.
Github user cloud-fan commented on a diff in the pull request:
https://github.com/apache/spark/pull/14712#discussion_r77304066
--- Diff: sql/core/src/main/scala/org/apache/spark/sql/execution/command/AnalyzeTableCommand.scala ---
@@ -88,24 +85,54 @@ case class AnalyzeTableCommand(tableName: String) extends RunnableCommand {
}
}.getOrElse(0L)
- // Update the Hive metastore if the total size of the table is different than the size
- // recorded in the Hive metastore.
- // This logic is based on org.apache.hadoop.hive.ql.exec.StatsTask.aggregateStats().
- if (newTotalSize > 0 && newTotalSize != oldTotalSize) {
- sessionState.catalog.alterTable(
- catalogTable.copy(
- properties = relation.catalogTable.properties +
- (AnalyzeTableCommand.TOTAL_SIZE_FIELD -> newTotalSize.toString)))
- }
+ updateTableStats(
+ catalogTable,
+ oldTotalSize = catalogTable.stats.map(_.sizeInBytes.toLong).getOrElse(0L),
+ oldRowCount = catalogTable.stats.flatMap(_.rowCount.map(_.toLong)).getOrElse(-1L),
+ newTotalSize = newTotalSize)
+
+ // data source tables have been converted into LogicalRelations
+ case logicalRel: LogicalRelation if logicalRel.catalogTable.isDefined =>
+ val table = logicalRel.catalogTable.get
+ updateTableStats(
+ table,
+ oldTotalSize = table.stats.map(_.sizeInBytes.toLong).getOrElse(0L),
+ oldRowCount = table.stats.flatMap(_.rowCount.map(_.toLong)).getOrElse(-1L),
+ newTotalSize = logicalRel.relation.sizeInBytes)
case otherRelation =>
- throw new AnalysisException(s"ANALYZE TABLE is only supported for Hive tables, " +
- s"but '${tableIdent.unquotedString}' is a ${otherRelation.nodeName}.")
+ throw new AnalysisException(s"ANALYZE TABLE is not supported for " +
+ s"${otherRelation.nodeName}.")
}
+
+ def updateTableStats(
+ catalogTable: CatalogTable,
+ oldTotalSize: Long,
+ oldRowCount: Long,
+ newTotalSize: Long): Unit = {
+ var newStats: Option[Statistics] = None
+ if (newTotalSize > 0 && newTotalSize != oldTotalSize) {
+ newStats = Some(Statistics(sizeInBytes = newTotalSize))
--- End diff --
if we run `ANALYZE TABLE` first, and then run `ANALYZE TABLE NOSCAN` immediately, the row count will be removed. Does it make sense? The row count is still valid for this case
---
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 infrastructure@apache.org or file a JIRA ticket
with INFRA.
---
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org
[GitHub] spark pull request #14712: [SPARK-17072] [SQL] support table-level statistic...
Posted by hvanhovell <gi...@git.apache.org>.
Github user hvanhovell commented on a diff in the pull request:
https://github.com/apache/spark/pull/14712#discussion_r75501043
--- Diff: sql/core/src/main/scala/org/apache/spark/sql/execution/SparkSqlParser.scala ---
@@ -99,9 +99,7 @@ class SparkSqlAstBuilder(conf: SQLConf) extends AstBuilder {
ctx.identifier.getText.toLowerCase == "noscan") {
--- End diff --
Yeah there are. AFAIK we will also support column level statistics.
---
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 infrastructure@apache.org or file a JIRA ticket
with INFRA.
---
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org
[GitHub] spark issue #14712: [SPARK-17072] [SQL] support table-level statistics gener...
Posted by gatorsmile <gi...@git.apache.org>.
Github user gatorsmile commented on the issue:
https://github.com/apache/spark/pull/14712
Found another related JIRA: https://issues.apache.org/jira/browse/HIVE-12730. This is only available in Hive 2.1. They are trying to resolve the issues we hit:
> We would like to provide a way for developers/users to modify the numRows and dataSize for a table/partition. Right now although they are part of the table properties, they will be set to -1 when the task is not coming from a statsTask.
Now, users can change the statistics by the DDL statement. For example,
```SQL
alter table s update statistics set('numRows'='1212', 'rawDataSize'='500500');
```
More important, after this fix, what we did in this PR does not work. `STATS_GENERATED_VIA_STATS_TASK` is not available. Instead, they changed it to `STATS_GENERATED`. Two options are availabel: `TASK` and `USER`.
Thus, I believe our solution should not be based on how Hive behaves, if possible.
---
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 infrastructure@apache.org or file a JIRA ticket
with INFRA.
---
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org
[GitHub] spark issue #14712: [SPARK-17072] [SQL] support table-level statistics gener...
Posted by AmplabJenkins <gi...@git.apache.org>.
Github user AmplabJenkins commented on the issue:
https://github.com/apache/spark/pull/14712
Merged build finished. Test PASSed.
---
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 infrastructure@apache.org or file a JIRA ticket
with INFRA.
---
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org
[GitHub] spark pull request #14712: [SPARK-17072] [SQL] support table-level statistic...
Posted by wzhfy <gi...@git.apache.org>.
Github user wzhfy commented on a diff in the pull request:
https://github.com/apache/spark/pull/14712#discussion_r75569106
--- Diff: sql/core/src/main/scala/org/apache/spark/sql/execution/command/AnalyzeTableCommand.scala ---
@@ -88,14 +90,30 @@ case class AnalyzeTableCommand(tableName: String) extends RunnableCommand {
}
}.getOrElse(0L)
- // Update the Hive metastore if the total size of the table is different than the size
+ val needUpdate = new mutable.HashMap[String, String]()
+ if (newTotalSize > 0 && newTotalSize != oldTotalSize) {
+ needUpdate += (AnalyzeTableCommand.TOTAL_SIZE_FIELD -> newTotalSize.toString)
+ }
+ if (!noscan) {
+ val oldRowCount = tableParameters.get(AnalyzeTableCommand.ROW_COUNT).map(_.toLong)
+ .getOrElse(-1L)
+ val newRowCount = sparkSession.table(tableName).count()
+
+ if (newRowCount >= 0 && newRowCount != oldRowCount) {
+ needUpdate += (AnalyzeTableCommand.ROW_COUNT -> newRowCount.toString)
+ }
+ }
+ // Update the Hive metastore if the above parameters of the table is different than those
// recorded in the Hive metastore.
// This logic is based on org.apache.hadoop.hive.ql.exec.StatsTask.aggregateStats().
- if (newTotalSize > 0 && newTotalSize != oldTotalSize) {
+ if (needUpdate.nonEmpty) {
+ // need to set this parameter so that we can store other parameters like "numRows" into
+ // Hive metastore
+ needUpdate.put(AnalyzeTableCommand.STATS_GENERATED_VIA_STATS_TASK,
--- End diff --
If we don't set this parameter, "numRows" can not be stored into Hive metastore. We need to do this in Spark so that we can persist our statistics in metastore.
---
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 infrastructure@apache.org or file a JIRA ticket
with INFRA.
---
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org
[GitHub] spark pull request #14712: [SPARK-17072] [SQL] support table-level statistic...
Posted by wzhfy <gi...@git.apache.org>.
Github user wzhfy commented on a diff in the pull request:
https://github.com/apache/spark/pull/14712#discussion_r76931629
--- Diff: sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/catalog/SessionCatalog.scala ---
@@ -235,14 +235,18 @@ class SessionCatalog(
* Note: If the underlying implementation does not support altering a certain field,
* this becomes a no-op.
*/
- def alterTable(tableDefinition: CatalogTable): Unit = {
+ def alterTable(tableDefinition: CatalogTable, fromAnalyze: Boolean = false): Unit = {
--- End diff --
I'll fix this, thank you
---
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 infrastructure@apache.org or file a JIRA ticket
with INFRA.
---
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org
[GitHub] spark pull request #14712: [SPARK-17072] [SQL] support table-level statistic...
Posted by hvanhovell <gi...@git.apache.org>.
Github user hvanhovell commented on a diff in the pull request:
https://github.com/apache/spark/pull/14712#discussion_r75436727
--- Diff: sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/plans/logical/LogicalPlan.scala ---
@@ -95,6 +95,12 @@ abstract class LogicalPlan extends QueryPlan[LogicalPlan] with Logging {
}
/**
+ * Estimate complete [[Statistics]] for this plan. Each plan need to override this to get
+ * complete statistics.
+ */
+ def completeStats: Statistics = statistics
--- End diff --
What is the difference with the other statistics field? Could you give an example?
---
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 infrastructure@apache.org or file a JIRA ticket
with INFRA.
---
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org
[GitHub] spark pull request #14712: [SPARK-17072] [SQL] support table-level statistic...
Posted by hvanhovell <gi...@git.apache.org>.
Github user hvanhovell commented on a diff in the pull request:
https://github.com/apache/spark/pull/14712#discussion_r75601984
--- Diff: sql/hive/src/main/scala/org/apache/spark/sql/hive/MetastoreRelation.scala ---
@@ -141,7 +142,16 @@ private[hive] case class MetastoreRelation(
sparkSession.sessionState.conf.defaultSizeInBytes
})
}
- )
+ val tableParams = hiveQlTable.getParameters
+ val rowCount = tableParams.get(AnalyzeTableCommand.ROW_COUNT)
+ if (rowCount != null && rowCount.toLong >=0) {
--- End diff --
Keeping it is fine.
---
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 infrastructure@apache.org or file a JIRA ticket
with INFRA.
---
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org
[GitHub] spark pull request #14712: [SPARK-17072] [SQL] support table-level statistic...
Posted by viirya <gi...@git.apache.org>.
Github user viirya commented on a diff in the pull request:
https://github.com/apache/spark/pull/14712#discussion_r77108572
--- Diff: sql/core/src/main/scala/org/apache/spark/sql/execution/datasources/LogicalRelation.scala ---
@@ -72,9 +73,11 @@ case class LogicalRelation(
// expId can be different but the relation is still the same.
override lazy val cleanArgs: Seq[Any] = Seq(relation)
- @transient override lazy val statistics: Statistics = Statistics(
- sizeInBytes = BigInt(relation.sizeInBytes)
- )
+ // inheritedStats is inherited from a CatalogRelation
--- End diff --
The comment is not correct now.
---
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 infrastructure@apache.org or file a JIRA ticket
with INFRA.
---
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org
[GitHub] spark issue #14712: [SPARK-17072] [SQL] support table-level statistics gener...
Posted by AmplabJenkins <gi...@git.apache.org>.
Github user AmplabJenkins commented on the issue:
https://github.com/apache/spark/pull/14712
Merged build finished. Test FAILed.
---
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 infrastructure@apache.org or file a JIRA ticket
with INFRA.
---
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org
[GitHub] spark issue #14712: [SPARK-17072] [SQL] support table-level statistics gener...
Posted by yhuai <gi...@git.apache.org>.
Github user yhuai commented on the issue:
https://github.com/apache/spark/pull/14712
I have created https://issues.apache.org/jira/browse/SPARK-17408. @wzhfy Can you take a look?
---
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 infrastructure@apache.org or file a JIRA ticket
with INFRA.
---
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org
[GitHub] spark issue #14712: [SPARK-17072] [SQL] support table-level statistics gener...
Posted by SparkQA <gi...@git.apache.org>.
Github user SparkQA commented on the issue:
https://github.com/apache/spark/pull/14712
**[Test build #64789 has started](https://amplab.cs.berkeley.edu/jenkins/job/SparkPullRequestBuilder/64789/consoleFull)** for PR 14712 at commit [`b6c655a`](https://github.com/apache/spark/commit/b6c655a176c313aa8aa055ef985401f78557e4ec).
---
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 infrastructure@apache.org or file a JIRA ticket
with INFRA.
---
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org
[GitHub] spark issue #14712: [SPARK-17072] [SQL] support table-level statistics gener...
Posted by AmplabJenkins <gi...@git.apache.org>.
Github user AmplabJenkins commented on the issue:
https://github.com/apache/spark/pull/14712
Merged build finished. Test FAILed.
---
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 infrastructure@apache.org or file a JIRA ticket
with INFRA.
---
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org
[GitHub] spark issue #14712: [SPARK-17072] [SQL] support table-level statistics gener...
Posted by gatorsmile <gi...@git.apache.org>.
Github user gatorsmile commented on the issue:
https://github.com/apache/spark/pull/14712
Since you are added to the white list, you can trigger the test by yourself. Below is the command you can use:
- "ok to test" to accept this pull request for testing
- "test this please" for a one time test run
- If the build fails for other various reasons you can rebuild. "retest this please" to start a new build
---
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 infrastructure@apache.org or file a JIRA ticket
with INFRA.
---
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org
[GitHub] spark pull request #14712: [SPARK-17072] [SQL] support table-level statistic...
Posted by wzhfy <gi...@git.apache.org>.
Github user wzhfy commented on a diff in the pull request:
https://github.com/apache/spark/pull/14712#discussion_r77119270
--- Diff: sql/core/src/main/scala/org/apache/spark/sql/execution/datasources/LogicalRelation.scala ---
@@ -72,9 +73,11 @@ case class LogicalRelation(
// expId can be different but the relation is still the same.
override lazy val cleanArgs: Seq[Any] = Seq(relation)
- @transient override lazy val statistics: Statistics = Statistics(
- sizeInBytes = BigInt(relation.sizeInBytes)
- )
+ // inheritedStats is inherited from a CatalogRelation
--- End diff --
Thanks, I'll remove it
---
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 infrastructure@apache.org or file a JIRA ticket
with INFRA.
---
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org
[GitHub] spark issue #14712: [SPARK-17072] [SQL] support table-level statistics gener...
Posted by SparkQA <gi...@git.apache.org>.
Github user SparkQA commented on the issue:
https://github.com/apache/spark/pull/14712
**[Test build #64789 has finished](https://amplab.cs.berkeley.edu/jenkins/job/SparkPullRequestBuilder/64789/consoleFull)** for PR 14712 at commit [`b6c655a`](https://github.com/apache/spark/commit/b6c655a176c313aa8aa055ef985401f78557e4ec).
* This patch passes all tests.
* This patch merges cleanly.
* This patch adds no public classes.
---
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 infrastructure@apache.org or file a JIRA ticket
with INFRA.
---
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org
[GitHub] spark pull request #14712: [SPARK-17072] [SQL] support table-level statistic...
Posted by wzhfy <gi...@git.apache.org>.
Github user wzhfy commented on a diff in the pull request:
https://github.com/apache/spark/pull/14712#discussion_r76545213
--- Diff: sql/core/src/main/scala/org/apache/spark/sql/execution/datasources/DataSourceStrategy.scala ---
@@ -207,9 +207,11 @@ class FindDataSourceTable(sparkSession: SparkSession) extends Rule[LogicalPlan]
className = table.provider.get,
options = table.storage.properties)
- LogicalRelation(
+ val logicalRel = LogicalRelation(
dataSource.resolveRelation(),
metastoreTableIdentifier = Some(table.identifier))
+ logicalRel.inheritedStats = table.catalogStats
--- End diff --
Do you mean adding statistics as a constructor parameter in LogicalRelation? I tried this in my first implementation, but many code paths needed to be fixed (pattern match like LogicalRelation(src: BaseRelation, _, _)). I'll switch back if that's ok.
---
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 infrastructure@apache.org or file a JIRA ticket
with INFRA.
---
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org
[GitHub] spark pull request #14712: [SPARK-17072] [SQL] support table-level statistic...
Posted by gatorsmile <gi...@git.apache.org>.
Github user gatorsmile commented on a diff in the pull request:
https://github.com/apache/spark/pull/14712#discussion_r76920340
--- Diff: sql/hive/src/test/scala/org/apache/spark/sql/hive/StatisticsSuite.scala ---
@@ -168,6 +169,81 @@ class StatisticsSuite extends QueryTest with TestHiveSingleton with SQLTestUtils
TableIdentifier("tempTable"), ignoreIfNotExists = true, purge = false)
}
+ private def checkMetastoreRelationStats(
+ tableName: String,
+ totalSize: Long,
+ rowCount: Option[BigInt]): Unit = {
+ val df = sql(s"SELECT * FROM $tableName")
+ val relations = df.queryExecution.analyzed.collect { case rel: MetastoreRelation =>
+ rel.statistics
+ assert(rel.statistics.sizeInBytes === totalSize)
+ assert(rel.statistics.rowCount === rowCount)
+ }
+ assert(relations.size === 1)
+ }
+
+ private def checkLogicalRelationStats(tableName: String, rowCount: Option[BigInt]): Unit = {
+ val df = sql(s"SELECT * FROM $tableName")
+ val relations = df.queryExecution.analyzed.collect { case rel: LogicalRelation =>
+ assert(rel.statistics.sizeInBytes === rel.relation.sizeInBytes)
+ assert(rel.statistics.rowCount === rowCount)
+ }
+ assert(relations.size === 1)
+ }
+
+ test("test table-level statistics for hive tables created in HiveExternalCatalog") {
--- End diff --
Can you split the test case to multiple smaller independent ones?
---
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 infrastructure@apache.org or file a JIRA ticket
with INFRA.
---
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org
[GitHub] spark pull request #14712: [SPARK-17072] [SQL] support table-level statistic...
Posted by wzhfy <gi...@git.apache.org>.
Github user wzhfy commented on a diff in the pull request:
https://github.com/apache/spark/pull/14712#discussion_r76388064
--- Diff: sql/hive/src/main/scala/org/apache/spark/sql/hive/client/HiveClientImpl.scala ---
@@ -427,6 +430,44 @@ private[hive] class HiveClientImpl(
client.alterTable(qualifiedTableName, hiveTable)
}
+ override def alterTableStats(table: CatalogTable): Unit = withHiveState {
--- End diff --
Based on this, we should move alterTableStats to `HiveExternalCatalog`, and still keep constructStatsFromHive in `HiveClientImpl`, 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 infrastructure@apache.org or file a JIRA ticket
with INFRA.
---
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org
[GitHub] spark issue #14712: [SPARK-17072] [SQL] support table-level statistics gener...
Posted by SparkQA <gi...@git.apache.org>.
Github user SparkQA commented on the issue:
https://github.com/apache/spark/pull/14712
**[Test build #64459 has started](https://amplab.cs.berkeley.edu/jenkins/job/SparkPullRequestBuilder/64459/consoleFull)** for PR 14712 at commit [`aee4139`](https://github.com/apache/spark/commit/aee4139031b283e95bf0ef9ae6488c3396909ec4).
---
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 infrastructure@apache.org or file a JIRA ticket
with INFRA.
---
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org
[GitHub] spark issue #14712: [SPARK-17072] [SQL] support table-level statistics gener...
Posted by viirya <gi...@git.apache.org>.
Github user viirya commented on the issue:
https://github.com/apache/spark/pull/14712
yeah I think we should focus in the top priority target in this pr. And the hive related translation can be addressed in later prs.
---
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 infrastructure@apache.org or file a JIRA ticket
with INFRA.
---
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org
[GitHub] spark issue #14712: [SPARK-17072] [SQL] support table-level statistics gener...
Posted by cloud-fan <gi...@git.apache.org>.
Github user cloud-fan commented on the issue:
https://github.com/apache/spark/pull/14712
retest this please
---
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 infrastructure@apache.org or file a JIRA ticket
with INFRA.
---
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org
[GitHub] spark pull request #14712: [SPARK-17072] [SQL] support table-level statistic...
Posted by viirya <gi...@git.apache.org>.
Github user viirya commented on a diff in the pull request:
https://github.com/apache/spark/pull/14712#discussion_r76930682
--- Diff: sql/hive/src/main/scala/org/apache/spark/sql/hive/MetastoreRelation.scala ---
@@ -140,7 +145,12 @@ private[hive] case class MetastoreRelation(
sparkSession.sessionState.conf.defaultSizeInBytes
})
}
- )
+ if (catalogTable.catalogStats.isDefined) {
--- End diff --
We can skip the above computation of `sizeInBytes` if `catalogStats` is defined.
---
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 infrastructure@apache.org or file a JIRA ticket
with INFRA.
---
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org
[GitHub] spark issue #14712: [SPARK-17072] [SQL] support table-level statistics gener...
Posted by gatorsmile <gi...@git.apache.org>.
Github user gatorsmile commented on the issue:
https://github.com/apache/spark/pull/14712
What is our CBO plan for data source tables? Is it implemented in the prototype? It is not mentioned in the design doc. If we want to support `InMemoryCatalog`, we need to provide the support now.
---
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 infrastructure@apache.org or file a JIRA ticket
with INFRA.
---
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org
[GitHub] spark issue #14712: [SPARK-17072] [SQL] support table-level statistics gener...
Posted by SparkQA <gi...@git.apache.org>.
Github user SparkQA commented on the issue:
https://github.com/apache/spark/pull/14712
**[Test build #64750 has finished](https://amplab.cs.berkeley.edu/jenkins/job/SparkPullRequestBuilder/64750/consoleFull)** for PR 14712 at commit [`aa438c4`](https://github.com/apache/spark/commit/aa438c43f78d5edd679fd3e6294d953181a40268).
* This patch passes all tests.
* This patch merges cleanly.
* This patch adds no public classes.
---
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 infrastructure@apache.org or file a JIRA ticket
with INFRA.
---
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org
[GitHub] spark pull request #14712: [SPARK-17072] [SQL] support table-level statistic...
Posted by hvanhovell <gi...@git.apache.org>.
Github user hvanhovell commented on a diff in the pull request:
https://github.com/apache/spark/pull/14712#discussion_r75500405
--- Diff: sql/hive/src/main/scala/org/apache/spark/sql/hive/MetastoreRelation.scala ---
@@ -141,7 +142,16 @@ private[hive] case class MetastoreRelation(
sparkSession.sessionState.conf.defaultSizeInBytes
})
}
- )
+ val tableParams = hiveQlTable.getParameters
+ val rowCount = tableParams.get(AnalyzeTableCommand.ROW_COUNT)
+ if (rowCount != null && rowCount.toLong >=0) {
--- End diff --
`Statistics(sizeInBytes, Some(sizeInBytes), Option(rowCount).map(_.toLong))` is shorter than this if-else block.
---
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 infrastructure@apache.org or file a JIRA ticket
with INFRA.
---
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org
[GitHub] spark pull request #14712: [SPARK-17072] [SQL] support table-level statistic...
Posted by cloud-fan <gi...@git.apache.org>.
Github user cloud-fan commented on a diff in the pull request:
https://github.com/apache/spark/pull/14712#discussion_r77301097
--- Diff: sql/core/src/main/scala/org/apache/spark/sql/execution/command/AnalyzeTableCommand.scala ---
@@ -88,24 +85,54 @@ case class AnalyzeTableCommand(tableName: String) extends RunnableCommand {
}
}.getOrElse(0L)
- // Update the Hive metastore if the total size of the table is different than the size
- // recorded in the Hive metastore.
- // This logic is based on org.apache.hadoop.hive.ql.exec.StatsTask.aggregateStats().
- if (newTotalSize > 0 && newTotalSize != oldTotalSize) {
- sessionState.catalog.alterTable(
- catalogTable.copy(
- properties = relation.catalogTable.properties +
- (AnalyzeTableCommand.TOTAL_SIZE_FIELD -> newTotalSize.toString)))
- }
+ updateTableStats(
+ catalogTable,
+ oldTotalSize = catalogTable.stats.map(_.sizeInBytes.toLong).getOrElse(0L),
+ oldRowCount = catalogTable.stats.flatMap(_.rowCount.map(_.toLong)).getOrElse(-1L),
+ newTotalSize = newTotalSize)
+
+ // data source tables have been converted into LogicalRelations
+ case logicalRel: LogicalRelation if logicalRel.catalogTable.isDefined =>
+ val table = logicalRel.catalogTable.get
+ updateTableStats(
+ table,
+ oldTotalSize = table.stats.map(_.sizeInBytes.toLong).getOrElse(0L),
+ oldRowCount = table.stats.flatMap(_.rowCount.map(_.toLong)).getOrElse(-1L),
--- End diff --
so we always calculate `oldTotalSize` and `oldRowCount` by reading the `stats` field in `CatalogTable`, I think `updateTableStats` only need to take one parameter, the `CatalogTable`, and we can calculate `oldTotalSize` and `oldRowCount` in the method.
---
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 infrastructure@apache.org or file a JIRA ticket
with INFRA.
---
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org
[GitHub] spark pull request #14712: [SPARK-17072] [SQL] support table-level statistic...
Posted by wzhfy <gi...@git.apache.org>.
Github user wzhfy commented on a diff in the pull request:
https://github.com/apache/spark/pull/14712#discussion_r77308279
--- Diff: sql/hive/src/main/scala/org/apache/spark/sql/hive/HiveExternalCatalog.scala ---
@@ -383,21 +384,34 @@ private[spark] class HiveExternalCatalog(conf: SparkConf, hadoopConf: Configurat
requireTableExists(db, tableDefinition.identifier.table)
verifyTableProperties(tableDefinition)
- if (DDLUtils.isDatasourceTable(tableDefinition)) {
- val oldDef = client.getTable(db, tableDefinition.identifier.table)
+ // convert table statistics to properties so that we can persist them through hive api
+ val catalogTable = if (tableDefinition.stats.isDefined) {
--- End diff --
@cloud-fan this may cause an unnecessary copy for hive table when `tableDefinition.stats` is empty
---
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 infrastructure@apache.org or file a JIRA ticket
with INFRA.
---
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org
[GitHub] spark issue #14712: [SPARK-17072] [SQL] support table-level statistics gener...
Posted by AmplabJenkins <gi...@git.apache.org>.
Github user AmplabJenkins commented on the issue:
https://github.com/apache/spark/pull/14712
Merged build finished. Test FAILed.
---
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 infrastructure@apache.org or file a JIRA ticket
with INFRA.
---
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org
[GitHub] spark issue #14712: [SPARK-17072] [SQL] support table-level statistics gener...
Posted by SparkQA <gi...@git.apache.org>.
Github user SparkQA commented on the issue:
https://github.com/apache/spark/pull/14712
**[Test build #64641 has finished](https://amplab.cs.berkeley.edu/jenkins/job/SparkPullRequestBuilder/64641/consoleFull)** for PR 14712 at commit [`aef78d4`](https://github.com/apache/spark/commit/aef78d4bffac4dad99d1646c659e626a4eccb26b).
* This patch passes all tests.
* This patch merges cleanly.
* This patch adds no public classes.
---
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 infrastructure@apache.org or file a JIRA ticket
with INFRA.
---
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org
[GitHub] spark pull request #14712: [SPARK-17072] [SQL] support table-level statistic...
Posted by wzhfy <gi...@git.apache.org>.
Github user wzhfy commented on a diff in the pull request:
https://github.com/apache/spark/pull/14712#discussion_r76921301
--- Diff: sql/core/src/main/scala/org/apache/spark/sql/execution/datasources/LogicalRelation.scala ---
@@ -33,7 +33,8 @@ import org.apache.spark.util.Utils
case class LogicalRelation(
relation: BaseRelation,
expectedOutputAttributes: Option[Seq[Attribute]] = None,
- metastoreTableIdentifier: Option[TableIdentifier] = None)
+ metastoreTableIdentifier: Option[TableIdentifier] = None,
+ inheritedStats: Option[Statistics] = None)
--- End diff --
it uses catalogStats of CatalogTable in MetastoreRelation
---
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 infrastructure@apache.org or file a JIRA ticket
with INFRA.
---
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org
[GitHub] spark pull request #14712: [SPARK-17072] [SQL] support table-level statistic...
Posted by cloud-fan <gi...@git.apache.org>.
Github user cloud-fan commented on a diff in the pull request:
https://github.com/apache/spark/pull/14712#discussion_r77572880
--- Diff: sql/hive/src/test/scala/org/apache/spark/sql/hive/StatisticsSuite.scala ---
@@ -168,6 +171,154 @@ class StatisticsSuite extends QueryTest with TestHiveSingleton with SQLTestUtils
TableIdentifier("tempTable"), ignoreIfNotExists = true, purge = false)
}
+ private def checkMetastoreRelationStats(
+ tableName: String,
+ expectedStats: Option[Statistics]): Unit = {
+ val df = sql(s"SELECT * FROM $tableName")
+ val relations = df.queryExecution.analyzed.collect { case rel: MetastoreRelation =>
+ expectedStats match {
+ case Some(es) =>
+ assert(rel.catalogTable.stats.isDefined)
+ val stats = rel.catalogTable.stats.get
+ assert(stats.sizeInBytes === es.sizeInBytes)
+ assert(stats.rowCount === es.rowCount)
+ case None =>
+ assert(rel.catalogTable.stats.isEmpty)
+ }
+ rel
+ }
+ assert(relations.size === 1)
+ }
+
+ test("test table-level statistics for hive tables created in HiveExternalCatalog") {
+ val textTable = "textTable"
+ withTable(textTable) {
+ // Currently Spark's statistics are self-contained, we don't have statistics until we use
+ // the `ANALYZE TABLE` command.
+ sql(s"CREATE TABLE $textTable (key STRING, value STRING) STORED AS TEXTFILE")
+ checkMetastoreRelationStats(textTable, expectedStats = None)
+ sql(s"INSERT INTO TABLE $textTable SELECT * FROM src")
+ checkMetastoreRelationStats(textTable, expectedStats = None)
+
+ // noscan won't count the number of rows
+ sql(s"ANALYZE TABLE $textTable COMPUTE STATISTICS noscan")
+ checkMetastoreRelationStats(textTable, expectedStats =
+ Some(Statistics(sizeInBytes = 5812, rowCount = None)))
--- End diff --
sorry I missed this, we should avoid hardcode nondeterministic values(like file size) in test, for this case, we only need to make sure the first `sizeInBytes` is greater than 0, and the second `sizeInBytes` is equal to the first one.
---
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 infrastructure@apache.org or file a JIRA ticket
with INFRA.
---
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org
[GitHub] spark issue #14712: [SPARK-17072] [SQL] support table-level statistics gener...
Posted by wzhfy <gi...@git.apache.org>.
Github user wzhfy commented on the issue:
https://github.com/apache/spark/pull/14712
@cloud-fan Can you please launch test for this pr? thanks!
---
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 infrastructure@apache.org or file a JIRA ticket
with INFRA.
---
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org
[GitHub] spark pull request #14712: [SPARK-17072] [SQL] support table-level statistic...
Posted by gatorsmile <gi...@git.apache.org>.
Github user gatorsmile commented on a diff in the pull request:
https://github.com/apache/spark/pull/14712#discussion_r75573560
--- Diff: sql/core/src/main/scala/org/apache/spark/sql/execution/datasources/LogicalRelation.scala ---
@@ -72,9 +72,12 @@ case class LogicalRelation(
// expId can be different but the relation is still the same.
override lazy val cleanArgs: Seq[Any] = Seq(relation)
- @transient override lazy val statistics: Statistics = Statistics(
- sizeInBytes = BigInt(relation.sizeInBytes)
- )
+ // statistics inherited from a MetastoreRelation
+ @transient var inheritedStats: Option[Statistics] = None
--- End diff --
This is not a bug in your PR. Let me fix it in a separate PR and then you can focus on the major goal of this PR.
---
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 infrastructure@apache.org or file a JIRA ticket
with INFRA.
---
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org
[GitHub] spark pull request #14712: [SPARK-17072] [SQL] support table-level statistic...
Posted by gatorsmile <gi...@git.apache.org>.
Github user gatorsmile commented on a diff in the pull request:
https://github.com/apache/spark/pull/14712#discussion_r76926260
--- Diff: sql/hive/src/test/scala/org/apache/spark/sql/hive/StatisticsSuite.scala ---
@@ -168,6 +169,81 @@ class StatisticsSuite extends QueryTest with TestHiveSingleton with SQLTestUtils
TableIdentifier("tempTable"), ignoreIfNotExists = true, purge = false)
}
+ private def checkMetastoreRelationStats(
+ tableName: String,
+ totalSize: Long,
+ rowCount: Option[BigInt]): Unit = {
+ val df = sql(s"SELECT * FROM $tableName")
+ val relations = df.queryExecution.analyzed.collect { case rel: MetastoreRelation =>
+ rel.statistics
+ assert(rel.statistics.sizeInBytes === totalSize)
+ assert(rel.statistics.rowCount === rowCount)
+ }
+ assert(relations.size === 1)
+ }
+
+ private def checkLogicalRelationStats(tableName: String, rowCount: Option[BigInt]): Unit = {
+ val df = sql(s"SELECT * FROM $tableName")
+ val relations = df.queryExecution.analyzed.collect { case rel: LogicalRelation =>
+ assert(rel.statistics.sizeInBytes === rel.relation.sizeInBytes)
--- End diff --
If this is the reason, you need to leave a TODO task in the code. Otherwise, we might forget it.
---
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 infrastructure@apache.org or file a JIRA ticket
with INFRA.
---
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org
[GitHub] spark issue #14712: [SPARK-17072] [SQL] support table-level statistics gener...
Posted by SparkQA <gi...@git.apache.org>.
Github user SparkQA commented on the issue:
https://github.com/apache/spark/pull/14712
**[Test build #64886 has finished](https://amplab.cs.berkeley.edu/jenkins/job/SparkPullRequestBuilder/64886/consoleFull)** for PR 14712 at commit [`5d6e559`](https://github.com/apache/spark/commit/5d6e5599b558512000f3f62349276ebf19be366a).
* This patch passes all tests.
* This patch merges cleanly.
* This patch adds no public classes.
---
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 infrastructure@apache.org or file a JIRA ticket
with INFRA.
---
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org
[GitHub] spark pull request #14712: [SPARK-17072] [SQL] support table-level statistic...
Posted by rxin <gi...@git.apache.org>.
Github user rxin commented on a diff in the pull request:
https://github.com/apache/spark/pull/14712#discussion_r75436918
--- Diff: sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/plans/logical/LogicalPlan.scala ---
@@ -95,6 +95,12 @@ abstract class LogicalPlan extends QueryPlan[LogicalPlan] with Logging {
}
/**
+ * Estimate complete [[Statistics]] for this plan. Each plan need to override this to get
+ * complete statistics.
+ */
+ def completeStats: Statistics = statistics
--- End diff --
why not just use the existing statistics field?
---
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 infrastructure@apache.org or file a JIRA ticket
with INFRA.
---
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org
[GitHub] spark pull request #14712: [SPARK-17072] [SQL] support table-level statistic...
Posted by gatorsmile <gi...@git.apache.org>.
Github user gatorsmile commented on a diff in the pull request:
https://github.com/apache/spark/pull/14712#discussion_r75550523
--- Diff: sql/hive/src/main/scala/org/apache/spark/sql/hive/MetastoreRelation.scala ---
@@ -141,7 +142,16 @@ private[hive] case class MetastoreRelation(
sparkSession.sessionState.conf.defaultSizeInBytes
})
}
- )
+ val tableParams = hiveQlTable.getParameters
+ val rowCount = tableParams.get(AnalyzeTableCommand.ROW_COUNT)
+ if (rowCount != null && rowCount.toLong >=0) {
+ // TODO: we will compute the 'real' total size when we have column stats:
+ // average size of row * number of rows
+ Statistics(sizeInBytes, Some(sizeInBytes), Some(rowCount.toLong))
--- End diff --
They are having the same types. Thus, a better way is
```Scala
Statistics(sizeInBytes, estimatedSize = Some(sizeInBytes), rowCount = Some(rowCount.toLong))
```
---
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 infrastructure@apache.org or file a JIRA ticket
with INFRA.
---
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org
[GitHub] spark issue #14712: [SPARK-17072] [SQL] support table-level statistics gener...
Posted by gatorsmile <gi...@git.apache.org>.
Github user gatorsmile commented on the issue:
https://github.com/apache/spark/pull/14712
@wzhfy I am kind of worried about the dependency of Hive metastore.
- Using the same table property names like Hive: Hive metastore could change them in an unexpected way (for example, by a Hive metastore bug). The behaviors might be different in different metastore versions. However, the statistics can be shared by Hive execution and Spark execution. Thus, it could benefit the Spark users who are using Hive and Spark together on the same set of tables.
- Using the different names, like what we did for data source table schema: Spark fully controls them and we just treat the Hive metastore as a persistent storage of these statistics.
- Provided a configuration parameter so that users can control which option they preferred?
This is a design decision we need to make. @rxin @yhuai @hvanhovell @liancheng @cloud-fan @clockfly
---
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 infrastructure@apache.org or file a JIRA ticket
with INFRA.
---
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org
[GitHub] spark pull request #14712: [SPARK-17072] [SQL] support table-level statistic...
Posted by viirya <gi...@git.apache.org>.
Github user viirya commented on a diff in the pull request:
https://github.com/apache/spark/pull/14712#discussion_r75572040
--- Diff: sql/hive/src/test/scala/org/apache/spark/sql/hive/StatisticsSuite.scala ---
@@ -168,6 +170,57 @@ class StatisticsSuite extends QueryTest with TestHiveSingleton with SQLTestUtils
TableIdentifier("tempTable"), ignoreIfNotExists = true, purge = false)
}
+ test("generate table-level statistics") {
+ def checkTableStats(
+ statsSeq: Seq[Statistics],
+ sizeInBytes: Int,
+ estimatedSize: Int,
+ rowCount: Int): Unit = {
+ assert(statsSeq.size === 1)
+ assert(statsSeq.head.sizeInBytes === BigInt(sizeInBytes))
+ assert(statsSeq.head.estimatedSize === Some(BigInt(estimatedSize)))
+ assert(statsSeq.head.rowCount === Some(BigInt(rowCount)))
+ }
+
+ sql("CREATE TABLE analyzeTable (key STRING, value STRING)").collect()
+ sql("CREATE TABLE parquetTable (key STRING, value STRING) STORED AS PARQUET").collect()
+ sql("CREATE TABLE orcTable (key STRING, value STRING) STORED AS ORC").collect()
+
+ sql("INSERT INTO TABLE analyzeTable SELECT * FROM src").collect()
+ sql("INSERT INTO TABLE parquetTable SELECT * FROM src").collect()
+ sql("INSERT INTO TABLE orcTable SELECT * FROM src").collect()
+ sql("INSERT INTO TABLE orcTable SELECT * FROM src").collect()
+
+ sql("ANALYZE TABLE analyzeTable COMPUTE STATISTICS")
+ sql("ANALYZE TABLE parquetTable COMPUTE STATISTICS")
+ sql("ANALYZE TABLE orcTable COMPUTE STATISTICS")
+
+ var df = sql("SELECT * FROM analyzeTable")
+ var stats = df.queryExecution.analyzed.collect { case mr: MetastoreRelation =>
+ mr.statistics
+ }
+ checkTableStats(stats, 5812, 5812, 500)
+
+ // test statistics of LogicalRelation inherited from MetastoreRelation
+ df = sql("SELECT * FROM parquetTable")
+ stats = df.queryExecution.analyzed.collect { case rel: LogicalRelation =>
+ rel.statistics
+ }
+ checkTableStats(stats, 4236, 4236, 500)
+
+ sql("SET spark.sql.hive.convertMetastoreOrc=true").collect()
--- End diff --
Please use `withSQLConf` .
---
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 infrastructure@apache.org or file a JIRA ticket
with INFRA.
---
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org
[GitHub] spark issue #14712: [SPARK-17072] [SQL] support table-level statistics gener...
Posted by AmplabJenkins <gi...@git.apache.org>.
Github user AmplabJenkins commented on the issue:
https://github.com/apache/spark/pull/14712
Test FAILed.
Refer to this link for build results (access rights to CI server needed):
https://amplab.cs.berkeley.edu/jenkins//job/SparkPullRequestBuilder/64848/
Test FAILed.
---
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 infrastructure@apache.org or file a JIRA ticket
with INFRA.
---
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org
[GitHub] spark pull request #14712: [SPARK-17072] [SQL] support table-level statistic...
Posted by wzhfy <gi...@git.apache.org>.
Github user wzhfy commented on a diff in the pull request:
https://github.com/apache/spark/pull/14712#discussion_r77310310
--- Diff: sql/core/src/main/scala/org/apache/spark/sql/execution/command/AnalyzeTableCommand.scala ---
@@ -88,24 +85,54 @@ case class AnalyzeTableCommand(tableName: String) extends RunnableCommand {
}
}.getOrElse(0L)
- // Update the Hive metastore if the total size of the table is different than the size
- // recorded in the Hive metastore.
- // This logic is based on org.apache.hadoop.hive.ql.exec.StatsTask.aggregateStats().
- if (newTotalSize > 0 && newTotalSize != oldTotalSize) {
- sessionState.catalog.alterTable(
- catalogTable.copy(
- properties = relation.catalogTable.properties +
- (AnalyzeTableCommand.TOTAL_SIZE_FIELD -> newTotalSize.toString)))
- }
+ updateTableStats(
+ catalogTable,
+ oldTotalSize = catalogTable.stats.map(_.sizeInBytes.toLong).getOrElse(0L),
+ oldRowCount = catalogTable.stats.flatMap(_.rowCount.map(_.toLong)).getOrElse(-1L),
+ newTotalSize = newTotalSize)
+
+ // data source tables have been converted into LogicalRelations
+ case logicalRel: LogicalRelation if logicalRel.catalogTable.isDefined =>
+ val table = logicalRel.catalogTable.get
+ updateTableStats(
+ table,
+ oldTotalSize = table.stats.map(_.sizeInBytes.toLong).getOrElse(0L),
+ oldRowCount = table.stats.flatMap(_.rowCount.map(_.toLong)).getOrElse(-1L),
+ newTotalSize = logicalRel.relation.sizeInBytes)
case otherRelation =>
- throw new AnalysisException(s"ANALYZE TABLE is only supported for Hive tables, " +
- s"but '${tableIdent.unquotedString}' is a ${otherRelation.nodeName}.")
+ throw new AnalysisException(s"ANALYZE TABLE is not supported for " +
+ s"${otherRelation.nodeName}.")
}
+
+ def updateTableStats(
+ catalogTable: CatalogTable,
+ oldTotalSize: Long,
+ oldRowCount: Long,
+ newTotalSize: Long): Unit = {
+ var newStats: Option[Statistics] = None
+ if (newTotalSize > 0 && newTotalSize != oldTotalSize) {
+ newStats = Some(Statistics(sizeInBytes = newTotalSize))
--- End diff --
@cloud-fan When we have row count info, we can't tell whether the row count is valid or not - we can also run ANALYZE TABLE, and run `INSERT INTO`, then run `ANALYZE TABLE NOSCAN`. So removing it can make sure we only have the right answer.
---
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 infrastructure@apache.org or file a JIRA ticket
with INFRA.
---
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org
[GitHub] spark pull request #14712: [SPARK-17072] [SQL] support table-level statistic...
Posted by scwf <gi...@git.apache.org>.
Github user scwf commented on a diff in the pull request:
https://github.com/apache/spark/pull/14712#discussion_r77014850
--- Diff: sql/hive/src/test/scala/org/apache/spark/sql/hive/StatisticsSuite.scala ---
@@ -168,6 +169,107 @@ class StatisticsSuite extends QueryTest with TestHiveSingleton with SQLTestUtils
TableIdentifier("tempTable"), ignoreIfNotExists = true, purge = false)
}
+ private def checkMetastoreRelationStats(
+ tableName: String,
+ expectedTotalSize: Long,
+ expectedRowCount: Option[BigInt]): Unit = {
+ val df = sql(s"SELECT * FROM $tableName")
+ val relations = df.queryExecution.analyzed.collect { case rel: MetastoreRelation =>
+ assert(rel.statistics.sizeInBytes === expectedTotalSize)
+ assert(rel.statistics.rowCount === expectedRowCount)
+ rel
+ }
+ assert(relations.size === 1)
+ }
+
+ test("test table-level statistics for hive tables created in HiveExternalCatalog") {
+ val textTable = "textTable"
+ withTable(textTable) {
+ sql(s"CREATE TABLE $textTable (key STRING, value STRING) STORED AS TEXTFILE")
+ checkMetastoreRelationStats(textTable,
+ expectedTotalSize = spark.sessionState.conf.defaultSizeInBytes, expectedRowCount = None)
+
+ sql(s"INSERT INTO TABLE $textTable SELECT * FROM src")
+ // don't have our statistics, MetastoreRelation uses hive's `totalSize`
+ checkMetastoreRelationStats(textTable, expectedTotalSize = 5812, expectedRowCount = None)
+
+ // noscan won't count the number of rows
+ sql(s"ANALYZE TABLE $textTable COMPUTE STATISTICS noscan")
+ checkMetastoreRelationStats(textTable, expectedTotalSize = 5812, expectedRowCount = None)
+
+ // without noscan, we count the number of rows
+ sql(s"ANALYZE TABLE $textTable COMPUTE STATISTICS")
+ checkMetastoreRelationStats(textTable, expectedTotalSize = 5812, expectedRowCount = Some(500))
+ }
+ }
+
+ test("test whether the old stats are removed") {
+ val textTable = "textTable"
+ withTable(textTable) {
+ sql(s"CREATE TABLE $textTable (key STRING, value STRING) STORED AS TEXTFILE")
+ sql(s"INSERT INTO TABLE $textTable SELECT * FROM src")
+ sql(s"ANALYZE TABLE $textTable COMPUTE STATISTICS")
+ checkMetastoreRelationStats(textTable, expectedTotalSize = 5812, expectedRowCount = Some(500))
+
+ sql(s"INSERT INTO TABLE $textTable SELECT * FROM src")
+ sql(s"ANALYZE TABLE $textTable COMPUTE STATISTICS noscan")
+ // update total size and remove the old and invalid row count
+ checkMetastoreRelationStats(textTable, expectedTotalSize = 11624, expectedRowCount = None)
+ }
+ }
+
+ private def checkLogicalRelationStats(
+ tableName: String,
+ expectedRowCount: Option[BigInt]): Unit = {
+ val df = sql(s"SELECT * FROM $tableName")
+ val relations = df.queryExecution.analyzed.collect { case rel: LogicalRelation =>
+ // TODO: We don't have an expected value here because parquet size is different on Windows
+ // and Linux, we need to find the reason and fix this.
+ assert(rel.statistics.sizeInBytes === rel.relation.sizeInBytes)
+ assert(rel.statistics.rowCount === expectedRowCount)
+ rel
+ }
+ assert(relations.size === 1)
+ }
+
+ test("test statistics of LogicalRelation inherited from MetastoreRelation") {
+ 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")
+ sql(s"ANALYZE TABLE $parquetTable COMPUTE STATISTICS")
+ sql(s"ANALYZE TABLE $orcTable COMPUTE STATISTICS")
+
+ checkLogicalRelationStats(parquetTable, expectedRowCount = Some(500))
--- End diff --
for parquet table we'd better also set the `spark.sql.hive.convertMetastoreParquet` like orc table below, this is to avoid failure because of other test case changing this config.
---
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 infrastructure@apache.org or file a JIRA ticket
with INFRA.
---
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org
[GitHub] spark issue #14712: [SPARK-17072] [SQL] support table-level statistics gener...
Posted by wzhfy <gi...@git.apache.org>.
Github user wzhfy commented on the issue:
https://github.com/apache/spark/pull/14712
retest this please
---
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 infrastructure@apache.org or file a JIRA ticket
with INFRA.
---
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org
[GitHub] spark pull request #14712: [SPARK-17072] [SQL] support table-level statistic...
Posted by cloud-fan <gi...@git.apache.org>.
Github user cloud-fan commented on a diff in the pull request:
https://github.com/apache/spark/pull/14712#discussion_r75479677
--- Diff: sql/core/src/main/scala/org/apache/spark/sql/execution/SparkSqlParser.scala ---
@@ -99,9 +99,7 @@ class SparkSqlAstBuilder(conf: SQLConf) extends AstBuilder {
ctx.identifier.getText.toLowerCase == "noscan") {
--- End diff --
except `noscan`, are there some other options we may support in the future?
---
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 infrastructure@apache.org or file a JIRA ticket
with INFRA.
---
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org
[GitHub] spark issue #14712: [SPARK-17072] [SQL] support table-level statistics gener...
Posted by wzhfy <gi...@git.apache.org>.
Github user wzhfy commented on the issue:
https://github.com/apache/spark/pull/14712
@cloud-fan I agree with you. I'll update this pr tomorrow.
---
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 infrastructure@apache.org or file a JIRA ticket
with INFRA.
---
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org
[GitHub] spark issue #14712: [SPARK-17072] [SQL] support table-level statistics gener...
Posted by SparkQA <gi...@git.apache.org>.
Github user SparkQA commented on the issue:
https://github.com/apache/spark/pull/14712
**[Test build #64886 has started](https://amplab.cs.berkeley.edu/jenkins/job/SparkPullRequestBuilder/64886/consoleFull)** for PR 14712 at commit [`5d6e559`](https://github.com/apache/spark/commit/5d6e5599b558512000f3f62349276ebf19be366a).
---
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 infrastructure@apache.org or file a JIRA ticket
with INFRA.
---
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org
[GitHub] spark pull request #14712: [SPARK-17072] [SQL] support table-level statistic...
Posted by cloud-fan <gi...@git.apache.org>.
Github user cloud-fan commented on a diff in the pull request:
https://github.com/apache/spark/pull/14712#discussion_r76924362
--- Diff: sql/hive/src/main/scala/org/apache/spark/sql/hive/HiveExternalCatalog.scala ---
@@ -401,6 +401,13 @@ private[spark] class HiveExternalCatalog(conf: SparkConf, hadoopConf: Configurat
}
}
+ override def alterTableStats(tableDefinition: CatalogTable): Unit = withClient {
--- End diff --
I'm not sure we wanna support the second way to set properties. If users set them with ALTER TABLE, we should throw exception. cc @yhuai @gatorsmile what do you think?
---
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 infrastructure@apache.org or file a JIRA ticket
with INFRA.
---
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org
[GitHub] spark pull request #14712: [SPARK-17072] [SQL] support table-level statistic...
Posted by wzhfy <gi...@git.apache.org>.
Github user wzhfy commented on a diff in the pull request:
https://github.com/apache/spark/pull/14712#discussion_r77307095
--- Diff: sql/core/src/main/scala/org/apache/spark/sql/execution/command/AnalyzeTableCommand.scala ---
@@ -88,24 +85,54 @@ case class AnalyzeTableCommand(tableName: String) extends RunnableCommand {
}
}.getOrElse(0L)
- // Update the Hive metastore if the total size of the table is different than the size
- // recorded in the Hive metastore.
- // This logic is based on org.apache.hadoop.hive.ql.exec.StatsTask.aggregateStats().
- if (newTotalSize > 0 && newTotalSize != oldTotalSize) {
- sessionState.catalog.alterTable(
- catalogTable.copy(
- properties = relation.catalogTable.properties +
- (AnalyzeTableCommand.TOTAL_SIZE_FIELD -> newTotalSize.toString)))
- }
+ updateTableStats(
+ catalogTable,
+ oldTotalSize = catalogTable.stats.map(_.sizeInBytes.toLong).getOrElse(0L),
+ oldRowCount = catalogTable.stats.flatMap(_.rowCount.map(_.toLong)).getOrElse(-1L),
+ newTotalSize = newTotalSize)
+
+ // data source tables have been converted into LogicalRelations
+ case logicalRel: LogicalRelation if logicalRel.catalogTable.isDefined =>
+ val table = logicalRel.catalogTable.get
+ updateTableStats(
+ table,
+ oldTotalSize = table.stats.map(_.sizeInBytes.toLong).getOrElse(0L),
+ oldRowCount = table.stats.flatMap(_.rowCount.map(_.toLong)).getOrElse(-1L),
--- End diff --
@cloud-fan yeah, that makes code much cleaner, thanks
---
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 infrastructure@apache.org or file a JIRA ticket
with INFRA.
---
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org
[GitHub] spark issue #14712: [SPARK-17072] [SQL] support table-level statistics gener...
Posted by AmplabJenkins <gi...@git.apache.org>.
Github user AmplabJenkins commented on the issue:
https://github.com/apache/spark/pull/14712
Test PASSed.
Refer to this link for build results (access rights to CI server needed):
https://amplab.cs.berkeley.edu/jenkins//job/SparkPullRequestBuilder/64726/
Test PASSed.
---
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 infrastructure@apache.org or file a JIRA ticket
with INFRA.
---
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org
[GitHub] spark pull request #14712: [SPARK-17072] [SQL] support table-level statistic...
Posted by hvanhovell <gi...@git.apache.org>.
Github user hvanhovell commented on a diff in the pull request:
https://github.com/apache/spark/pull/14712#discussion_r75516336
--- Diff: sql/core/src/main/scala/org/apache/spark/sql/execution/command/AnalyzeTableCommand.scala ---
@@ -108,4 +126,8 @@ case class AnalyzeTableCommand(tableName: String) extends RunnableCommand {
object AnalyzeTableCommand {
val TOTAL_SIZE_FIELD = "totalSize"
+ // same as org.apache.hadoop.hive.common.StatsSetupConst
+ val ROW_COUNT = "numRows"
+ val STATS_GENERATED_VIA_STATS_TASK = "STATS_GENERATED_VIA_STATS_TASK"
+ val TRUE = "true"
--- End diff --
??? Do we really need this :)...
---
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 infrastructure@apache.org or file a JIRA ticket
with INFRA.
---
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org
[GitHub] spark pull request #14712: [SPARK-17072] [SQL] support table-level statistic...
Posted by gatorsmile <gi...@git.apache.org>.
Github user gatorsmile commented on a diff in the pull request:
https://github.com/apache/spark/pull/14712#discussion_r75519430
--- Diff: sql/hive/src/test/scala/org/apache/spark/sql/hive/StatisticsSuite.scala ---
@@ -168,6 +170,57 @@ class StatisticsSuite extends QueryTest with TestHiveSingleton with SQLTestUtils
TableIdentifier("tempTable"), ignoreIfNotExists = true, purge = false)
}
+ test("generate table-level statistics") {
+ def checkTableStats(
+ statsSeq: Seq[Statistics],
+ sizeInBytes: Int,
+ estimatedSize: Int,
+ rowCount: Int): Unit = {
+ assert(statsSeq.size === 1)
+ assert(statsSeq.head.sizeInBytes === BigInt(sizeInBytes))
+ assert(statsSeq.head.estimatedSize === Some(BigInt(estimatedSize)))
+ assert(statsSeq.head.rowCount === Some(BigInt(rowCount)))
+ }
+
+ sql("CREATE TABLE analyzeTable (key STRING, value STRING)").collect()
+ sql("CREATE TABLE parquetTable (key STRING, value STRING) STORED AS PARQUET").collect()
+ sql("CREATE TABLE orcTable (key STRING, value STRING) STORED AS ORC").collect()
+
+ sql("INSERT INTO TABLE analyzeTable SELECT * FROM src").collect()
+ sql("INSERT INTO TABLE parquetTable SELECT * FROM src").collect()
+ sql("INSERT INTO TABLE orcTable SELECT * FROM src").collect()
+ sql("INSERT INTO TABLE orcTable SELECT * FROM src").collect()
+
+ sql("ANALYZE TABLE analyzeTable COMPUTE STATISTICS")
+ sql("ANALYZE TABLE parquetTable COMPUTE STATISTICS")
+ sql("ANALYZE TABLE orcTable COMPUTE STATISTICS")
+
+ var df = sql("SELECT * FROM analyzeTable")
+ var stats = df.queryExecution.analyzed.collect { case mr: MetastoreRelation =>
+ mr.statistics
+ }
+ checkTableStats(stats, 5812, 5812, 500)
+
+ // test statistics of LogicalRelation inherited from MetastoreRelation
+ df = sql("SELECT * FROM parquetTable")
+ stats = df.queryExecution.analyzed.collect { case rel: LogicalRelation =>
+ rel.statistics
+ }
+ checkTableStats(stats, 4236, 4236, 500)
+
+ sql("SET spark.sql.hive.convertMetastoreOrc=true").collect()
+ df = sql("SELECT * FROM orcTable")
+ stats = df.queryExecution.analyzed.collect { case rel: LogicalRelation =>
+ rel.statistics
+ }
+ checkTableStats(stats, 6046, 6046, 1000)
+ sql("RESET").collect()
+
+ sql("DROP TABLE analyzeTable").collect()
+ sql("DROP TABLE parquetTable").collect()
+ sql("DROP TABLE orcTable").collect()
--- End diff --
Please use `withTable` here.
---
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 infrastructure@apache.org or file a JIRA ticket
with INFRA.
---
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org
[GitHub] spark issue #14712: [SPARK-17072] [SQL] support table-level statistics gener...
Posted by cloud-fan <gi...@git.apache.org>.
Github user cloud-fan commented on the issue:
https://github.com/apache/spark/pull/14712
I wanna make sure we are in the same page:
**top priority**: users analyze the table in Spark and query it in Spark. (this must work)
**second priority**: the table is already analyzed by Hive, users query it in Spark.(this should work)
**low priority**: users analyze the table in Spark and query it in Hive.(it will be good if this works, but also fine if this doesn't)
I'm a little hesitant about dealing with the `STATS_GENERATED_VIA_STATS_TASK` and `COLUMN_STATS_ACCURATE` flags, are they only needed for the third(low priority) target? If they are, I'd like to ignore them to simplify the logic.
---
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 infrastructure@apache.org or file a JIRA ticket
with INFRA.
---
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org
[GitHub] spark pull request #14712: [SPARK-17072] [SQL] support table-level statistic...
Posted by wzhfy <gi...@git.apache.org>.
Github user wzhfy commented on a diff in the pull request:
https://github.com/apache/spark/pull/14712#discussion_r75450024
--- Diff: sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/plans/logical/LogicalPlan.scala ---
@@ -95,6 +95,12 @@ abstract class LogicalPlan extends QueryPlan[LogicalPlan] with Logging {
}
/**
+ * Estimate complete [[Statistics]] for this plan. Each plan need to override this to get
+ * complete statistics.
+ */
+ def completeStats: Statistics = statistics
--- End diff --
ok, i've updated this pr based on your comments
---
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 infrastructure@apache.org or file a JIRA ticket
with INFRA.
---
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org