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

    https://github.com/apache/spark/pull/12872#discussion_r62026708
  
    --- Diff: 
sql/hive/src/test/scala/org/apache/spark/sql/hive/execution/SQLViewSuite.scala 
---
    @@ -69,18 +108,71 @@ class SQLViewSuite extends QueryTest with SQLTestUtils 
with TestHiveSingleton {
         }
       }
     
    +  test("correctly parse CREATE TEMPORARY VIEW statement") {
    +    withView("testView") {
    +      sql(
    +        """CREATE TEMPORARY VIEW
    +        |testView (c1 COMMENT 'blabla', c2 COMMENT 'blabla')
    +        |TBLPROPERTIES ('a' = 'b')
    +        |AS SELECT * FROM jt""".stripMargin)
    +      checkAnswer(sql("SELECT c1, c2 FROM testView ORDER BY c1"), (1 to 
9).map(i => Row(i, i)))
    +    }
    +  }
    +
    +  test("should NOT allow CREATE TEMPORARY VIEW when TEMPORARY VIEW with 
same name exists") {
    +    withView("testView") {
    +      sql("CREATE TEMPORARY VIEW testView AS SELECT id FROM jt")
    +
    +      val e = intercept[AnalysisException] {
    +        sql("CREATE TEMPORARY VIEW testView AS SELECT id FROM 
jt").collect()
    +      }
    +
    +      assert(e.message.contains("Temporary table") && 
e.message.contains("already exists"))
    +    }
    +  }
    +
    +  test("should allow CREATE TEMPORARY VIEW when a permanent VIEW with same 
name exists") {
    +    withView("testView", "default.testView") {
    +      sql("CREATE VIEW testView AS SELECT id FROM jt")
    +      sql("CREATE TEMPORARY VIEW testView AS SELECT id FROM jt").collect()
    +    }
    +  }
    +
    +  test("should allow CREATE permanent VIEW when a TEMPORARY VIEW with same 
name exists") {
    +    withView("testView", "default.testView") {
    +      sql("CREATE TEMPORARY VIEW testView AS SELECT id FROM jt")
    +      sql("CREATE VIEW testView AS SELECT id FROM jt").collect()
    +    }
    +  }
    +
       test("correctly handle CREATE VIEW IF NOT EXISTS") {
         withSQLConf(SQLConf.NATIVE_VIEW.key -> "true") {
           withTable("jt2") {
    -        sql("CREATE VIEW testView AS SELECT id FROM jt")
    +        withView("testView") {
    +          sql("CREATE VIEW testView AS SELECT id FROM jt")
     
    -        val df = (1 until 10).map(i => i -> i).toDF("i", "j")
    -        df.write.format("json").saveAsTable("jt2")
    -        sql("CREATE VIEW IF NOT EXISTS testView AS SELECT * FROM jt2")
    +          val df = (1 until 10).map(i => i -> i).toDF("i", "j")
    +          df.write.format("json").saveAsTable("jt2")
    +          sql("CREATE VIEW IF NOT EXISTS testView AS SELECT * FROM jt2")
    +
    +          // make sure our view doesn't change.
    +          checkAnswer(sql("SELECT * FROM testView ORDER BY id"), (1 to 
9).map(i => Row(i)))
    +        }
    +      }
    +    }
    +  }
     
    -        // make sure our view doesn't change.
    +  test(s"correctly handle CREATE OR REPLACE TEMPORARY VIEW") {
    +    withTable("jt2") {
    +      withView("testView") {
    +        sql("CREATE OR REPLACE TEMPORARY VIEW testView AS SELECT id FROM 
jt")
             checkAnswer(sql("SELECT * FROM testView ORDER BY id"), (1 to 
9).map(i => Row(i)))
    -        sql("DROP VIEW testView")
    +
    +        val df = (1 until 10).map(i => i -> i).toDF("i", "j")
    +        df.write.format("json").saveAsTable("jt2")
    --- End diff --
    
    The sorted persistent table is used by the checking logic below. 
    ```
    checkAnswer(sql("SELECT * FROM testView ORDER BY i"), (1 to 9).map(i => 
Row(i, i)))
    ```


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