diff options
author | Reynold Xin <rxin@databricks.com> | 2016-04-21 17:41:29 -0700 |
---|---|---|
committer | Reynold Xin <rxin@databricks.com> | 2016-04-21 17:41:29 -0700 |
commit | f181aee07c0ee105b2a34581105eeeada7d42363 (patch) | |
tree | d3dd7f74e0aa2ad9881517ce8c79052bf0863de0 /sql/catalyst | |
parent | 4e726227a3e68c776ea30b78b7db8d01d00b44d6 (diff) | |
download | spark-f181aee07c0ee105b2a34581105eeeada7d42363.tar.gz spark-f181aee07c0ee105b2a34581105eeeada7d42363.tar.bz2 spark-f181aee07c0ee105b2a34581105eeeada7d42363.zip |
[SPARK-14821][SQL] Implement AnalyzeTable in sql/core and remove HiveSqlAstBuilder
## What changes were proposed in this pull request?
This patch moves analyze table parsing into SparkSqlAstBuilder and removes HiveSqlAstBuilder.
In order to avoid extensive refactoring, I created a common trait for CatalogRelation and MetastoreRelation, and match on that. In the future we should probably just consolidate the two into a single thing so we don't need this common trait.
## How was this patch tested?
Updated unit tests.
Author: Reynold Xin <rxin@databricks.com>
Closes #12584 from rxin/SPARK-14821.
Diffstat (limited to 'sql/catalyst')
3 files changed, 23 insertions, 9 deletions
diff --git a/sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/catalog/SessionCatalog.scala b/sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/catalog/SessionCatalog.scala index 34e1cb7315..ab5124ea56 100644 --- a/sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/catalog/SessionCatalog.scala +++ b/sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/catalog/SessionCatalog.scala @@ -266,7 +266,7 @@ class SessionCatalog( val relation = if (name.database.isDefined || !tempTables.contains(table)) { val metadata = externalCatalog.getTable(db, table) - CatalogRelation(db, metadata, alias) + SimpleCatalogRelation(db, metadata, alias) } else { tempTables(table) } diff --git a/sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/catalog/interface.scala b/sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/catalog/interface.scala index ad989a97e4..d2294efd9a 100644 --- a/sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/catalog/interface.scala +++ b/sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/catalog/interface.scala @@ -295,17 +295,31 @@ object ExternalCatalog { /** + * 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. + */ +trait CatalogRelation { + def catalogTable: CatalogTable +} + + +/** * A [[LogicalPlan]] that wraps [[CatalogTable]]. + * + * Note that in the future we should consolidate this and HiveCatalogRelation. */ -case class CatalogRelation( - db: String, +case class SimpleCatalogRelation( + databaseName: String, metadata: CatalogTable, alias: Option[String] = None) - extends LeafNode { + extends LeafNode with CatalogRelation { // TODO: implement this override def output: Seq[Attribute] = Seq.empty - require(metadata.identifier.database == Some(db), + override def catalogTable: CatalogTable = metadata + + require(metadata.identifier.database == Some(databaseName), "provided database does not match the one specified in the table definition") } diff --git a/sql/catalyst/src/test/scala/org/apache/spark/sql/catalyst/catalog/SessionCatalogSuite.scala b/sql/catalyst/src/test/scala/org/apache/spark/sql/catalyst/catalog/SessionCatalogSuite.scala index 426273e1e3..27205c4587 100644 --- a/sql/catalyst/src/test/scala/org/apache/spark/sql/catalyst/catalog/SessionCatalogSuite.scala +++ b/sql/catalyst/src/test/scala/org/apache/spark/sql/catalyst/catalog/SessionCatalogSuite.scala @@ -372,25 +372,25 @@ class SessionCatalogSuite extends SparkFunSuite { sessionCatalog.setCurrentDatabase("db2") // If we explicitly specify the database, we'll look up the relation in that database assert(sessionCatalog.lookupRelation(TableIdentifier("tbl1", Some("db2"))) - == SubqueryAlias("tbl1", CatalogRelation("db2", metastoreTable1))) + == SubqueryAlias("tbl1", SimpleCatalogRelation("db2", metastoreTable1))) // Otherwise, we'll first look up a temporary table with the same name assert(sessionCatalog.lookupRelation(TableIdentifier("tbl1")) == SubqueryAlias("tbl1", tempTable1)) // Then, if that does not exist, look up the relation in the current database sessionCatalog.dropTable(TableIdentifier("tbl1"), ignoreIfNotExists = false) assert(sessionCatalog.lookupRelation(TableIdentifier("tbl1")) - == SubqueryAlias("tbl1", CatalogRelation("db2", metastoreTable1))) + == SubqueryAlias("tbl1", SimpleCatalogRelation("db2", metastoreTable1))) } test("lookup table relation with alias") { val catalog = new SessionCatalog(newBasicCatalog()) val alias = "monster" val tableMetadata = catalog.getTableMetadata(TableIdentifier("tbl1", Some("db2"))) - val relation = SubqueryAlias("tbl1", CatalogRelation("db2", tableMetadata)) + val relation = SubqueryAlias("tbl1", SimpleCatalogRelation("db2", tableMetadata)) val relationWithAlias = SubqueryAlias(alias, SubqueryAlias("tbl1", - CatalogRelation("db2", tableMetadata, Some(alias)))) + SimpleCatalogRelation("db2", tableMetadata, Some(alias)))) assert(catalog.lookupRelation( TableIdentifier("tbl1", Some("db2")), alias = None) == relation) assert(catalog.lookupRelation( |