-
Notifications
You must be signed in to change notification settings - Fork 29k
[SPARK-43203][SQL] Move all Drop Table case to DataSource V2 #41348
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 all commits
bfd7c2f
5d0677d
6e1628c
e237366
719eb22
9927414
bfed49e
85164da
c477802
2a77746
b9e5488
9ed2051
93c632d
8282f87
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -24,6 +24,7 @@ import org.apache.hadoop.fs.{FileSystem, Path} | |
| import org.apache.spark.internal.Logging | ||
| import org.apache.spark.internal.config.ConfigEntry | ||
| import org.apache.spark.sql.{Dataset, SparkSession} | ||
| import org.apache.spark.sql.catalyst.catalog.HiveTableRelation | ||
| import org.apache.spark.sql.catalyst.expressions.{Attribute, SubqueryExpression} | ||
| import org.apache.spark.sql.catalyst.optimizer.EliminateResolvedHint | ||
| import org.apache.spark.sql.catalyst.plans.logical.{IgnoreCachedData, LogicalPlan, ResolvedHint, SubqueryAlias, View} | ||
|
|
@@ -190,6 +191,11 @@ class CacheManager extends Logging with AdaptiveSparkPlanHelper { | |
| isSameName(ident.qualifier :+ ident.name) && | ||
| isSameName(v1Ident.catalog.toSeq ++ v1Ident.database :+ v1Ident.table) | ||
|
|
||
| case SubqueryAlias(ident, HiveTableRelation(catalogTable, _, _, _, _)) => | ||
|
Member
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. Add support for |
||
| val v1Ident = catalogTable.identifier | ||
| isSameName(ident.qualifier :+ ident.name) && | ||
| isSameName(v1Ident.catalog.toSeq ++ v1Ident.database :+ v1Ident.table) | ||
|
|
||
| case _ => false | ||
| } | ||
| } | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -71,7 +71,12 @@ class V2SessionCatalog(catalog: SessionCatalog) | |
| } | ||
|
|
||
| override def loadTable(ident: Identifier): Table = { | ||
| V1Table(catalog.getTableMetadata(ident.asTableIdentifier)) | ||
| try { | ||
| V1Table(catalog.getTableMetadata(ident.asTableIdentifier)) | ||
| } catch { | ||
| case _: NoSuchDatabaseException => | ||
|
Member
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. loadTable will return
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. does it cause test failures?
Member
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. Yes, the |
||
| throw QueryCompilationErrors.noSuchTableError(ident) | ||
| } | ||
| } | ||
|
|
||
| override def loadTable(ident: Identifier, timestamp: Long): Table = { | ||
|
|
@@ -110,6 +115,10 @@ class V2SessionCatalog(catalog: SessionCatalog) | |
| createTable(ident, CatalogV2Util.v2ColumnsToStructType(columns), partitions, properties) | ||
| } | ||
|
|
||
| override def purgeTable(ident: Identifier): Boolean = { | ||
| dropTableInternal(ident, purge = true) | ||
| } | ||
|
|
||
| // TODO: remove it when no tests calling this deprecated method. | ||
| override def createTable( | ||
| ident: Identifier, | ||
|
|
@@ -194,16 +203,29 @@ class V2SessionCatalog(catalog: SessionCatalog) | |
| } | ||
|
|
||
| override def dropTable(ident: Identifier): Boolean = { | ||
| dropTableInternal(ident) | ||
| } | ||
|
|
||
| private def dropTableInternal(ident: Identifier, purge: Boolean = false): Boolean = { | ||
| try { | ||
| if (loadTable(ident) != null) { | ||
| catalog.dropTable( | ||
| ident.asTableIdentifier, | ||
| ignoreIfNotExists = true, | ||
| purge = true /* skip HDFS trash */) | ||
| true | ||
| } else { | ||
| false | ||
| loadTable(ident) match { | ||
| case V1Table(v1Table) if v1Table.tableType == CatalogTableType.VIEW => | ||
| throw QueryCompilationErrors.wrongCommandForObjectTypeError( | ||
| operation = "DROP TABLE", | ||
| requiredType = s"${CatalogTableType.EXTERNAL.name} or" + | ||
| s" ${CatalogTableType.MANAGED.name}", | ||
| objectName = v1Table.qualifiedName, | ||
| foundType = v1Table.tableType.name, | ||
| alternative = "DROP VIEW" | ||
| ) | ||
| case _ => | ||
| } | ||
| catalog.invalidateCachedTable(ident.asTableIdentifier) | ||
| catalog.dropTable( | ||
| ident.asTableIdentifier, | ||
| ignoreIfNotExists = true, | ||
| purge = purge) | ||
| true | ||
| } catch { | ||
| case _: NoSuchTableException => | ||
| false | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.