[GitHub] spark pull request #14314: [SPARK-16678] [SPARK-16677] [SQL] Fix two View-re...

2016-07-25 Thread asfgit
Github user asfgit closed the pull request at:

https://github.com/apache/spark/pull/14314


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



[GitHub] spark pull request #14314: [SPARK-16678] [SPARK-16677] [SQL] Fix two View-re...

2016-07-22 Thread gatorsmile
Github user gatorsmile commented on a diff in the pull request:

https://github.com/apache/spark/pull/14314#discussion_r71939503
  
--- Diff: 
sql/hive/src/test/scala/org/apache/spark/sql/hive/execution/SQLViewSuite.scala 
---
@@ -55,6 +54,76 @@ class SQLViewSuite extends QueryTest with SQLTestUtils 
with TestHiveSingleton {
 }
   }
 
+  test("error handling: existing a table with the duplicate name when 
creating/altering a view") {
+withTable("tab1") {
+  sql("CREATE TABLE tab1 (id int)")
+  var e = intercept[AnalysisException] {
+sql("CREATE OR REPLACE VIEW tab1 AS SELECT * FROM jt")
+  }.getMessage
+  assert(e.contains("The following is an existing table, not a view: 
`default`.`tab1`"))
+  e = intercept[AnalysisException] {
+sql("CREATE VIEW tab1 AS SELECT * FROM jt")
--- End diff --

```
hive> CREATE VIEW tab1 AS SELECT * FROM t1;
FAILED: Execution Error, return code 1 from 
org.apache.hadoop.hive.ql.exec.DDLTask. AlreadyExistsException(message:Table 
tab1 already exists)
```


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



[GitHub] spark pull request #14314: [SPARK-16678] [SPARK-16677] [SQL] Fix two View-re...

2016-07-22 Thread gatorsmile
Github user gatorsmile commented on a diff in the pull request:

https://github.com/apache/spark/pull/14314#discussion_r71939188
  
--- Diff: 
sql/hive/src/test/scala/org/apache/spark/sql/hive/execution/SQLViewSuite.scala 
---
@@ -55,6 +54,76 @@ class SQLViewSuite extends QueryTest with SQLTestUtils 
with TestHiveSingleton {
 }
   }
 
+  test("error handling: existing a table with the duplicate name when 
creating/altering a view") {
+withTable("tab1") {
+  sql("CREATE TABLE tab1 (id int)")
+  var e = intercept[AnalysisException] {
+sql("CREATE OR REPLACE VIEW tab1 AS SELECT * FROM jt")
+  }.getMessage
+  assert(e.contains("The following is an existing table, not a view: 
`default`.`tab1`"))
+  e = intercept[AnalysisException] {
+sql("CREATE VIEW tab1 AS SELECT * FROM jt")
+  }.getMessage
+  assert(e.contains("The following is an existing table, not a view: 
`default`.`tab1`"))
+  e = intercept[AnalysisException] {
+sql("ALTER VIEW tab1 AS SELECT * FROM jt")
+  }.getMessage
+  assert(e.contains("The following is an existing table, not a view: 
`default`.`tab1`"))
+}
+  }
+
+  test("existing a table with the duplicate name when CREATE VIEW IF NOT 
EXISTS") {
+withTable("tab1") {
+  sql("CREATE TABLE tab1 (id int)")
+  sql("CREATE VIEW IF NOT EXISTS tab1 AS SELECT * FROM jt")
+  checkAnswer(sql("select count(*) FROM tab1"), Row(0))
+}
+  }
+
+  test("error handling: insert/load/truncate table commands against a temp 
view") {
+val viewName = "testView"
+withView(viewName) {
--- End diff --

Will fix it, after your PR is merged. 
https://github.com/apache/spark/pull/14318

Thanks!


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



[GitHub] spark pull request #14314: [SPARK-16678] [SPARK-16677] [SQL] Fix two View-re...

2016-07-22 Thread gatorsmile
Github user gatorsmile commented on a diff in the pull request:

https://github.com/apache/spark/pull/14314#discussion_r71938799
  
--- Diff: 
sql/hive/src/test/scala/org/apache/spark/sql/hive/execution/SQLViewSuite.scala 
---
@@ -55,6 +54,76 @@ class SQLViewSuite extends QueryTest with SQLTestUtils 
with TestHiveSingleton {
 }
   }
 
+  test("error handling: existing a table with the duplicate name when 
creating/altering a view") {
+withTable("tab1") {
+  sql("CREATE TABLE tab1 (id int)")
+  var e = intercept[AnalysisException] {
+sql("CREATE OR REPLACE VIEW tab1 AS SELECT * FROM jt")
+  }.getMessage
+  assert(e.contains("The following is an existing table, not a view: 
`default`.`tab1`"))
+  e = intercept[AnalysisException] {
+sql("CREATE VIEW tab1 AS SELECT * FROM jt")
--- End diff --

For this case, it shows `table already existed`. However, when we found a 
view/table exists, the error message is wrong:
```
View $tableIdentifier already exists. If you want to update the view 
definition,
 please use ALTER VIEW AS or CREATE OR REPLACE VIEW AS
```
We are unable to alter a table (that is not a view) by these commands 
`ALTER VIEW AS or CREATE OR REPLACE VIEW AS`.

See the [source code] 
(https://github.com/gatorsmile/spark/blob/c64092c6aaec42663278343a27467c1c8c165b92/sql/core/src/main/scala/org/apache/spark/sql/execution/command/views.scala#L119-L124)



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



[GitHub] spark pull request #14314: [SPARK-16678] [SPARK-16677] [SQL] Fix two View-re...

2016-07-22 Thread cloud-fan
Github user cloud-fan commented on a diff in the pull request:

https://github.com/apache/spark/pull/14314#discussion_r71884535
  
--- Diff: 
sql/hive/src/test/scala/org/apache/spark/sql/hive/execution/SQLViewSuite.scala 
---
@@ -55,6 +54,76 @@ class SQLViewSuite extends QueryTest with SQLTestUtils 
with TestHiveSingleton {
 }
   }
 
+  test("error handling: existing a table with the duplicate name when 
creating/altering a view") {
+withTable("tab1") {
+  sql("CREATE TABLE tab1 (id int)")
+  var e = intercept[AnalysisException] {
+sql("CREATE OR REPLACE VIEW tab1 AS SELECT * FROM jt")
+  }.getMessage
+  assert(e.contains("The following is an existing table, not a view: 
`default`.`tab1`"))
+  e = intercept[AnalysisException] {
+sql("CREATE VIEW tab1 AS SELECT * FROM jt")
+  }.getMessage
+  assert(e.contains("The following is an existing table, not a view: 
`default`.`tab1`"))
+  e = intercept[AnalysisException] {
+sql("ALTER VIEW tab1 AS SELECT * FROM jt")
+  }.getMessage
+  assert(e.contains("The following is an existing table, not a view: 
`default`.`tab1`"))
+}
+  }
+
+  test("existing a table with the duplicate name when CREATE VIEW IF NOT 
EXISTS") {
+withTable("tab1") {
+  sql("CREATE TABLE tab1 (id int)")
+  sql("CREATE VIEW IF NOT EXISTS tab1 AS SELECT * FROM jt")
+  checkAnswer(sql("select count(*) FROM tab1"), Row(0))
+}
+  }
+
+  test("error handling: insert/load/truncate table commands against a temp 
view") {
+val viewName = "testView"
+withView(viewName) {
--- End diff --

`withTempTable`, as now we call temp view as temp table in test utils...


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



[GitHub] spark pull request #14314: [SPARK-16678] [SPARK-16677] [SQL] Fix two View-re...

2016-07-22 Thread cloud-fan
Github user cloud-fan commented on a diff in the pull request:

https://github.com/apache/spark/pull/14314#discussion_r71883793
  
--- Diff: 
sql/hive/src/test/scala/org/apache/spark/sql/hive/execution/SQLViewSuite.scala 
---
@@ -55,6 +54,76 @@ class SQLViewSuite extends QueryTest with SQLTestUtils 
with TestHiveSingleton {
 }
   }
 
+  test("error handling: existing a table with the duplicate name when 
creating/altering a view") {
+withTable("tab1") {
+  sql("CREATE TABLE tab1 (id int)")
+  var e = intercept[AnalysisException] {
+sql("CREATE OR REPLACE VIEW tab1 AS SELECT * FROM jt")
+  }.getMessage
+  assert(e.contains("The following is an existing table, not a view: 
`default`.`tab1`"))
+  e = intercept[AnalysisException] {
+sql("CREATE VIEW tab1 AS SELECT * FROM jt")
--- End diff --

what's hive's error message for this case? `view already existing` or `not 
a view`?


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



[GitHub] spark pull request #14314: [SPARK-16678] [SPARK-16677] [SQL] Fix two View-re...

2016-07-21 Thread gatorsmile
Github user gatorsmile commented on a diff in the pull request:

https://github.com/apache/spark/pull/14314#discussion_r71827097
  
--- Diff: 
sql/core/src/main/scala/org/apache/spark/sql/execution/command/views.scala ---
@@ -105,6 +105,12 @@ case class CreateViewCommand(
   val tableIdentifier = tableDesc.identifier.copy(database = 
Option(database))
 
   if (sessionState.catalog.tableExists(tableIdentifier)) {
+val tableMetadata = 
sessionState.catalog.getTableMetadata(tableIdentifier)
+if (tableMetadata.tableType != CatalogTableType.VIEW) {
+  throw new AnalysisException(
--- End diff --

Yeah, a good question. Just did a check using Hive. It is allowed by Hive. 
```
hive> CREATE VIEW IF NOT EXISTS tab1 AS SELECT * FROM t1;
OK
Time taken: 0.678 seconds
```
Let me move this a little bit down. 


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



[GitHub] spark pull request #14314: [SPARK-16678] [SPARK-16677] [SQL] Fix two View-re...

2016-07-21 Thread viirya
Github user viirya commented on a diff in the pull request:

https://github.com/apache/spark/pull/14314#discussion_r71825974
  
--- Diff: 
sql/core/src/main/scala/org/apache/spark/sql/execution/command/views.scala ---
@@ -105,6 +105,12 @@ case class CreateViewCommand(
   val tableIdentifier = tableDesc.identifier.copy(database = 
Option(database))
 
   if (sessionState.catalog.tableExists(tableIdentifier)) {
+val tableMetadata = 
sessionState.catalog.getTableMetadata(tableIdentifier)
+if (tableMetadata.tableType != CatalogTableType.VIEW) {
+  throw new AnalysisException(
--- End diff --

If allowing existing, do we still need to throw this excepion?


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