-
Notifications
You must be signed in to change notification settings - Fork 29.1k
[SPARK-19678][SQL] remove MetastoreRelation #17015
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
Closed
Closed
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -19,10 +19,11 @@ package org.apache.spark.sql.catalyst.catalog | |
|
|
||
| import java.util.Date | ||
|
|
||
| import scala.collection.mutable | ||
| import com.google.common.base.Objects | ||
|
|
||
| import org.apache.spark.sql.AnalysisException | ||
| import org.apache.spark.sql.catalyst.{FunctionIdentifier, InternalRow, TableIdentifier} | ||
| import org.apache.spark.sql.catalyst.{CatalystConf, FunctionIdentifier, InternalRow, TableIdentifier} | ||
| import org.apache.spark.sql.catalyst.analysis.MultiInstanceRelation | ||
| 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 | ||
|
|
@@ -349,36 +350,43 @@ object CatalogTypes { | |
|
|
||
|
|
||
| /** | ||
| * An interface that is implemented by logical plans to return the underlying catalog table. | ||
| * If we can in the future consolidate SimpleCatalogRelation and MetastoreRelation, we should | ||
| * probably remove this interface. | ||
| * A [[LogicalPlan]] that represents a table. | ||
| */ | ||
| trait CatalogRelation { | ||
| def catalogTable: CatalogTable | ||
| def output: Seq[Attribute] | ||
| } | ||
| case class CatalogRelation( | ||
| tableMeta: CatalogTable, | ||
| dataCols: Seq[Attribute], | ||
| partitionCols: Seq[Attribute]) extends LeafNode with MultiInstanceRelation { | ||
| assert(tableMeta.identifier.database.isDefined) | ||
|
||
| assert(tableMeta.partitionSchema.sameType(partitionCols.toStructType)) | ||
| assert(tableMeta.dataSchema.sameType(dataCols.toStructType)) | ||
|
|
||
| // The partition column should always appear after data columns. | ||
| override def output: Seq[Attribute] = dataCols ++ partitionCols | ||
|
|
||
| def isPartitioned: Boolean = partitionCols.nonEmpty | ||
|
|
||
| override def equals(relation: Any): Boolean = relation match { | ||
| case other: CatalogRelation => tableMeta == other.tableMeta && output == other.output | ||
| case _ => false | ||
| } | ||
|
|
||
| override def hashCode(): Int = { | ||
| Objects.hashCode(tableMeta.identifier, output) | ||
| } | ||
|
|
||
| /** | ||
| * A [[LogicalPlan]] that wraps [[CatalogTable]]. | ||
| * | ||
| * Note that in the future we should consolidate this and HiveCatalogRelation. | ||
| */ | ||
| case class SimpleCatalogRelation( | ||
| metadata: CatalogTable) | ||
| extends LeafNode with CatalogRelation { | ||
|
|
||
| override def catalogTable: CatalogTable = metadata | ||
|
|
||
| override lazy val resolved: Boolean = false | ||
|
|
||
| override val output: Seq[Attribute] = { | ||
| val (partCols, dataCols) = metadata.schema.toAttributes | ||
| // Since data can be dumped in randomly with no validation, everything is nullable. | ||
| .map(_.withNullability(true).withQualifier(Some(metadata.identifier.table))) | ||
| .partition { a => | ||
| metadata.partitionColumnNames.contains(a.name) | ||
| } | ||
| dataCols ++ partCols | ||
| /** Only compare table identifier. */ | ||
| override lazy val cleanArgs: Seq[Any] = Seq(tableMeta.identifier) | ||
|
|
||
| override def computeStats(conf: CatalystConf): Statistics = { | ||
| // For data source tables, we will create a `LogicalRelation` and won't call this method, for | ||
| // hive serde tables, we will always generate a statistics. | ||
| // TODO: unify the table stats generation. | ||
| tableMeta.stats.map(_.toPlanStats(output)).getOrElse { | ||
| throw new IllegalStateException("table stats must be specified.") | ||
| } | ||
| } | ||
|
|
||
| override def newInstance(): LogicalPlan = copy( | ||
| dataCols = dataCols.map(_.newInstance()), | ||
| partitionCols = partitionCols.map(_.newInstance())) | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
dataColsandpartitionColsare needed only becauseCatalogRelationextendsMultiInstanceRelation?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.
yes, and at least we need a
Seq[Attribute]as output.