-
Notifications
You must be signed in to change notification settings - Fork 28.9k
[SPARK-16678] [SPARK-16677] [SQL] Fix two View-related bugs #14314
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
| if (sessionState.catalog.tableExists(tableIdentifier)) { | ||
| val tableMetadata = sessionState.catalog.getTableMetadata(tableIdentifier) | ||
| if (tableMetadata.tableType != CatalogTableType.VIEW) { | ||
| throw new AnalysisException( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If allowing existing, do we still need to throw this exception?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
|
Test build #62712 has finished for PR 14314 at commit
|
|
Test build #62716 has finished for PR 14314 at commit
|
|
Test build #62717 has finished for PR 14314 at commit
|
|
cc @cloud-fan |
| }.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") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
what's hive's error message for this case? view already existing or not a view?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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
The message is better than table already exists, I think.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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)
|
Test build #62800 has finished for PR 14314 at commit
|
|
LGTM, waiting for #14297 |
|
Test build #62825 has finished for PR 14314 at commit
|
|
thanks, merging to master! |
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,
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,
LOAD DATA LOCAL INPATH "$testData" INTO TABLE $viewNameHow was this patch tested?
Added test cases