-
Notifications
You must be signed in to change notification settings - Fork 29k
[SPARK-18911] [SQL] Define CatalogStatistics to interact with metastore and convert it to Statistics in relations #16323
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
Changes from 1 commit
f9db620
72a16e5
5dbaade
bd5eacc
d3227dc
573b560
978bb11
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
- Loading branch information
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -19,10 +19,12 @@ package org.apache.spark.sql.catalyst.catalog | |
|
|
||
| import java.util.Date | ||
|
|
||
| import scala.collection.mutable | ||
|
|
||
| import org.apache.spark.sql.AnalysisException | ||
| import org.apache.spark.sql.catalyst.{FunctionIdentifier, InternalRow, TableIdentifier} | ||
| import org.apache.spark.sql.catalyst.expressions.{Attribute, Cast, Literal} | ||
| import org.apache.spark.sql.catalyst.plans.logical.{CatalogStatistics, LeafNode, LogicalPlan} | ||
| import org.apache.spark.sql.catalyst.expressions.{Attribute, AttributeMap, Cast, Literal} | ||
| import org.apache.spark.sql.catalyst.plans.logical._ | ||
| import org.apache.spark.sql.catalyst.util.quoteIdentifier | ||
| import org.apache.spark.sql.types.{StructField, StructType} | ||
|
|
||
|
|
@@ -241,6 +243,38 @@ case class CatalogTable( | |
| } | ||
|
|
||
|
|
||
| /** | ||
| * This class of statistics is used in [[CatalogTable]] to interact with metastore. | ||
| */ | ||
| case class CatalogStatistics( | ||
| sizeInBytes: BigInt, | ||
| rowCount: Option[BigInt] = None, | ||
| colStats: Map[String, ColumnStat] = Map.empty) { | ||
|
|
||
| /** | ||
| * Convert [[CatalogStatistics]] to [[Statistics]], and match column stats to attributes based | ||
| * on column names. | ||
| */ | ||
| def convert(attributes: Seq[Attribute]): Statistics = { | ||
|
||
| val matched = mutable.HashMap[Attribute, ColumnStat]() | ||
| attributes.foreach { attr => | ||
| if (colStats.contains(attr.name)) { | ||
| matched.put(attr, colStats(attr.name)) | ||
| } | ||
| } | ||
|
||
| Statistics(sizeInBytes = sizeInBytes, rowCount = rowCount, | ||
| attributeStats = AttributeMap(matched.toSeq)) | ||
| } | ||
|
|
||
| /** Readable string representation for the CatalogStatistics. */ | ||
| def simpleString: String = { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. why do you define a
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Because we don't print column stats in it, it's not a "complete" string representation. Column stats can be too much and make CatalogTable unreadable. |
||
| Seq(s"sizeInBytes=$sizeInBytes", | ||
| if (rowCount.isDefined) s"rowCount=${rowCount.get}" else "" | ||
| ).filter(_.nonEmpty).mkString(", ") | ||
|
||
| } | ||
| } | ||
|
|
||
|
|
||
| case class CatalogTableType private(name: String) | ||
| object CatalogTableType { | ||
| val EXTERNAL = new CatalogTableType("EXTERNAL") | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you add few words explaining why don't use
StatisticsforCatalogTable?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ok