-
Notifications
You must be signed in to change notification settings - Fork 29k
[SPARK-17440] [SPARK-17441] Fixed Multiple Bugs in ALTER TABLE #15004
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
|
Test build #65058 has finished for PR 15004 at commit
|
|
cc @cloud-fan @yhuai |
|
|
||
| checkMisuseForAlterTableOrView( | ||
| s"$oldViewName ADD IF NOT EXISTS PARTITION (a='4', b='8')", isAlterView = false) | ||
|
|
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.
We also need to test isAlterView = true for ADD PARTITION and DROP PARTITION. Let me add them now...
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.
uh, both are not supported. nvm. I think we already cover all the cases. Code is ready to review. Thanks!
| verifyAlterTableType(_, tableIdentifier, isView)) | ||
| } | ||
|
|
||
| def verifyAlterTableType( |
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.
I think we only need this one, and we can remove the old one.
|
Accept all the comments. Will address comments now. Thanks! : ) |
|
Test build #65137 has finished for PR 15004 at commit
|
| createPartitionedTable(tableIdent, isDatasourceTable = false) | ||
| sql("ALTER TABLE dbx.tab1 PARTITION (a='1', b='q') RENAME TO PARTITION (a='100', b='p')") | ||
| sql("ALTER TABLE dbx.tab1 PARTITION (a='2', b='c') RENAME TO PARTITION (a='200', b='c')") | ||
| sql("ALTER TABLE dbx.tab1 PARTITION (a='2', b='c') RENAME TO PARTITION (a='20', b='c')") |
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.
unnecessary change?
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.
https://github.com/gatorsmile/spark/blob/5d0cffe6b59dc36d63f7d1e055903b53ce2fec42/sql/core/src/test/scala/org/apache/spark/sql/execution/command/DDLSuite.scala#L878 will be longer than 100 characters... That is why I changed it to avoid adding another line.
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.
ok then it's fine...
|
Test build #65151 has finished for PR 15004 at commit
|
|
retest this please |
|
LGTM |
|
Test build #65375 has finished for PR 15004 at commit
|
|
|
||
| val e = intercept[AnalysisException] { | ||
| sql("ALTER TABLE tab1 RENAME TO tab2") | ||
| sql("ALTER VIEW tab1 RENAME TO tab2") |
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.
Sorry I missed this one. So we can't use ALTER TABLE to alter temp view now?
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.
en... You are right. Let me resolve this soon.
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.
Will also add a few test cases for ensuring ALTER TABLE commands can alter temporary views.
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.
The problem is fixed. : )
| * If the command ALTER VIEW is to alter a table or ALTER TABLE is to alter a view, | ||
| * issue an exception [[AnalysisException]]. | ||
| * issue an exception [[AnalysisException]]. Temporary views can be altered by both | ||
| * ALTER VIEW and ALTER TABLE commands. |
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.
we may also explain the reason, i.e. temporary views can be created by CREATE TEMPORARY TABLE
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.
and we can remove this trick if we decide to not allow temporary views to be created by CREATE TEMPORARY TABLE.
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. Let me do it now. Thanks!
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.
The comment is added. Thanks!
|
Test build #65417 has finished for PR 15004 at commit
|
|
Test build #65419 has finished for PR 15004 at commit
|
| val table = catalog.getTableMetadata(tableName) | ||
| if (DDLUtils.isDatasourceTable(table)) { | ||
| throw new AnalysisException( | ||
| "ALTER TABLE RENAME PARTITION is not allowed for tables defined using the datasource API") |
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.
we can just say data source table, to be consistent with other places.
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.
Sure, will do it. Thanks!
|
thanks, merging to master! you can address my last comment in your other PRs |
|
Thank you! : ) |
### What changes were proposed in this pull request?
For the following `ALTER TABLE` DDL, we should issue an exception when the target table is a `VIEW`:
```SQL
ALTER TABLE viewName SET LOCATION '/path/to/your/lovely/heart'
ALTER TABLE viewName SET SERDE 'whatever'
ALTER TABLE viewName SET SERDEPROPERTIES ('x' = 'y')
ALTER TABLE viewName PARTITION (a=1, b=2) SET SERDEPROPERTIES ('x' = 'y')
ALTER TABLE viewName ADD IF NOT EXISTS PARTITION (a='4', b='8')
ALTER TABLE viewName DROP IF EXISTS PARTITION (a='2')
ALTER TABLE viewName RECOVER PARTITIONS
ALTER TABLE viewName PARTITION (a='1', b='q') RENAME TO PARTITION (a='100', b='p')
```
In addition, `ALTER TABLE RENAME PARTITION` is unable to handle data source tables, just like the other `ALTER PARTITION` commands. We should issue an exception instead.
### How was this patch tested?
Added a few test cases.
Author: gatorsmile <[email protected]>
Closes apache#15004 from gatorsmile/altertable.
What changes were proposed in this pull request?
For the following
ALTER TABLEDDL, we should issue an exception when the target table is aVIEW:In addition,
ALTER TABLE RENAME PARTITIONis unable to handle data source tables, just like the otherALTER PARTITIONcommands. We should issue an exception instead.How was this patch tested?
Added a few test cases.