-
Notifications
You must be signed in to change notification settings - Fork 29k
[SPARK-17502] [SQL] Fix Multiple Bugs in DDL Statements on Temporary Views #15054
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
cc47c3e
855df61
61749b7
60371d8
6029a95
7c1a8e5
a01f6b3
333497a
5e40880
f305c4c
c662d2c
48ce44e
ee3096c
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 |
|---|---|---|
|
|
@@ -265,7 +265,7 @@ case class AlterTableUnsetPropertiesCommand( | |
| override def run(sparkSession: SparkSession): Seq[Row] = { | ||
| val catalog = sparkSession.sessionState.catalog | ||
| DDLUtils.verifyAlterTableType(catalog, tableName, isView) | ||
| val table = catalog.getNonTempTableMetadata(tableName) | ||
| val table = catalog.getTableMetadata(tableName) | ||
|
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. same here, we can always pass in a table identifier with database |
||
|
|
||
| if (!ifExists) { | ||
| propKeys.foreach { k => | ||
|
|
@@ -305,7 +305,7 @@ case class AlterTableSerDePropertiesCommand( | |
|
|
||
| override def run(sparkSession: SparkSession): Seq[Row] = { | ||
| val catalog = sparkSession.sessionState.catalog | ||
| val table = catalog.getNonTempTableMetadata(tableName) | ||
| val table = catalog.getTableMetadata(tableName) | ||
| // For datasource tables, disallow setting serde or specifying partition | ||
| if (partSpec.isDefined && DDLUtils.isDatasourceTable(table)) { | ||
| throw new AnalysisException("Operation not allowed: ALTER TABLE SET " + | ||
|
|
@@ -354,7 +354,7 @@ case class AlterTableAddPartitionCommand( | |
|
|
||
| override def run(sparkSession: SparkSession): Seq[Row] = { | ||
| val catalog = sparkSession.sessionState.catalog | ||
| val table = catalog.getNonTempTableMetadata(tableName) | ||
| val table = catalog.getTableMetadata(tableName) | ||
| if (DDLUtils.isDatasourceTable(table)) { | ||
| throw new AnalysisException( | ||
| "ALTER TABLE ADD PARTITION is not allowed for tables defined using the datasource API") | ||
|
|
@@ -414,7 +414,7 @@ case class AlterTableDropPartitionCommand( | |
|
|
||
| override def run(sparkSession: SparkSession): Seq[Row] = { | ||
| val catalog = sparkSession.sessionState.catalog | ||
| val table = catalog.getNonTempTableMetadata(tableName) | ||
| val table = catalog.getTableMetadata(tableName) | ||
| if (DDLUtils.isDatasourceTable(table)) { | ||
| throw new AnalysisException( | ||
| "ALTER TABLE DROP PARTITIONS is not allowed for tables defined using the datasource API") | ||
|
|
@@ -468,7 +468,7 @@ case class AlterTableRecoverPartitionsCommand( | |
|
|
||
| override def run(spark: SparkSession): Seq[Row] = { | ||
| val catalog = spark.sessionState.catalog | ||
| val table = catalog.getNonTempTableMetadata(tableName) | ||
| val table = catalog.getTableMetadata(tableName) | ||
| val qualifiedName = table.identifier.quotedString | ||
|
|
||
| if (DDLUtils.isDatasourceTable(table)) { | ||
|
|
@@ -645,7 +645,7 @@ case class AlterTableSetLocationCommand( | |
|
|
||
| override def run(sparkSession: SparkSession): Seq[Row] = { | ||
| val catalog = sparkSession.sessionState.catalog | ||
| val table = catalog.getNonTempTableMetadata(tableName) | ||
| val table = catalog.getTableMetadata(tableName) | ||
| partitionSpec match { | ||
| case Some(spec) => | ||
| // Partition spec is specified, so we set the location only for this partition | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -64,7 +64,11 @@ case class CreateTableLikeCommand( | |
| s"Source table in CREATE TABLE LIKE does not exist: '$sourceTable'") | ||
| } | ||
|
|
||
| val sourceTableDesc = catalog.getTableMetadata(sourceTable) | ||
| val sourceTableDesc = if (catalog.isTemporaryTable(sourceTable)) { | ||
| catalog.getTempViewMetadata(sourceTable.table) | ||
|
||
| } else { | ||
| catalog.getTableMetadata(sourceTable) | ||
| } | ||
|
|
||
| // Storage format | ||
| val newStorage = | ||
|
|
@@ -176,7 +180,11 @@ case class AlterTableRenameCommand( | |
| } | ||
| } | ||
| // For datasource tables, we also need to update the "path" serde property | ||
| val table = catalog.getTableMetadata(oldName) | ||
| val table = if (catalog.isTemporaryTable(oldName)) { | ||
| catalog.getTempViewMetadata(oldName.table) | ||
| } else { | ||
| catalog.getTableMetadata(oldName) | ||
| } | ||
| if (DDLUtils.isDatasourceTable(table) && table.tableType == CatalogTableType.MANAGED) { | ||
| val newPath = catalog.defaultTablePath(newTblName) | ||
| val newTable = table.withNewStorage( | ||
|
|
@@ -214,7 +222,7 @@ case class LoadDataCommand( | |
|
|
||
| override def run(sparkSession: SparkSession): Seq[Row] = { | ||
| val catalog = sparkSession.sessionState.catalog | ||
| val targetTable = catalog.getNonTempTableMetadata(table) | ||
| val targetTable = catalog.getTableMetadata(table) | ||
| val qualifiedName = targetTable.identifier.quotedString | ||
|
|
||
| if (targetTable.tableType == CatalogTableType.VIEW) { | ||
|
|
@@ -333,7 +341,7 @@ case class TruncateTableCommand( | |
|
|
||
| override def run(spark: SparkSession): Seq[Row] = { | ||
| val catalog = spark.sessionState.catalog | ||
| val table = catalog.getNonTempTableMetadata(tableName) | ||
| val table = catalog.getTableMetadata(tableName) | ||
| val qualifiedName = table.identifier.quotedString | ||
|
|
||
| if (table.tableType == CatalogTableType.EXTERNAL) { | ||
|
|
@@ -592,13 +600,19 @@ case class ShowTablePropertiesCommand(table: TableIdentifier, propertyKey: Optio | |
| * SHOW COLUMNS (FROM | IN) table_identifier [(FROM | IN) database]; | ||
| * }}} | ||
| */ | ||
| case class ShowColumnsCommand(table: TableIdentifier) extends RunnableCommand { | ||
| case class ShowColumnsCommand(tableName: TableIdentifier) extends RunnableCommand { | ||
| override val output: Seq[Attribute] = { | ||
| AttributeReference("col_name", StringType, nullable = false)() :: Nil | ||
| } | ||
|
|
||
| override def run(sparkSession: SparkSession): Seq[Row] = { | ||
| sparkSession.sessionState.catalog.getTableMetadata(table).schema.map { c => | ||
| val catalog = sparkSession.sessionState.catalog | ||
| val table = if (catalog.isTemporaryTable(tableName)) { | ||
| catalog.getTempViewMetadata(tableName.table) | ||
| } else { | ||
| catalog.getTableMetadata(tableName) | ||
| } | ||
| table.schema.map { c => | ||
| Row(c.name) | ||
| } | ||
| } | ||
|
|
@@ -634,7 +648,7 @@ case class ShowPartitionsCommand( | |
|
|
||
| override def run(sparkSession: SparkSession): Seq[Row] = { | ||
| val catalog = sparkSession.sessionState.catalog | ||
| val table = catalog.getNonTempTableMetadata(tableName) | ||
| val table = catalog.getTableMetadata(tableName) | ||
| val qualifiedName = table.identifier.quotedString | ||
|
|
||
| /** | ||
|
|
@@ -686,9 +700,7 @@ case class ShowCreateTableCommand(table: TableIdentifier) extends RunnableComman | |
|
|
||
| override def run(sparkSession: SparkSession): Seq[Row] = { | ||
| val catalog = sparkSession.sessionState.catalog | ||
| val db = table.database.getOrElse(catalog.getCurrentDatabase) | ||
| val qualifiedName = TableIdentifier(table.table, Some(db)) | ||
| val tableMetadata = catalog.getTableMetadata(qualifiedName) | ||
| val tableMetadata = catalog.getTableMetadata(table) | ||
|
|
||
| // TODO: unify this after we unify the CREATE TABLE syntax for hive serde and data source table. | ||
| val stmt = if (DDLUtils.isDatasourceTable(tableMetadata)) { | ||
|
|
||
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.
let's move these 2 methods to the right section:
handles only temp viewThere 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.
where do we need this method?
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.
: ) Just removed
getTempViewMetadataand movedgetTempViewMetadataOptionto the position you want