-
Notifications
You must be signed in to change notification settings - Fork 29k
[SPARK-34490][SQL] Analysis should fail if the view refers a dropped table #31606
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
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 |
|---|---|---|
|
|
@@ -19,6 +19,8 @@ package org.apache.spark.sql.catalyst.analysis | |
|
|
||
| import java.io.File | ||
|
|
||
| import scala.collection.JavaConverters._ | ||
|
|
||
| import org.mockito.ArgumentMatchers.any | ||
| import org.mockito.Mockito._ | ||
| import org.mockito.invocation.InvocationOnMock | ||
|
|
@@ -27,8 +29,8 @@ import org.scalatest.matchers.must.Matchers | |
| import org.apache.spark.sql.catalyst.TableIdentifier | ||
| import org.apache.spark.sql.catalyst.catalog.{CatalogDatabase, CatalogStorageFormat, CatalogTable, CatalogTableType, ExternalCatalog, InMemoryCatalog, SessionCatalog} | ||
| import org.apache.spark.sql.catalyst.dsl.plans._ | ||
| import org.apache.spark.sql.connector.InMemoryTableCatalog | ||
| import org.apache.spark.sql.connector.catalog.{CatalogManager, CatalogNotFoundException, Identifier, Table, V1Table} | ||
| import org.apache.spark.sql.connector.{InMemoryTable, InMemoryTableCatalog} | ||
| import org.apache.spark.sql.connector.catalog.{CatalogManager, CatalogNotFoundException, Identifier, Table} | ||
| import org.apache.spark.sql.types._ | ||
|
|
||
| class TableLookupCacheSuite extends AnalysisTest with Matchers { | ||
|
|
@@ -46,7 +48,12 @@ class TableLookupCacheSuite extends AnalysisTest with Matchers { | |
| ignoreIfExists = false) | ||
| val v2Catalog = new InMemoryTableCatalog { | ||
| override def loadTable(ident: Identifier): Table = { | ||
| V1Table(externalCatalog.getTable("default", ident.name)) | ||
| val catalogTable = externalCatalog.getTable("default", ident.name) | ||
| new InMemoryTable( | ||
| catalogTable.identifier.table, | ||
| catalogTable.schema, | ||
| Array.empty, | ||
| Map.empty[String, String].asJava) | ||
|
Contributor
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. change V1Table to V2Table here, because to lookup V1 table, the catalog will return |
||
| } | ||
| override def name: String = CatalogManager.SESSION_CATALOG_NAME | ||
| } | ||
|
|
||
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.
when shall we skip the check?
Uh oh!
There was an error while loading. Please reload this page.
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.
For
UnresolvedView,UnresolvedTable,UnresolvedTableOrView, we uselookupTempViewto check whether the temp view exists, but it's ok to skip the checkAnalysis. For example:UnresolvedTable, if it is a view, should analyzer should throwexpectTableNotViewErrorrather thantable or view not foundThere 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.
@imback82 This is something we should improve. For
SELECT ... FROM viewandDROP VIEW view, the way to lookup the view should be different.For
SELECT ... FROM view, we must fully resolve the view, as we need to execute it.For
DROP VIEW view, we only need to get the view metadata entry. The same toALTER VIEW ....I think we should change how we resolve
UnresolvedTableOrViewandUnresolvedView, to only get the view metadata.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.
OK, I will think about this.