diff --git a/sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/catalog/GlobalTempViewManager.scala b/sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/catalog/GlobalTempViewManager.scala index c7bd2a4cd800d..5141c66f86cd8 100644 --- a/sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/catalog/GlobalTempViewManager.scala +++ b/sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/catalog/GlobalTempViewManager.scala @@ -22,7 +22,6 @@ import javax.annotation.concurrent.GuardedBy import scala.collection.mutable import org.apache.spark.sql.catalyst.analysis.TempTableAlreadyExistsException -import org.apache.spark.sql.catalyst.plans.logical.LogicalPlan import org.apache.spark.sql.catalyst.util.StringUtils import org.apache.spark.sql.errors.QueryCompilationErrors @@ -40,12 +39,12 @@ class GlobalTempViewManager(val database: String) { /** List of view definitions, mapping from view name to logical plan. */ @GuardedBy("this") - private val viewDefinitions = new mutable.HashMap[String, LogicalPlan] + private val viewDefinitions = new mutable.HashMap[String, TemporaryViewRelation] /** * Returns the global view definition which matches the given name, or None if not found. */ - def get(name: String): Option[LogicalPlan] = synchronized { + def get(name: String): Option[TemporaryViewRelation] = synchronized { viewDefinitions.get(name) } @@ -55,7 +54,7 @@ class GlobalTempViewManager(val database: String) { */ def create( name: String, - viewDefinition: LogicalPlan, + viewDefinition: TemporaryViewRelation, overrideIfExists: Boolean): Unit = synchronized { if (!overrideIfExists && viewDefinitions.contains(name)) { throw new TempTableAlreadyExistsException(name) @@ -68,7 +67,7 @@ class GlobalTempViewManager(val database: String) { */ def update( name: String, - viewDefinition: LogicalPlan): Boolean = synchronized { + viewDefinition: TemporaryViewRelation): Boolean = synchronized { if (viewDefinitions.contains(name)) { viewDefinitions.put(name, viewDefinition) true 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 74a80f566f94a..c220a97df828b 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 @@ -101,7 +101,7 @@ class SessionCatalog( /** List of temporary views, mapping from table name to their logical plan. */ @GuardedBy("this") - protected val tempViews = new mutable.HashMap[String, LogicalPlan] + protected val tempViews = new mutable.HashMap[String, TemporaryViewRelation] // Note: we track current database here because certain operations do not explicitly // specify the database (e.g. DROP TABLE my_table). In these cases we must first @@ -573,13 +573,13 @@ class SessionCatalog( */ def createTempView( name: String, - tableDefinition: LogicalPlan, + viewDefinition: TemporaryViewRelation, overrideIfExists: Boolean): Unit = synchronized { val table = formatTableName(name) if (tempViews.contains(table) && !overrideIfExists) { throw new TempTableAlreadyExistsException(name) } - tempViews.put(table, tableDefinition) + tempViews.put(table, viewDefinition) } /** @@ -587,7 +587,7 @@ class SessionCatalog( */ def createGlobalTempView( name: String, - viewDefinition: LogicalPlan, + viewDefinition: TemporaryViewRelation, overrideIfExists: Boolean): Unit = { globalTempViewManager.create(formatTableName(name), viewDefinition, overrideIfExists) } @@ -598,7 +598,7 @@ class SessionCatalog( */ def alterTempViewDefinition( name: TableIdentifier, - viewDefinition: LogicalPlan): Boolean = synchronized { + viewDefinition: TemporaryViewRelation): Boolean = synchronized { val viewName = formatTableName(name.table) if (name.database.isEmpty) { if (tempViews.contains(viewName)) { @@ -617,14 +617,14 @@ class SessionCatalog( /** * Return a local temporary view exactly as it was stored. */ - def getRawTempView(name: String): Option[LogicalPlan] = synchronized { + def getRawTempView(name: String): Option[TemporaryViewRelation] = synchronized { tempViews.get(formatTableName(name)) } /** * Generate a [[View]] operator from the temporary view stored. */ - def getTempView(name: String): Option[LogicalPlan] = synchronized { + def getTempView(name: String): Option[View] = synchronized { getRawTempView(name).map(getTempViewPlan) } @@ -635,14 +635,14 @@ class SessionCatalog( /** * Return a global temporary view exactly as it was stored. */ - def getRawGlobalTempView(name: String): Option[LogicalPlan] = { + def getRawGlobalTempView(name: String): Option[TemporaryViewRelation] = { globalTempViewManager.get(formatTableName(name)) } /** * Generate a [[View]] operator from the global temporary view stored. */ - def getGlobalTempView(name: String): Option[LogicalPlan] = { + def getGlobalTempView(name: String): Option[View] = { getRawGlobalTempView(name).map(getTempViewPlan) } @@ -680,25 +680,10 @@ class SessionCatalog( def getTempViewOrPermanentTableMetadata(name: TableIdentifier): CatalogTable = synchronized { val table = formatTableName(name.table) if (name.database.isEmpty) { - tempViews.get(table).map { - case TemporaryViewRelation(metadata, _) => metadata - case plan => - CatalogTable( - identifier = TableIdentifier(table), - tableType = CatalogTableType.VIEW, - storage = CatalogStorageFormat.empty, - schema = plan.output.toStructType) - }.getOrElse(getTableMetadata(name)) + tempViews.get(table).map(_.tableMeta).getOrElse(getTableMetadata(name)) } else if (formatDatabaseName(name.database.get) == globalTempViewManager.database) { - globalTempViewManager.get(table).map { - case TemporaryViewRelation(metadata, _) => metadata - case plan => - CatalogTable( - identifier = TableIdentifier(table, Some(globalTempViewManager.database)), - tableType = CatalogTableType.VIEW, - storage = CatalogStorageFormat.empty, - schema = plan.output.toStructType) - }.getOrElse(throw new NoSuchTableException(globalTempViewManager.database, table)) + globalTempViewManager.get(table).map(_.tableMeta) + .getOrElse(throw new NoSuchTableException(globalTempViewManager.database, table)) } else { getTableMetadata(name) } @@ -834,20 +819,11 @@ class SessionCatalog( } } - private def getTempViewPlan(plan: LogicalPlan): LogicalPlan = { - plan match { - case TemporaryViewRelation(tableMeta, None) => - fromCatalogTable(tableMeta, isTempView = true) - case TemporaryViewRelation(tableMeta, Some(plan)) => - View(desc = tableMeta, isTempView = true, child = plan) - case other => other - } - } - - def getTempViewSchema(plan: LogicalPlan): StructType = { - plan match { - case viewInfo: TemporaryViewRelation => viewInfo.tableMeta.schema - case v => v.schema + private def getTempViewPlan(viewInfo: TemporaryViewRelation): View = { + if (viewInfo.plan.isEmpty) { + fromCatalogTable(viewInfo.tableMeta, isTempView = true) + } else { + View(desc = viewInfo.tableMeta, isTempView = true, child = viewInfo.plan.get) } } diff --git a/sql/catalyst/src/test/scala/org/apache/spark/sql/catalyst/analysis/AnalysisTest.scala b/sql/catalyst/src/test/scala/org/apache/spark/sql/catalyst/analysis/AnalysisTest.scala index 5877f19300323..f4217a43d2a28 100644 --- a/sql/catalyst/src/test/scala/org/apache/spark/sql/catalyst/analysis/AnalysisTest.scala +++ b/sql/catalyst/src/test/scala/org/apache/spark/sql/catalyst/analysis/AnalysisTest.scala @@ -21,28 +21,62 @@ import java.net.URI import java.util.Locale import org.apache.spark.sql.AnalysisException -import org.apache.spark.sql.catalyst.QueryPlanningTracker -import org.apache.spark.sql.catalyst.catalog.{CatalogDatabase, InMemoryCatalog, SessionCatalog} +import org.apache.spark.sql.catalyst.{QueryPlanningTracker, TableIdentifier} +import org.apache.spark.sql.catalyst.catalog.{CatalogDatabase, CatalogStorageFormat, CatalogTable, CatalogTableType, InMemoryCatalog, SessionCatalog, TemporaryViewRelation} +import org.apache.spark.sql.catalyst.catalog.CatalogTable.VIEW_STORING_ANALYZED_PLAN import org.apache.spark.sql.catalyst.parser.ParseException import org.apache.spark.sql.catalyst.plans.PlanTest import org.apache.spark.sql.catalyst.plans.logical._ import org.apache.spark.sql.catalyst.rules.Rule -import org.apache.spark.sql.internal.SQLConf +import org.apache.spark.sql.internal.{SQLConf, StaticSQLConf} trait AnalysisTest extends PlanTest { protected def extendedAnalysisRules: Seq[Rule[LogicalPlan]] = Nil + protected def createTempView( + catalog: SessionCatalog, + name: String, + plan: LogicalPlan, + overrideIfExists: Boolean): Unit = { + val identifier = TableIdentifier(name) + val metadata = CatalogTable( + identifier = identifier, + tableType = CatalogTableType.VIEW, + storage = CatalogStorageFormat.empty, + schema = plan.schema, + properties = Map((VIEW_STORING_ANALYZED_PLAN, "true"))) + val viewDefinition = TemporaryViewRelation(metadata, Some(plan)) + catalog.createTempView(name, viewDefinition, overrideIfExists) + } + + protected def createGlobalTempView( + catalog: SessionCatalog, + name: String, + plan: LogicalPlan, + overrideIfExists: Boolean): Unit = { + val globalDb = Some(SQLConf.get.getConf(StaticSQLConf.GLOBAL_TEMP_DATABASE)) + val identifier = TableIdentifier(name, globalDb) + val metadata = CatalogTable( + identifier = identifier, + tableType = CatalogTableType.VIEW, + storage = CatalogStorageFormat.empty, + schema = plan.schema, + properties = Map((VIEW_STORING_ANALYZED_PLAN, "true"))) + val viewDefinition = TemporaryViewRelation(metadata, Some(plan)) + catalog.createGlobalTempView(name, viewDefinition, overrideIfExists) + } + protected def getAnalyzer: Analyzer = { val catalog = new SessionCatalog(new InMemoryCatalog, FunctionRegistry.builtin) catalog.createDatabase( CatalogDatabase("default", "", new URI("loc"), Map.empty), ignoreIfExists = false) - catalog.createTempView("TaBlE", TestRelations.testRelation, overrideIfExists = true) - catalog.createTempView("TaBlE2", TestRelations.testRelation2, overrideIfExists = true) - catalog.createTempView("TaBlE3", TestRelations.testRelation3, overrideIfExists = true) - catalog.createGlobalTempView("TaBlE4", TestRelations.testRelation4, overrideIfExists = true) - catalog.createGlobalTempView("TaBlE5", TestRelations.testRelation5, overrideIfExists = true) + createTempView(catalog, "TaBlE", TestRelations.testRelation, overrideIfExists = true) + createTempView(catalog, "TaBlE2", TestRelations.testRelation2, overrideIfExists = true) + createTempView(catalog, "TaBlE3", TestRelations.testRelation3, overrideIfExists = true) + createGlobalTempView(catalog, "TaBlE4", TestRelations.testRelation4, overrideIfExists = true) + createGlobalTempView(catalog, "TaBlE5", TestRelations.testRelation5, overrideIfExists = true) new Analyzer(catalog) { override val extendedResolutionRules = EliminateSubqueryAliases +: extendedAnalysisRules } diff --git a/sql/catalyst/src/test/scala/org/apache/spark/sql/catalyst/analysis/DecimalPrecisionSuite.scala b/sql/catalyst/src/test/scala/org/apache/spark/sql/catalyst/analysis/DecimalPrecisionSuite.scala index 9892e62a9ce19..dd37bc021be77 100644 --- a/sql/catalyst/src/test/scala/org/apache/spark/sql/catalyst/analysis/DecimalPrecisionSuite.scala +++ b/sql/catalyst/src/test/scala/org/apache/spark/sql/catalyst/analysis/DecimalPrecisionSuite.scala @@ -28,7 +28,6 @@ import org.apache.spark.sql.catalyst.plans.logical.{LocalRelation, Project, Unio import org.apache.spark.sql.internal.SQLConf import org.apache.spark.sql.types._ - class DecimalPrecisionSuite extends AnalysisTest with BeforeAndAfter { private val catalog = new SessionCatalog(new InMemoryCatalog, EmptyFunctionRegistry) private val analyzer = new Analyzer(catalog) @@ -49,10 +48,6 @@ class DecimalPrecisionSuite extends AnalysisTest with BeforeAndAfter { private val f: Expression = UnresolvedAttribute("f") private val b: Expression = UnresolvedAttribute("b") - before { - catalog.createTempView("table", relation, overrideIfExists = true) - } - private def checkType(expression: Expression, expectedType: DataType): Unit = { val plan = Project(Seq(Alias(expression, "c")()), relation) assert(analyzer.execute(plan).schema.fields(0).dataType === expectedType) diff --git a/sql/catalyst/src/test/scala/org/apache/spark/sql/catalyst/catalog/SessionCatalogSuite.scala b/sql/catalyst/src/test/scala/org/apache/spark/sql/catalyst/catalog/SessionCatalogSuite.scala index ce06a76b8c1b6..954a57acd04cd 100644 --- a/sql/catalyst/src/test/scala/org/apache/spark/sql/catalyst/catalog/SessionCatalogSuite.scala +++ b/sql/catalyst/src/test/scala/org/apache/spark/sql/catalyst/catalog/SessionCatalogSuite.scala @@ -305,17 +305,17 @@ abstract class SessionCatalogSuite extends AnalysisTest with Eventually { withBasicCatalog { catalog => val tempTable1 = Range(1, 10, 1, 10) val tempTable2 = Range(1, 20, 2, 10) - catalog.createTempView("tbl1", tempTable1, overrideIfExists = false) - catalog.createTempView("tbl2", tempTable2, overrideIfExists = false) + createTempView(catalog, "tbl1", tempTable1, overrideIfExists = false) + createTempView(catalog, "tbl2", tempTable2, overrideIfExists = false) assert(getTempViewRawPlan(catalog.getTempView("tbl1")) == Option(tempTable1)) assert(getTempViewRawPlan(catalog.getTempView("tbl2")) == Option(tempTable2)) assert(getTempViewRawPlan(catalog.getTempView("tbl3")).isEmpty) // Temporary view already exists intercept[TempTableAlreadyExistsException] { - catalog.createTempView("tbl1", tempTable1, overrideIfExists = false) + createTempView(catalog, "tbl1", tempTable1, overrideIfExists = false) } // Temporary view already exists but we override it - catalog.createTempView("tbl1", tempTable2, overrideIfExists = true) + createTempView(catalog, "tbl1", tempTable2, overrideIfExists = true) assert(getTempViewRawPlan(catalog.getTempView("tbl1")) == Option(tempTable2)) } } @@ -356,7 +356,7 @@ abstract class SessionCatalogSuite extends AnalysisTest with Eventually { test("drop temp table") { withBasicCatalog { catalog => val tempTable = Range(1, 10, 2, 10) - catalog.createTempView("tbl1", tempTable, overrideIfExists = false) + createTempView(catalog, "tbl1", tempTable, overrideIfExists = false) catalog.setCurrentDatabase("db2") assert(getTempViewRawPlan(catalog.getTempView("tbl1")) == Some(tempTable)) assert(catalog.externalCatalog.listTables("db2").toSet == Set("tbl1", "tbl2")) @@ -368,7 +368,7 @@ abstract class SessionCatalogSuite extends AnalysisTest with Eventually { catalog.dropTable(TableIdentifier("tbl1"), ignoreIfNotExists = false, purge = false) assert(catalog.externalCatalog.listTables("db2").toSet == Set("tbl2")) // If database is specified, temp tables are never dropped - catalog.createTempView("tbl1", tempTable, overrideIfExists = false) + createTempView(catalog, "tbl1", tempTable, overrideIfExists = false) catalog.createTable(newTable("tbl1", "db2"), ignoreIfExists = false) catalog.dropTable(TableIdentifier("tbl1", Some("db2")), ignoreIfNotExists = false, purge = false) @@ -423,7 +423,7 @@ abstract class SessionCatalogSuite extends AnalysisTest with Eventually { test("rename temp table") { withBasicCatalog { catalog => val tempTable = Range(1, 10, 2, 10) - catalog.createTempView("tbl1", tempTable, overrideIfExists = false) + createTempView(catalog, "tbl1", tempTable, overrideIfExists = false) catalog.setCurrentDatabase("db2") assert(getTempViewRawPlan(catalog.getTempView("tbl1")) == Option(tempTable)) assert(catalog.externalCatalog.listTables("db2").toSet == Set("tbl1", "tbl2")) @@ -625,7 +625,7 @@ abstract class SessionCatalogSuite extends AnalysisTest with Eventually { withBasicCatalog { catalog => val tempTable1 = Range(1, 10, 1, 10) val metastoreTable1 = catalog.externalCatalog.getTable("db2", "tbl1") - catalog.createTempView("tbl1", tempTable1, overrideIfExists = false) + createTempView(catalog, "tbl1", tempTable1, overrideIfExists = false) catalog.setCurrentDatabase("db2") // If we explicitly specify the database, we'll look up the relation in that database assert(catalog.lookupRelation(TableIdentifier("tbl1", Some("db2"))).children.head @@ -701,7 +701,7 @@ abstract class SessionCatalogSuite extends AnalysisTest with Eventually { assert(catalog.tableExists(TableIdentifier("tbl1"))) assert(catalog.tableExists(TableIdentifier("tbl2"))) - catalog.createTempView("tbl3", tempTable, overrideIfExists = false) + createTempView(catalog, "tbl3", tempTable, overrideIfExists = false) // tableExists should not check temp view. assert(!catalog.tableExists(TableIdentifier("tbl3"))) } @@ -718,7 +718,7 @@ abstract class SessionCatalogSuite extends AnalysisTest with Eventually { catalog.getTempViewOrPermanentTableMetadata(TableIdentifier("view1", Some("default"))) }.getMessage - catalog.createTempView("view1", tempTable, overrideIfExists = false) + createTempView(catalog, "view1", tempTable, overrideIfExists = false) assert(catalog.getTempViewOrPermanentTableMetadata( TableIdentifier("view1")).identifier.table == "view1") assert(catalog.getTempViewOrPermanentTableMetadata( @@ -733,8 +733,8 @@ abstract class SessionCatalogSuite extends AnalysisTest with Eventually { test("list tables without pattern") { withBasicCatalog { catalog => val tempTable = Range(1, 10, 2, 10) - catalog.createTempView("tbl1", tempTable, overrideIfExists = false) - catalog.createTempView("tbl4", tempTable, overrideIfExists = false) + createTempView(catalog, "tbl1", tempTable, overrideIfExists = false) + createTempView(catalog, "tbl4", tempTable, overrideIfExists = false) assert(catalog.listTables("db1").toSet == Set(TableIdentifier("tbl1"), TableIdentifier("tbl4"))) assert(catalog.listTables("db2").toSet == @@ -751,8 +751,8 @@ abstract class SessionCatalogSuite extends AnalysisTest with Eventually { test("list tables with pattern") { withBasicCatalog { catalog => val tempTable = Range(1, 10, 2, 10) - catalog.createTempView("tbl1", tempTable, overrideIfExists = false) - catalog.createTempView("tbl4", tempTable, overrideIfExists = false) + createTempView(catalog, "tbl1", tempTable, overrideIfExists = false) + createTempView(catalog, "tbl4", tempTable, overrideIfExists = false) assert(catalog.listTables("db1", "*").toSet == catalog.listTables("db1").toSet) assert(catalog.listTables("db2", "*").toSet == catalog.listTables("db2").toSet) assert(catalog.listTables("db2", "tbl*").toSet == @@ -774,8 +774,8 @@ abstract class SessionCatalogSuite extends AnalysisTest with Eventually { catalog.createTable(newTable("tbl1", "mydb"), ignoreIfExists = false) catalog.createTable(newTable("tbl2", "mydb"), ignoreIfExists = false) val tempTable = Range(1, 10, 2, 10) - catalog.createTempView("temp_view1", tempTable, overrideIfExists = false) - catalog.createTempView("temp_view4", tempTable, overrideIfExists = false) + createTempView(catalog, "temp_view1", tempTable, overrideIfExists = false) + createTempView(catalog, "temp_view4", tempTable, overrideIfExists = false) assert(catalog.listTables("mydb").toSet == catalog.listTables("mydb", "*").toSet) assert(catalog.listTables("mydb").toSet == catalog.listTables("mydb", "*", true).toSet) @@ -801,8 +801,8 @@ abstract class SessionCatalogSuite extends AnalysisTest with Eventually { test("list temporary view with pattern") { withBasicCatalog { catalog => val tempTable = Range(1, 10, 2, 10) - catalog.createTempView("temp_view1", tempTable, overrideIfExists = false) - catalog.createTempView("temp_view4", tempTable, overrideIfExists = false) + createTempView(catalog, "temp_view1", tempTable, overrideIfExists = false) + createTempView(catalog, "temp_view4", tempTable, overrideIfExists = false) assert(catalog.listLocalTempViews("*").toSet == Set(TableIdentifier("temp_view1"), TableIdentifier("temp_view4"))) assert(catalog.listLocalTempViews("temp_view*").toSet == @@ -815,10 +815,10 @@ abstract class SessionCatalogSuite extends AnalysisTest with Eventually { test("list global temporary view and local temporary view with pattern") { withBasicCatalog { catalog => val tempTable = Range(1, 10, 2, 10) - catalog.createTempView("temp_view1", tempTable, overrideIfExists = false) - catalog.createTempView("temp_view4", tempTable, overrideIfExists = false) - catalog.globalTempViewManager.create("global_temp_view1", tempTable, overrideIfExists = false) - catalog.globalTempViewManager.create("global_temp_view2", tempTable, overrideIfExists = false) + createTempView(catalog, "temp_view1", tempTable, overrideIfExists = false) + createTempView(catalog, "temp_view4", tempTable, overrideIfExists = false) + createGlobalTempView(catalog, "global_temp_view1", tempTable, overrideIfExists = false) + createGlobalTempView(catalog, "global_temp_view2", tempTable, overrideIfExists = false) assert(catalog.listTables(catalog.globalTempViewManager.database, "*").toSet == Set(TableIdentifier("temp_view1"), TableIdentifier("temp_view4"), @@ -1581,7 +1581,7 @@ abstract class SessionCatalogSuite extends AnalysisTest with Eventually { test("copy SessionCatalog state - temp views") { withEmptyCatalog { original => val tempTable1 = Range(1, 10, 1, 10) - original.createTempView("copytest1", tempTable1, overrideIfExists = false) + createTempView(original, "copytest1", tempTable1, overrideIfExists = false) // check if tables copied over val clone = new SessionCatalog(original.externalCatalog) @@ -1595,7 +1595,7 @@ abstract class SessionCatalogSuite extends AnalysisTest with Eventually { assert(getTempViewRawPlan(original.getTempView("copytest1")) == Some(tempTable1)) val tempTable2 = Range(1, 20, 2, 10) - original.createTempView("copytest2", tempTable2, overrideIfExists = false) + createTempView(original, "copytest2", tempTable2, overrideIfExists = false) assert(clone.getTempView("copytest2").isEmpty) } } @@ -1696,13 +1696,13 @@ abstract class SessionCatalogSuite extends AnalysisTest with Eventually { test("SPARK-34197: refreshTable should not invalidate the relation cache for temporary views") { withBasicCatalog { catalog => - catalog.createTempView("tbl1", Range(1, 10, 1, 10), false) + createTempView(catalog, "tbl1", Range(1, 10, 1, 10), false) val qualifiedName1 = QualifiedTableName("default", "tbl1") catalog.cacheTable(qualifiedName1, Range(1, 10, 1, 10)) catalog.refreshTable(TableIdentifier("tbl1")) assert(catalog.getCachedTable(qualifiedName1) != null) - catalog.createGlobalTempView("tbl2", Range(2, 10, 1, 10), false) + createGlobalTempView(catalog, "tbl2", Range(2, 10, 1, 10), false) val qualifiedName2 = QualifiedTableName(catalog.globalTempViewManager.database, "tbl2") catalog.cacheTable(qualifiedName2, Range(2, 10, 1, 10)) catalog.refreshTable(TableIdentifier("tbl2", Some(catalog.globalTempViewManager.database))) diff --git a/sql/core/src/test/scala/org/apache/spark/sql/execution/command/PlanResolutionSuite.scala b/sql/core/src/test/scala/org/apache/spark/sql/execution/command/PlanResolutionSuite.scala index 3307410dbc447..4fd7bad4e376e 100644 --- a/sql/core/src/test/scala/org/apache/spark/sql/execution/command/PlanResolutionSuite.scala +++ b/sql/core/src/test/scala/org/apache/spark/sql/execution/command/PlanResolutionSuite.scala @@ -121,7 +121,7 @@ class PlanResolutionSuite extends AnalysisTest { new InMemoryCatalog, EmptyFunctionRegistry, new SQLConf().copy(SQLConf.CASE_SENSITIVE -> true)) - v1SessionCatalog.createTempView("v", LocalRelation(Nil), false) + createTempView(v1SessionCatalog, "v", LocalRelation(Nil), false) private val catalogManagerWithDefault = { val manager = mock(classOf[CatalogManager]) diff --git a/sql/core/src/test/scala/org/apache/spark/sql/internal/CatalogSuite.scala b/sql/core/src/test/scala/org/apache/spark/sql/internal/CatalogSuite.scala index 31b44802fb4ad..edd96e8337918 100644 --- a/sql/core/src/test/scala/org/apache/spark/sql/internal/CatalogSuite.scala +++ b/sql/core/src/test/scala/org/apache/spark/sql/internal/CatalogSuite.scala @@ -22,6 +22,7 @@ import java.io.File import org.apache.spark.sql.AnalysisException import org.apache.spark.sql.catalog.{Column, Database, Function, Table} import org.apache.spark.sql.catalyst.{FunctionIdentifier, ScalaReflection, TableIdentifier} +import org.apache.spark.sql.catalyst.analysis.AnalysisTest import org.apache.spark.sql.catalyst.catalog._ import org.apache.spark.sql.catalyst.expressions.Expression import org.apache.spark.sql.catalyst.plans.logical.Range @@ -33,7 +34,7 @@ import org.apache.spark.storage.StorageLevel /** * Tests for the user-facing [[org.apache.spark.sql.catalog.Catalog]]. */ -class CatalogSuite extends SharedSparkSession { +class CatalogSuite extends SharedSparkSession with AnalysisTest { import testImplicits._ private def sessionCatalog: SessionCatalog = spark.sessionState.catalog @@ -58,7 +59,7 @@ class CatalogSuite extends SharedSparkSession { } private def createTempTable(name: String): Unit = { - sessionCatalog.createTempView(name, Range(1, 2, 3, 4), overrideIfExists = true) + createTempView(sessionCatalog, name, Range(1, 2, 3, 4), overrideIfExists = true) } private def dropTable(name: String, db: Option[String] = None): Unit = { @@ -534,8 +535,8 @@ class CatalogSuite extends SharedSparkSession { dropTable("my_temp_table") // drop table in original session assert(spark.catalog.listTables().collect().map(_.name).toSet == Set()) assert(forkedSession.catalog.listTables().collect().map(_.name).toSet == Set("my_temp_table")) - forkedSession.sessionState.catalog - .createTempView("fork_table", Range(1, 2, 3, 4), overrideIfExists = true) + createTempView( + forkedSession.sessionState.catalog, "fork_table", Range(1, 2, 3, 4), overrideIfExists = true) assert(spark.catalog.listTables().collect().map(_.name).toSet == Set()) } diff --git a/sql/hive-thriftserver/src/main/scala/org/apache/spark/sql/hive/thriftserver/SparkGetColumnsOperation.scala b/sql/hive-thriftserver/src/main/scala/org/apache/spark/sql/hive/thriftserver/SparkGetColumnsOperation.scala index 580e267468593..4ba6dbf00c0f6 100644 --- a/sql/hive-thriftserver/src/main/scala/org/apache/spark/sql/hive/thriftserver/SparkGetColumnsOperation.scala +++ b/sql/hive-thriftserver/src/main/scala/org/apache/spark/sql/hive/thriftserver/SparkGetColumnsOperation.scala @@ -105,7 +105,7 @@ private[hive] class SparkGetColumnsOperation( val databasePattern = Pattern.compile(CLIServiceUtils.patternToRegex(schemaName)) if (databasePattern.matcher(globalTempViewDb).matches()) { catalog.globalTempViewManager.listViewNames(tablePattern).foreach { globalTempView => - catalog.getRawGlobalTempView(globalTempView).map(catalog.getTempViewSchema).foreach { + catalog.getRawGlobalTempView(globalTempView).map(_.tableMeta.schema).foreach { schema => addToRowSet(columnPattern, globalTempViewDb, globalTempView, schema) } } @@ -113,7 +113,7 @@ private[hive] class SparkGetColumnsOperation( // Temporary views catalog.listLocalTempViews(tablePattern).foreach { localTempView => - catalog.getRawTempView(localTempView.table).map(catalog.getTempViewSchema).foreach { + catalog.getRawTempView(localTempView.table).map(_.tableMeta.schema).foreach { schema => addToRowSet(columnPattern, null, localTempView.table, schema) } }