imback82 commented on a change in pull request #31652:
URL: https://github.com/apache/spark/pull/31652#discussion_r590988252
##########
File path:
sql/core/src/main/scala/org/apache/spark/sql/execution/command/views.scala
##########
@@ -192,38 +170,6 @@ case class CreateViewCommand(
Seq.empty[Row]
}
- /**
- * Checks if need to uncache the temp view being replaced.
- */
- private def needsToUncache(
- rawTempView: Option[LogicalPlan],
- aliasedPlan: LogicalPlan): Boolean = rawTempView match {
- // The temp view doesn't exist, no need to uncache.
- case None => false
- // Do not need to uncache if the to-be-replaced temp view plan and the new
plan are the
- // same-result plans.
- case Some(TemporaryViewRelation(_, Some(p))) => !p.sameResult(aliasedPlan)
- case Some(p) => !p.sameResult(aliasedPlan)
- }
-
- /**
- * If `userSpecifiedColumns` is defined, alias the analyzed plan to the user
specified columns,
- * else return the analyzed plan directly.
- */
- private def aliasPlan(session: SparkSession, analyzedPlan: LogicalPlan):
LogicalPlan = {
Review comment:
This is moved to `ViewHelper`.
##########
File path:
sql/core/src/main/scala/org/apache/spark/sql/execution/command/views.scala
##########
@@ -268,30 +268,32 @@ case class AlterViewAsCommand(
name: TableIdentifier,
originalText: String,
query: LogicalPlan) extends RunnableCommand {
+ require(query.resolved)
import ViewHelper._
override def innerChildren: Seq[QueryPlan[_]] = Seq(query)
override def run(session: SparkSession): Seq[Row] = {
- // If the plan cannot be analyzed, throw an exception and don't proceed.
- val qe = session.sessionState.executePlan(query)
- qe.assertAnalyzed()
- val analyzedPlan = qe.analyzed
-
if (session.sessionState.catalog.isTempView(name)) {
- alterTemporaryView(session, analyzedPlan)
+ alterTemporaryView(session, query)
} else {
- alterPermanentView(session, analyzedPlan)
+ alterPermanentView(session, query)
}
Seq.empty[Row]
}
private def alterTemporaryView(session: SparkSession, analyzedPlan:
LogicalPlan): Unit = {
+ checkCyclicViewReference(analyzedPlan, Seq(name), name)
+
+ logDebug(s"Try to uncache ${name.quotedString} before altering.")
+ CommandUtils.uncacheTableOrView(session, name.quotedString)
Review comment:
Since the logic is very similar, I refactored this part to share code
with `CreateViewCommand`.
##########
File path:
sql/core/src/main/scala/org/apache/spark/sql/execution/command/views.scala
##########
@@ -192,38 +170,6 @@ case class CreateViewCommand(
Seq.empty[Row]
}
- /**
- * Checks if need to uncache the temp view being replaced.
- */
- private def needsToUncache(
Review comment:
This is moved to `ViewHelper` and renamed to `produceSameResult` with a
slight change.
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]