diff options
author | gatorsmile <gatorsmile@gmail.com> | 2016-07-26 09:32:29 +0800 |
---|---|---|
committer | Wenchen Fan <wenchen@databricks.com> | 2016-07-26 09:32:29 +0800 |
commit | 3fc456694151e766c551b4bc58ed7c9457777666 (patch) | |
tree | 38eeb9d7ba104f777544c4a7f9a0443e6095c385 /sql/catalyst/src/main/scala | |
parent | e164a04b2ba3503e5c14cd1cd4beb40e0b79925a (diff) | |
download | spark-3fc456694151e766c551b4bc58ed7c9457777666.tar.gz spark-3fc456694151e766c551b4bc58ed7c9457777666.tar.bz2 spark-3fc456694151e766c551b4bc58ed7c9457777666.zip |
[SPARK-16678][SPARK-16677][SQL] Fix two View-related bugs
## What changes were proposed in this pull request?
**Issue 1: Disallow Creating/Altering a View when the same-name Table Exists (without IF NOT EXISTS)**
When we create OR alter a view, we check whether the view already exists. In the current implementation, if a table with the same name exists, we treat it as a view. However, this is not the right behavior. We should follow what Hive does. For example,
```
hive> CREATE TABLE tab1 (id int);
OK
Time taken: 0.196 seconds
hive> CREATE OR REPLACE VIEW tab1 AS SELECT * FROM t1;
FAILED: SemanticException [Error 10218]: Existing table is not a view
The following is an existing table, not a view: default.tab1
hive> ALTER VIEW tab1 AS SELECT * FROM t1;
FAILED: SemanticException [Error 10218]: Existing table is not a view
The following is an existing table, not a view: default.tab1
hive> CREATE VIEW IF NOT EXISTS tab1 AS SELECT * FROM t1;
OK
Time taken: 0.678 seconds
```
**Issue 2: Strange Error when Issuing Load Table Against A View**
Users should not be allowed to issue LOAD DATA against a view. Currently, when users doing it, we got a very strange runtime error. For example,
```SQL
LOAD DATA LOCAL INPATH "$testData" INTO TABLE $viewName
```
```
java.lang.reflect.InvocationTargetException was thrown.
java.lang.reflect.InvocationTargetException
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:606)
at org.apache.spark.sql.hive.client.Shim_v0_14.loadTable(HiveShim.scala:680)
```
## How was this patch tested?
Added test cases
Author: gatorsmile <gatorsmile@gmail.com>
Closes #14314 from gatorsmile/tableDDLAgainstView.
Diffstat (limited to 'sql/catalyst/src/main/scala')
-rw-r--r-- | sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/catalog/SessionCatalog.scala | 6 |
1 files changed, 3 insertions, 3 deletions
diff --git a/sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/catalog/SessionCatalog.scala b/sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/catalog/SessionCatalog.scala index 134fc4e698..1856dc4d64 100644 --- a/sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/catalog/SessionCatalog.scala +++ b/sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/catalog/SessionCatalog.scala @@ -443,12 +443,12 @@ class SessionCatalog( } /** - * Return whether a table with the specified name exists. + * Return whether a table/view with the specified name exists. * - * Note: If a database is explicitly specified, then this will return whether the table + * Note: If a database is explicitly specified, then this will return whether the table/view * exists in that particular database instead. In that case, even if there is a temporary * table with the same name, we will return false if the specified database does not - * contain the table. + * contain the table/view. */ def tableExists(name: TableIdentifier): Boolean = synchronized { val db = formatDatabaseName(name.database.getOrElse(currentDb)) |