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

    https://github.com/apache/spark/pull/16168#discussion_r91112094
  
    --- Diff: 
sql/hive/src/test/scala/org/apache/spark/sql/hive/execution/SQLViewSuite.scala 
---
    @@ -448,19 +476,105 @@ class SQLViewSuite extends QueryTest with 
SQLTestUtils with TestHiveSingleton {
         }
       }
     
    +  test("Using view after change the origin view") {
    +    withView("v1", "v2") {
    +      sql("CREATE VIEW v1 AS SELECT id FROM jt")
    +      sql("CREATE VIEW v2 AS SELECT * FROM v1")
    +      withTable("jt2", "jt3") {
    +        // Don't change the view schema
    +        val df2 = (1 until 10).map(i => i + i).toDF("id")
    +        df2.write.format("json").saveAsTable("jt2")
    +        sql("ALTER VIEW v1 AS SELECT * FROM jt2")
    +        // the view v2 should have the same output with the view v1
    +        checkAnswer(sql("SELECT * FROM v2"), sql("SELECT * FROM v1"))
    +        // the view v2 should have the same output with the table jt2
    +        checkAnswer(sql("SELECT * FROM v2"), sql("SELECT * FROM jt2"))
    +
    +        // Change the view schema
    +        val df3 = (1 until 10).map(i => i -> i).toDF("i", "j")
    +        df3.write.format("json").saveAsTable("jt3")
    +        sql("ALTER VIEW v1 AS SELECT * FROM jt3")
    +        val e = intercept[AnalysisException] {
    +          sql("SELECT * FROM v2")
    +        }
    +        assert(e.message.contains(
    +          "The underlying schema doesn't match the original schema, 
expected " +
    +            "STRUCT<`id`: INT> but got STRUCT<`i`: INT, `j`: INT>"))
    +      }
    +    }
    +  }
    +
    +  test("Using view after drop the origin view") {
    +    withView("v1", "v2") {
    +      sql("CREATE VIEW v1 AS SELECT id FROM jt")
    +      sql("CREATE VIEW v2 AS SELECT * FROM v1")
    +      // Drop the referenced view
    +      sql("DROP VIEW v1")
    +      val e = intercept[RuntimeException] {
    +        sql("SELECT * FROM v2")
    +      }
    +      assert(e.getMessage.contains(
    +        "Failed to analyze the canonicalized SQL"))
    +    }
    +  }
    +
    +  test("Using view after change the origin table") {
    +    withTable("tab1") {
    +      val df = (1 until 10).map(i => i).toDF("i")
    +      df.write.format("json").saveAsTable("tab1")
    +      withView("v1", "v2") {
    +        sql("CREATE VIEW v1 AS SELECT * FROM tab1")
    +        sql("CREATE VIEW v2 AS SELECT * FROM v1")
    +        // Don't change the table schema
    +        val df2 = (1 until 10).map(i => i * i).toDF("i")
    +        df2.write.format("json").mode("overwrite").saveAsTable("tab1")
    +        // the view v2 should have the same output with the view v1
    +        checkAnswer(sql("SELECT * FROM v2"), sql("SELECT * FROM v1"))
    +        // the view v2 should have the same output with the table testTable
    +        checkAnswer(sql("SELECT * FROM v2"), sql("SELECT * FROM tab1"))
    +
    +        // Change the table schema
    +        val df3 = (1 until 10).map(i => i -> i).toDF("a", "b")
    +        df3.write.format("json").mode("overwrite").saveAsTable("tab1")
    +        val e = intercept[RuntimeException] {
    +          sql("SELECT * FROM v2")
    +        }
    +        assert(e.getMessage.contains(
    +          "Failed to analyze the canonicalized SQL"))
    +      }
    +    }
    +  }
    +
    +  test("Using view after drop the origin table") {
    +    withTable("tab1") {
    +      val df = (1 until 10).map(i => i).toDF("i")
    +      df.write.format("json").saveAsTable("tab1")
    +      withView("v1") {
    +        sql("CREATE VIEW v1 AS SELECT * FROM tab1")
    +        // Drop the referenced table
    +        sql("DROP TABLE tab1")
    +        val e = intercept[RuntimeException] {
    +          sql("SELECT * FROM v1")
    +        }
    +        assert(e.getMessage.contains(
    +          "Failed to analyze the canonicalized SQL"))
    +      }
    +    }
    +  }
    +
    --- End diff --
    
    If you add a new test case to test the multiple-level expansion as I 
suggested before, this test case is just a duplicate. It may be removed.


---
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 infrastruct...@apache.org or file a JIRA ticket
with INFRA.
---

---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscr...@spark.apache.org
For additional commands, e-mail: reviews-h...@spark.apache.org

Reply via email to