Github user cloud-fan commented on a diff in the pull request:
https://github.com/apache/spark/pull/8990#discussion_r41425875
--- 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 --
we will parse it to table identifier, so having the database part is OK.
---
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]