-
Notifications
You must be signed in to change notification settings - Fork 29.3k
[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 9 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
This file was deleted.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -849,6 +849,7 @@ class SessionCatalog( | |
| tempViews.remove(table) | ||
| } | ||
| } | ||
| invalidateCachedTable(name) | ||
| } | ||
|
|
||
| /** | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,63 @@ | ||
| /* | ||
| * Licensed to the Apache Software Foundation (ASF) under one or more | ||
| * contributor license agreements. See the NOTICE file distributed with | ||
| * this work for additional information regarding copyright ownership. | ||
| * The ASF licenses this file to You under the Apache License, Version 2.0 | ||
| * (the "License"); you may not use this file except in compliance with | ||
| * the License. You may obtain a copy of the License at | ||
| * | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, software | ||
| * distributed under the License is distributed on an "AS IS" BASIS, | ||
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| * See the License for the specific language governing permissions and | ||
| * limitations under the License. | ||
| */ | ||
|
|
||
| package org.apache.spark.sql.internal.connector | ||
|
|
||
| import java.util.{Objects, StringJoiner} | ||
|
|
||
| import org.apache.spark.annotation.Evolving | ||
| import org.apache.spark.sql.catalyst.util.quoteIfNeeded | ||
| import org.apache.spark.sql.connector.catalog.Identifier | ||
|
|
||
| /** | ||
| * An {@link Identifier} implementation. | ||
| */ | ||
| @Evolving | ||
| class IdentifierImpl(namespace: Array[String], name: String) | ||
|
Hisoka-X marked this conversation as resolved.
Outdated
|
||
| extends Identifier { | ||
|
|
||
| assert(namespace != null, "Identifier namespace cannot be null") | ||
| assert(name != null, "Identifier name cannot be null") | ||
|
|
||
| override def namespace(): Array[String] = namespace | ||
|
|
||
| override def name(): String = name | ||
|
|
||
| override def toString: String = { | ||
| val joiner = new StringJoiner(".") | ||
| for (p <- namespace) { | ||
| joiner.add(quoteIfNeeded(p)) | ||
| } | ||
| joiner.add(quoteIfNeeded(name)) | ||
| joiner.toString | ||
| } | ||
|
|
||
| override def equals(o: Any): Boolean = { | ||
| o match { | ||
| case other: IdentifierImpl => (namespace sameElements other.namespace) && | ||
| name.equals(other.name) | ||
| case _ => false | ||
| } | ||
| } | ||
|
|
||
| override def hashCode: Int = { | ||
| var result = Objects.hash(name) | ||
| result = 31 * result + namespace.toSeq.hashCode() | ||
| result | ||
| } | ||
|
|
||
| } | ||
| 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,12 +203,27 @@ 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) { | ||
| val table = loadTable(ident) | ||
| if (table != null) { | ||
|
Hisoka-X marked this conversation as resolved.
Outdated
|
||
| val v1Table = table.asInstanceOf[V1Table].v1Table | ||
|
Hisoka-X marked this conversation as resolved.
Outdated
|
||
| if (v1Table.tableType == CatalogTableType.VIEW) { | ||
| throw QueryCompilationErrors.wrongCommandForObjectTypeError( | ||
| operation = "DROP TABLE", | ||
| requiredType = s"${CatalogTableType.EXTERNAL.name} or ${CatalogTableType.MANAGED.name}", | ||
| objectName = v1Table.qualifiedName, | ||
| foundType = v1Table.tableType.name, | ||
| alternative = "DROP VIEW" | ||
| ) | ||
| } | ||
| catalog.dropTable( | ||
| ident.asTableIdentifier, | ||
| ignoreIfNotExists = true, | ||
| purge = true /* skip HDFS trash */) | ||
| purge = purge) | ||
| true | ||
| } else { | ||
| false | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.