Github user cloud-fan commented on a diff in the pull request:

    https://github.com/apache/spark/pull/12324#discussion_r59680300
  
    --- Diff: 
sql/hive/src/test/scala/org/apache/spark/sql/hive/execution/HiveDDLSuite.scala 
---
    @@ -131,6 +131,124 @@ class HiveDDLSuite extends QueryTest with 
SQLTestUtils with TestHiveSingleton {
         }
       }
     
    +  test("alter views - rename") {
    +    val tabName = "tab1"
    +    withTable(tabName) {
    +      sqlContext.range(10).write.saveAsTable(tabName)
    +      val oldViewName = "view1"
    +      val newViewName = "view2"
    +      withView(oldViewName, newViewName) {
    +        val catalog = hiveContext.sessionState.catalog
    +        sql(s"CREATE VIEW $oldViewName AS SELECT * FROM $tabName")
    +
    +        assert(catalog.tableExists(TableIdentifier(oldViewName)))
    +        assert(!catalog.tableExists(TableIdentifier(newViewName)))
    +        sql(s"ALTER VIEW $oldViewName RENAME TO $newViewName")
    +        assert(!catalog.tableExists(TableIdentifier(oldViewName)))
    +        assert(catalog.tableExists(TableIdentifier(newViewName)))
    +
    +        sql(s"DROP VIEW $newViewName")
    +      }
    +    }
    +  }
    +
    +  test("alter views - set/unset tblproperties") {
    +    val tabName = "tab1"
    +    withTable(tabName) {
    +      sqlContext.range(10).write.saveAsTable(tabName)
    +      val viewName = "view1"
    +      withView(viewName) {
    +        val catalog = hiveContext.sessionState.catalog
    +        sql(s"CREATE VIEW $viewName AS SELECT * FROM $tabName")
    +
    +        assert(catalog.getTableMetadata(TableIdentifier(viewName))
    +          .properties.filter(_._1 != "transient_lastDdlTime") == Map())
    +        sql(s"ALTER VIEW $viewName SET TBLPROPERTIES ('p' = 'an')")
    +        assert(catalog.getTableMetadata(TableIdentifier(viewName))
    +          .properties.filter(_._1 != "transient_lastDdlTime") == Map("p" 
-> "an"))
    +
    +        // no exception or message will be issued if we set it again
    +        sql(s"ALTER VIEW $viewName SET TBLPROPERTIES ('p' = 'an')")
    +        assert(catalog.getTableMetadata(TableIdentifier(viewName))
    +          .properties.filter(_._1 != "transient_lastDdlTime") == Map("p" 
-> "an"))
    +
    +        // the value will be updated if we set the same key to a different 
value
    +        sql(s"ALTER VIEW $viewName SET TBLPROPERTIES ('p' = 'b')")
    +        assert(catalog.getTableMetadata(TableIdentifier(viewName))
    +          .properties.filter(_._1 != "transient_lastDdlTime") == Map("p" 
-> "b"))
    +
    +        sql(s"ALTER VIEW $viewName UNSET TBLPROPERTIES ('p')")
    +        assert(catalog.getTableMetadata(TableIdentifier(viewName))
    +          .properties.filter(_._1 != "transient_lastDdlTime") == Map())
    +
    +        val message = intercept[AnalysisException] {
    +          sql(s"ALTER VIEW $viewName UNSET TBLPROPERTIES ('p')")
    +        }.getMessage
    +        assert(message.contains(
    +          "attempted to unset non-existent property 'p' in table 
'`view1`'"))
    +
    +        sql(s"DROP VIEW $viewName")
    --- End diff --
    
    here too


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