@@ -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