Skip to content

Commit dffb01f

Browse files
cloud-fandongjoon-hyun
authored andcommitted
[SPARK-34152][SQL][FOLLOWUP] Do not uncache the temp view if it doesn't exist
### What changes were proposed in this pull request? This PR fixes a mistake in #31273. When CREATE OR REPLACE a temp view, we need to uncache the to-be-replaced existing temp view. However, we shouldn't uncache if there is no existing temp view. This doesn't cause real issues because the uncache action is failure-safe. But it produces a lot of warning messages. ### Why are the changes needed? Avoid unnecessary warning logs. ### Does this PR introduce _any_ user-facing change? no ### How was this patch tested? manually run tests and check the warning messages. Closes #31650 from cloud-fan/warnning. Authored-by: Wenchen Fan <[email protected]> Signed-off-by: Dongjoon Hyun <[email protected]>
1 parent f7ac2d6 commit dffb01f

File tree

1 file changed

+10
-8
lines changed
  • sql/core/src/main/scala/org/apache/spark/sql/execution/command

1 file changed

+10
-8
lines changed

sql/core/src/main/scala/org/apache/spark/sql/execution/command/views.scala

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ case class CreateViewCommand(
115115

116116
if (viewType == LocalTempView) {
117117
val aliasedPlan = aliasPlan(sparkSession, analyzedPlan)
118-
if (replace && !isSamePlan(catalog.getRawTempView(name.table), aliasedPlan)) {
118+
if (replace && needsToUncache(catalog.getRawTempView(name.table), aliasedPlan)) {
119119
logInfo(s"Try to uncache ${name.quotedString} before replacing.")
120120
checkCyclicViewReference(analyzedPlan, Seq(name), name)
121121
CommandUtils.uncacheTableOrView(sparkSession, name.quotedString)
@@ -139,7 +139,7 @@ case class CreateViewCommand(
139139
val db = sparkSession.sessionState.conf.getConf(StaticSQLConf.GLOBAL_TEMP_DATABASE)
140140
val viewIdent = TableIdentifier(name.table, Option(db))
141141
val aliasedPlan = aliasPlan(sparkSession, analyzedPlan)
142-
if (replace && !isSamePlan(catalog.getRawGlobalTempView(name.table), aliasedPlan)) {
142+
if (replace && needsToUncache(catalog.getRawGlobalTempView(name.table), aliasedPlan)) {
143143
logInfo(s"Try to uncache ${viewIdent.quotedString} before replacing.")
144144
checkCyclicViewReference(analyzedPlan, Seq(viewIdent), viewIdent)
145145
CommandUtils.uncacheTableOrView(sparkSession, viewIdent.quotedString)
@@ -193,15 +193,17 @@ case class CreateViewCommand(
193193
}
194194

195195
/**
196-
* Checks if the temp view (the result of getTempViewRawPlan or getRawGlobalTempView) is storing
197-
* the same plan as the given aliased plan.
196+
* Checks if need to uncache the temp view being replaced.
198197
*/
199-
private def isSamePlan(
198+
private def needsToUncache(
200199
rawTempView: Option[LogicalPlan],
201200
aliasedPlan: LogicalPlan): Boolean = rawTempView match {
202-
case Some(TemporaryViewRelation(_, Some(p))) => p.sameResult(aliasedPlan)
203-
case Some(p) => p.sameResult(aliasedPlan)
204-
case _ => false
201+
// The temp view doesn't exist, no need to uncache.
202+
case None => false
203+
// Do not need to uncache if the to-be-replaced temp view plan and the new plan are the
204+
// same-result plans.
205+
case Some(TemporaryViewRelation(_, Some(p))) => !p.sameResult(aliasedPlan)
206+
case Some(p) => !p.sameResult(aliasedPlan)
205207
}
206208

207209
/**

0 commit comments

Comments
 (0)