Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

[SPARK-27266][SQL] Support ANALYZE TABLE to collect tables stats for cached catalog views #24200

Closed
wants to merge 3 commits into from

Conversation

maropu
Copy link
Member

@maropu maropu commented Mar 25, 2019

What changes were proposed in this pull request?

The current master doesn't support ANALYZE TABLE to collect tables stats for catalog views even if they are cached as follows;

scala> sql(s"CREATE VIEW v AS SELECT 1 c")
scala> sql(s"CACHE LAZY TABLE v")
scala> sql(s"ANALYZE TABLE v COMPUTE STATISTICS")
org.apache.spark.sql.AnalysisException: ANALYZE TABLE is not supported on views.;
...

Since SPARK-25196 has supported to an ANALYZE command to collect column statistics for cached catalog view, we could support table stats, too.

How was this patch tested?

Added tests in StatisticsCollectionSuite and InMemoryColumnarQuerySuite.

@SparkQA
Copy link

SparkQA commented Mar 25, 2019

Test build #103895 has finished for PR 24200 at commit b51b9a8.

  • This patch fails due to an unknown error code, -9.
  • This patch merges cleanly.
  • This patch adds no public classes.

@maropu
Copy link
Member Author

maropu commented Mar 25, 2019

retest this please

@SparkQA
Copy link

SparkQA commented Mar 25, 2019

Test build #103906 has finished for PR 24200 at commit b51b9a8.

  • This patch passes all tests.
  • This patch merges cleanly.
  • This patch adds no public classes.

@maropu
Copy link
Member Author

maropu commented Mar 26, 2019

cc: @dongjoon-hyun

@dongjoon-hyun
Copy link
Member

Thank you for pinging me, @maropu . Yep. I'll take a look in a few hours.

statsOfPlanToCache.copy(sizeInBytes = cacheBuilder.sizeInBytesStats.value.longValue)
statsOfPlanToCache.copy(
sizeInBytes = cacheBuilder.sizeInBytesStats.value.longValue,
rowCount = Some(cacheBuilder.rowCountStats.value.longValue)
Copy link
Member

Choose a reason for hiding this comment

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

Is rowCount required additionally? If not, please remove this.

Copy link
Member Author

Choose a reason for hiding this comment

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

Yea, we need it because this change passes rowCount into upper nodes;

scala> sql("CREATE VIEW v AS SELECT 1 c")
scala> sql("CACHE TABLE v")
scala> spark.table("v").explain(true)
...
== Optimized Logical Plan ==
InMemoryRelation [c#28], StorageLevel(disk, memory, deserialized, 1 replicas)
   +- *(1) Project [1 AS c#1]
      +- Scan OneRowRelation[]
...

> w/o this change
scala> val stats = spark.table("v").queryExecution.optimizedPlan.stats
.... Statistics(sizeInBytes=4.0 B)

> w/ this change
scala> val stats = spark.table("v").queryExecution.optimizedPlan.stats
.... Statistics(sizeInBytes=4.0 B, rowCount=1)
                                   ^^^^^^^^^^^

val cacheManager = sparkSession.sharedState.cacheManager
if (cacheManager.lookupCachedData(table.logicalPlan).isDefined) {
// To collect table stats, materializes an underlying columnar RDD
table.collect()
Copy link
Member

Choose a reason for hiding this comment

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

Ur, @maropu , is this safe? Although ANALYZE TABLE is a heavy operation in general, Spark CBO collects statistics until now. For me, table.collect() looks too heavy.

Hi, @cloud-fan . Is this kind of heavy operations allowed?

Copy link
Member Author

@maropu maropu Mar 26, 2019

Choose a reason for hiding this comment

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

I wrote this code to do the same thing with the normal case:

if (noscan) None else Some(BigInt(sparkSession.table(tableIdentWithDB).count()))

@SparkQA
Copy link

SparkQA commented Mar 26, 2019

Test build #103953 has finished for PR 24200 at commit b4bbdad.

  • This patch fails due to an unknown error code, -9.
  • This patch merges cleanly.
  • This patch adds no public classes.

@maropu
Copy link
Member Author

maropu commented Mar 26, 2019

retest this please

@SparkQA
Copy link

SparkQA commented Mar 26, 2019

Test build #103959 has finished for PR 24200 at commit b4bbdad.

  • This patch passes all tests.
  • This patch merges cleanly.
  • This patch adds no public classes.

table.collect()
if (!noscan) {
// To collect table stats, materializes an underlying columnar RDD
table.collect()
Copy link
Member

Choose a reason for hiding this comment

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

According to the pointer you gave in the previous comment, table.count is enough for this?

Copy link
Member Author

@maropu maropu Mar 26, 2019

Choose a reason for hiding this comment

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

oh! I missed it... this is my silly mistake, sorry.

@SparkQA
Copy link

SparkQA commented Mar 27, 2019

Test build #103999 has finished for PR 24200 at commit 7b66f0d.

  • This patch passes all tests.
  • This patch merges cleanly.
  • This patch adds no public classes.

@dongjoon-hyun
Copy link
Member

Retest this please.

@SparkQA
Copy link

SparkQA commented Mar 31, 2019

Test build #104130 has finished for PR 24200 at commit 7b66f0d.

  • This patch fails due to an unknown error code, -9.
  • This patch merges cleanly.
  • This patch adds no public classes.

@dongjoon-hyun
Copy link
Member

Retest this please.

@SparkQA
Copy link

SparkQA commented Mar 31, 2019

Test build #104144 has finished for PR 24200 at commit 7b66f0d.

  • This patch passes all tests.
  • This patch merges cleanly.
  • This patch adds no public classes.

if (!noscan) {
// To collect table stats, materializes an underlying columnar RDD
table.count()
}
Copy link
Member

Choose a reason for hiding this comment

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

If noscan is true, this is no-op. We may want to show some warning or info here later. However, this is not a big deal. For now, this PR is much better than before because this prevents AnalysisException by supporting this. We can add doc later before 3.0.0 release (if needed.).

Copy link
Member

@dongjoon-hyun dongjoon-hyun left a comment

Choose a reason for hiding this comment

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

+1, LGTM. Thank you, @maropu .

Merged to master.

cc @gatorsmile .

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
3 participants