Github user hvanhovell commented on a diff in the pull request:

    https://github.com/apache/spark/pull/16168#discussion_r91051675
  
    --- Diff: 
sql/core/src/main/scala/org/apache/spark/sql/execution/command/views.scala ---
    @@ -275,20 +297,26 @@ case class AlterViewAsCommand(
           throw new AnalysisException(s"${viewMeta.identifier} is not a view.")
         }
     
    -    val viewSQL: String = new SQLBuilder(analyzedPlan).toSQL
    -    // Validate the view SQL - make sure we can parse it and analyze it.
    -    // If we cannot analyze the generated query, there is probably a bug 
in SQL generation.
    -    try {
    -      session.sql(viewSQL).queryExecution.assertAnalyzed()
    +    val currentDatabase = session.sessionState.catalog.getCurrentDatabase
    +
    +    // Validate the view SQL - make sure we can resolve it with 
currentDatabase.
    +    val originalSchema = try {
    +      val unresolvedPlan = 
session.sessionState.sqlParser.parsePlan(originalText)
    +      val resolvedPlan = 
session.sessionState.analyzer.execute(unresolvedPlan)
    +      session.sessionState.analyzer.checkAnalysis(resolvedPlan)
    +
    +      resolvedPlan.schema
         } catch {
           case NonFatal(e) =>
    -        throw new RuntimeException(s"Failed to analyze the canonicalized 
SQL: $viewSQL", e)
    +        throw new RuntimeException(s"Failed to analyze the canonicalized 
SQL: $originalText", e)
    --- End diff --
    
    Same a before


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at [email protected] or file a JIRA ticket
with INFRA.
---

---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to