Skip to content

Conversation

@gatorsmile
Copy link
Member

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:

 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.

@SparkQA
Copy link

SparkQA commented Sep 8, 2016

Test build #65058 has finished for PR 15004 at commit ea630f8.

  • This patch passes all tests.
  • This patch merges cleanly.
  • This patch adds no public classes.

@gatorsmile
Copy link
Member Author

cc @cloud-fan @yhuai


checkMisuseForAlterTableOrView(
s"$oldViewName ADD IF NOT EXISTS PARTITION (a='4', b='8')", isAlterView = false)

Copy link
Member Author

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

Copy link
Member Author

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(
Copy link
Contributor

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.

@gatorsmile
Copy link
Member Author

gatorsmile commented Sep 9, 2016

Accept all the comments. Will address comments now. Thanks! : )

@SparkQA
Copy link

SparkQA commented Sep 9, 2016

Test build #65137 has finished for PR 15004 at commit 5d0cffe.

  • This patch passes all tests.
  • This patch merges cleanly.
  • This patch adds no public classes.

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')")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

unnecessary change?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor

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

@SparkQA
Copy link

SparkQA commented Sep 9, 2016

Test build #65151 has finished for PR 15004 at commit 8b2ed94.

  • This patch passes all tests.
  • This patch merges cleanly.
  • This patch adds no public classes.

@cloud-fan
Copy link
Contributor

retest this please

@cloud-fan
Copy link
Contributor

LGTM

@SparkQA
Copy link

SparkQA commented Sep 14, 2016

Test build #65375 has finished for PR 15004 at commit 8b2ed94.

  • This patch passes all tests.
  • This patch merges cleanly.
  • This patch adds no public classes.


val e = intercept[AnalysisException] {
sql("ALTER TABLE tab1 RENAME TO tab2")
sql("ALTER VIEW tab1 RENAME TO tab2")
Copy link
Contributor

@cloud-fan cloud-fan Sep 14, 2016

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?

Copy link
Member Author

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.

Copy link
Member Author

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.

Copy link
Member Author

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.
Copy link
Contributor

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

Copy link
Contributor

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.

Copy link
Member Author

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!

Copy link
Member Author

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!

@SparkQA
Copy link

SparkQA commented Sep 15, 2016

Test build #65417 has finished for PR 15004 at commit 159f101.

  • This patch passes all tests.
  • This patch merges cleanly.
  • This patch adds no public classes.

@SparkQA
Copy link

SparkQA commented Sep 15, 2016

Test build #65419 has finished for PR 15004 at commit 91c3a28.

  • This patch passes all tests.
  • This patch merges cleanly.
  • This patch adds no public classes.

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")
Copy link
Contributor

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.

Copy link
Member Author

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!

@cloud-fan
Copy link
Contributor

thanks, merging to master! you can address my last comment in your other PRs

@asfgit asfgit closed this in 6a6adb1 Sep 15, 2016
@gatorsmile
Copy link
Member Author

Thank you! : )

wgtmac pushed a commit to wgtmac/spark that referenced this pull request Sep 19, 2016
### 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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants