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

    https://github.com/apache/spark/pull/8990#discussion_r41427063
  
    --- Diff: 
sql/hive/src/test/scala/org/apache/spark/sql/hive/execution/SQLQuerySuite.scala 
---
    @@ -1248,4 +1248,47 @@ class SQLQuerySuite extends QueryTest with 
SQLTestUtils with TestHiveSingleton {
             """.stripMargin), Row("b", 6.0) :: Row("a", 7.0) :: Nil)
         }
       }
    +
    +  test("create hive view for json table") {
    +    // json table is not hive-compatible, make sure the new flag fix it.
    +    withSQLConf(SQLConf.CANONICALIZE_VIEW.key -> "true") {
    +      withTable("jt") {
    +        sqlContext.range(1, 10).write.format("json").saveAsTable("jt")
    +        sql("CREATE 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")
    +      }
    +    }
    +  }
    +
    +  test("create hive view for partitioned parquet table") {
    +    // partitioned parquet table is not hive-compatible, make sure the new 
flag fix it.
    +    withSQLConf(SQLConf.CANONICALIZE_VIEW.key -> "true") {
    +      withTable("parTable") {
    +        val df = Seq(1 -> "a").toDF("i", "j")
    +        df.write.format("parquet").partitionBy("i").saveAsTable("parTable")
    +        sql("CREATE VIEW testView AS SELECT i, j FROM parTable")
    +        checkAnswer(sql("SELECT * FROM testView"), Row(1, "a"))
    +        sql("DROP VIEW testView")
    +      }
    +    }
    +  }
    +
    +  test("create hive view for joined tables") {
    +    // make sure the new flag can handle some complex cases like join and 
schema change.
    +    withSQLConf(SQLConf.CANONICALIZE_VIEW.key -> "true") {
    +      withTable("jt1", "jt2") {
    +        sqlContext.range(1, 
10).toDF("id1").write.format("json").saveAsTable("jt1")
    +        sqlContext.range(1, 
10).toDF("id2").write.format("json").saveAsTable("jt2")
    +        sql("CREATE VIEW testView AS SELECT * FROM jt1 JOIN jt2 ON id1 == 
id2")
    +        checkAnswer(sql("SELECT * FROM testView ORDER BY id1"), (1 to 
9).map(i => Row(i, i)))
    +
    +        val df = (1 until 10).map(i => i -> i).toDF("id1", "newCol")
    +        df.write.format("json").mode(SaveMode.Overwrite).saveAsTable("jt1")
    +        checkAnswer(sql("SELECT * FROM testView ORDER BY id1"), (1 to 
9).map(i => Row(i, i)))
    +
    +        sql("DROP VIEW testView")
    +      }
    +    }
    +  }
    --- End diff --
    
    still good to test :)


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