From 43f4fd6f9bfff749af17e3c65b53a33f5ecb0922 Mon Sep 17 00:00:00 2001 From: Wenchen Fan Date: Thu, 4 Aug 2016 16:48:30 +0800 Subject: [SPARK-16867][SQL] createTable and alterTable in ExternalCatalog should not take db ## What changes were proposed in this pull request? These 2 methods take `CatalogTable` as parameter, which already have the database information. ## How was this patch tested? existing test Author: Wenchen Fan Closes #14476 from cloud-fan/minor5. --- .../org/apache/spark/sql/catalyst/catalog/ExternalCatalog.scala | 9 +++++---- .../org/apache/spark/sql/catalyst/catalog/InMemoryCatalog.scala | 7 +++++-- .../org/apache/spark/sql/catalyst/catalog/SessionCatalog.scala | 4 ++-- 3 files changed, 12 insertions(+), 8 deletions(-) (limited to 'sql/catalyst/src/main') diff --git a/sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/catalog/ExternalCatalog.scala b/sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/catalog/ExternalCatalog.scala index 35fc6ddacb..27e1810814 100644 --- a/sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/catalog/ExternalCatalog.scala +++ b/sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/catalog/ExternalCatalog.scala @@ -69,20 +69,21 @@ abstract class ExternalCatalog { // Tables // -------------------------------------------------------------------------- - def createTable(db: String, tableDefinition: CatalogTable, ignoreIfExists: Boolean): Unit + def createTable(tableDefinition: CatalogTable, ignoreIfExists: Boolean): Unit def dropTable(db: String, table: String, ignoreIfNotExists: Boolean, purge: Boolean): Unit def renameTable(db: String, oldName: String, newName: String): Unit /** - * Alter a table whose name that matches the one specified in `tableDefinition`, - * assuming the table exists. + * Alter a table whose database and name match the ones specified in `tableDefinition`, assuming + * the table exists. Note that, even though we can specify database in `tableDefinition`, it's + * used to identify the table, not to alter the table's database, which is not allowed. * * Note: If the underlying implementation does not support altering a certain field, * this becomes a no-op. */ - def alterTable(db: String, tableDefinition: CatalogTable): Unit + def alterTable(tableDefinition: CatalogTable): Unit def getTable(db: String, table: String): CatalogTable diff --git a/sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/catalog/InMemoryCatalog.scala b/sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/catalog/InMemoryCatalog.scala index 67a90c8895..9ebf7de1a5 100644 --- a/sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/catalog/InMemoryCatalog.scala +++ b/sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/catalog/InMemoryCatalog.scala @@ -192,9 +192,10 @@ class InMemoryCatalog(hadoopConfig: Configuration = new Configuration) extends E // -------------------------------------------------------------------------- override def createTable( - db: String, tableDefinition: CatalogTable, ignoreIfExists: Boolean): Unit = synchronized { + assert(tableDefinition.identifier.database.isDefined) + val db = tableDefinition.identifier.database.get requireDbExists(db) val table = tableDefinition.identifier.table if (tableExists(db, table)) { @@ -266,7 +267,9 @@ class InMemoryCatalog(hadoopConfig: Configuration = new Configuration) extends E catalog(db).tables.remove(oldName) } - override def alterTable(db: String, tableDefinition: CatalogTable): Unit = synchronized { + override def alterTable(tableDefinition: CatalogTable): Unit = synchronized { + assert(tableDefinition.identifier.database.isDefined) + val db = tableDefinition.identifier.database.get requireTableExists(db, tableDefinition.identifier.table) catalog(db).tables(tableDefinition.identifier.table).table = tableDefinition } 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 980efda6cf..fabab32592 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 @@ -223,7 +223,7 @@ class SessionCatalog( val table = formatTableName(tableDefinition.identifier.table) val newTableDefinition = tableDefinition.copy(identifier = TableIdentifier(table, Some(db))) requireDbExists(db) - externalCatalog.createTable(db, newTableDefinition, ignoreIfExists) + externalCatalog.createTable(newTableDefinition, ignoreIfExists) } /** @@ -242,7 +242,7 @@ class SessionCatalog( val newTableDefinition = tableDefinition.copy(identifier = tableIdentifier) requireDbExists(db) requireTableExists(tableIdentifier) - externalCatalog.alterTable(db, newTableDefinition) + externalCatalog.alterTable(newTableDefinition) } /** -- cgit v1.2.3