Skip to content

Commit

Permalink
Address PR comments
Browse files Browse the repository at this point in the history
  • Loading branch information
imback82 committed Mar 9, 2021
1 parent e0dcec2 commit 3d2ef7f
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ import org.apache.spark.sql._
import org.apache.spark.sql.catalyst.TableIdentifier
import org.apache.spark.sql.catalyst.analysis.NoSuchTableException
import org.apache.spark.sql.catalyst.parser.ParseException
import org.apache.spark.sql.catalyst.plans.logical.View
import org.apache.spark.sql.internal.SQLConf._
import org.apache.spark.sql.test.{SharedSparkSession, SQLTestUtils}

Expand Down Expand Up @@ -910,21 +909,4 @@ abstract class SQLViewSuite extends QueryTest with SQLTestUtils {
}
}
}

test("SPARK-34152: global temp view's identifier should be correctly stored") {
Seq(true, false).foreach { storeAnalyzed =>
withSQLConf(STORE_ANALYZED_PLAN_FOR_VIEW.key -> storeAnalyzed.toString) {
withGlobalTempView("v") {
sql("CREATE GLOBAL TEMPORARY VIEW v AS SELECT 1")
val globalTempDB = spark.sharedState.globalTempViewManager.database
val globalTempView = spark.sessionState.catalog.getGlobalTempView("v")
globalTempView match {
case Some(v: View) if v.isTempView =>
assert(v.desc.identifier == TableIdentifier("v", Some(globalTempDB)))
case _ => fail(s"Global temp view not found: $globalTempDB.v")
}
}
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
package org.apache.spark.sql.execution

import org.apache.spark.sql.{AnalysisException, QueryTest, Row}
import org.apache.spark.sql.catalyst.TableIdentifier
import org.apache.spark.sql.catalyst.plans.logical.Repartition
import org.apache.spark.sql.internal.SQLConf._
import org.apache.spark.sql.test.{SharedSparkSession, SQLTestUtils}
Expand All @@ -32,6 +33,7 @@ abstract class SQLViewTestSuite extends QueryTest with SQLTestUtils {

protected def viewTypeString: String
protected def formattedViewName(viewName: String): String
protected def tableIdentifier(viewName: String): TableIdentifier

def createView(
viewName: String,
Expand Down Expand Up @@ -293,22 +295,45 @@ abstract class SQLViewTestSuite extends QueryTest with SQLTestUtils {
}
}
}

test("SPARK-34152: view's identifier should be correctly stored") {
Seq(true, false).foreach { storeAnalyzed =>
withSQLConf(STORE_ANALYZED_PLAN_FOR_VIEW.key -> storeAnalyzed.toString) {
val viewName = createView("v", "SELECT 1")
withView(viewName) {
val tblIdent = tableIdentifier("v")
val metadata = spark.sessionState.catalog.getTempViewOrPermanentTableMetadata(tblIdent)
assert(metadata.identifier == tblIdent)
}
}
}
}
}

class LocalTempViewTestSuite extends SQLViewTestSuite with SharedSparkSession {
override protected def viewTypeString: String = "TEMPORARY VIEW"
override protected def formattedViewName(viewName: String): String = viewName
override protected def tableIdentifier(viewName: String): TableIdentifier = {
TableIdentifier(viewName)
}
}

class GlobalTempViewTestSuite extends SQLViewTestSuite with SharedSparkSession {
private def db: String = spark.sharedState.globalTempViewManager.database
override protected def viewTypeString: String = "GLOBAL TEMPORARY VIEW"
override protected def formattedViewName(viewName: String): String = {
val globalTempDB = spark.sharedState.globalTempViewManager.database
s"$globalTempDB.$viewName"
s"$db.$viewName"
}
override protected def tableIdentifier(viewName: String): TableIdentifier = {
TableIdentifier(viewName, Some(db))
}
}

class PersistedViewTestSuite extends SQLViewTestSuite with SharedSparkSession {
private def db: String = "default"
override protected def viewTypeString: String = "VIEW"
override protected def formattedViewName(viewName: String): String = s"default.$viewName"
override protected def formattedViewName(viewName: String): String = s"$db.$viewName"
override protected def tableIdentifier(viewName: String): TableIdentifier = {
TableIdentifier(viewName, Some(db))
}
}

0 comments on commit 3d2ef7f

Please sign in to comment.