Skip to content
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

[SPARK-34152][SQL][FOLLOW-UP] Global temp view's identifier should be correctly stored #31783

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ case class CreateViewCommand(
originalText))
} else {
TemporaryViewRelation(
prepareTemporaryViewFromDataFrame(name, aliasedPlan),
prepareTemporaryViewFromDataFrame(viewIdent, aliasedPlan),
Some(aliasedPlan))
}
catalog.createGlobalTempView(name.table, tableDefinition, overrideIfExists = replace)
Expand Down
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) {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This has no effect for permanent view, and please let me know if this is not desirable. I can introduce isTempView for each suite and only apply this if the suite is for a local or global temp view.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it's ok to have a little waste in the test.

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))
}
}