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

    https://github.com/apache/spark/pull/14746#discussion_r76177293
  
    --- Diff: 
sql/hive/src/test/scala/org/apache/spark/sql/hive/execution/SQLViewSuite.scala 
---
    @@ -204,10 +206,67 @@ class SQLViewSuite extends QueryTest with 
SQLTestUtils with TestHiveSingleton {
         }
       }
     
    -  test("should allow CREATE permanent VIEW when a TEMPORARY VIEW with same 
name exists") {
    +  test("ALTER VIEW: alter a temporary view when a permanent VIEW with same 
name exists") {
    +    verifyAlterViewWithIdenticalName(isTempAlteredView = true)
    +  }
    +
    +  test("ALTER VIEW: alter a persistent view when a temp VIEW with same 
name exists") {
    +    verifyAlterViewWithIdenticalName(isTempAlteredView = false)
    +  }
    +
    +  private def verifyAlterViewWithIdenticalName (isTempAlteredView: 
Boolean) = {
    +    withView("testView", "default.testView") {
    +      val catalog = spark.sessionState.catalog
    +      val oldViewQuery = "SELECT id FROM jt"
    +      val newViewQuery = "SELECT  id, id1 FROM jt"
    +      sql(s"CREATE VIEW default.testView AS $oldViewQuery")
    +      sql(s"CREATE TEMPORARY VIEW testView AS $oldViewQuery")
    +      if (isTempAlteredView) {
    +        // When the database is not specified, we will first try to alter 
the temporary view
    +        sql(s"ALTER VIEW testView AS $newViewQuery")
    +      } else {
    +        // When the database is specified, we will try to alter the 
permanent view, no matter
    +        // whether the temporary view with the same name exists or not.
    +        sql(s"ALTER VIEW default.testView AS $newViewQuery")
    +      }
    +
    +      val persistentView = catalog.getTableMetadata(
    +        TableIdentifier(table = "testView", database = Some("default")))
    +      assert(persistentView.tableType == CatalogTableType.VIEW)
    +      val tempView = catalog.getTableMetadata(TableIdentifier("testView"))
    +      assert(tempView.tableType == CatalogTableType.VIEW)
    +      assert(tempView.viewOriginalText.isEmpty)
    +
    +      if (isTempAlteredView) {
    +        // View Text of the persistent view default.testView is changed
    --- End diff --
    
    : )


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