Skip to content
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
83 commits
Select commit Hold shift + click to select a range
9a6658c
[SPARK-17477]: SparkSQL cannot handle schema evolution from Int -> Lo…
wgtmac Sep 9, 2016
d978d4b
[SPARK-17354] [SQL] Partitioning by dates/timestamps should work with…
HyukjinKwon Sep 9, 2016
965d966
[SPARK-15453][SQL] FileSourceScanExec to extract `outputOrdering` inf…
tejasapatil Sep 10, 2016
a30257b
[SPARK-11496][GRAPHX] Parallel implementation of personalized pagerank
Sep 10, 2016
bca8f30
[SPARK-15509][FOLLOW-UP][ML][SPARKR] R MLlib algorithms should suppor…
yanboliang Sep 10, 2016
705fbdc
[SPARK-17396][CORE] Share the task support between UnionRDD instances.
rdblue Sep 10, 2016
9e6680e
[SPARK-16445][MLLIB][SPARKR] Fix @return description for sparkR mlp s…
keypointt Sep 10, 2016
71d6291
[SPARK-17389][ML][MLLIB] KMeans speedup with better choice of k-means…
srowen Sep 11, 2016
eb10a06
[SPARK-17439][SQL] Fixing compression issues with approximate quantil…
thunterdb Sep 11, 2016
8ce0d5e
[SPARK-17330][SPARK UT] Clean up spark-warehouse in UT
Sep 11, 2016
1d4165f
[SPARK-17336][PYSPARK] Fix appending multiple times to PYTHONPATH fro…
BryanCutler Sep 11, 2016
7d309ff
[SPARK-17389][FOLLOW-UP][ML] Change KMeans k-means|| default init ste…
yanboliang Sep 11, 2016
ed112bd
[SPARK-17415][SQL] Better error message for driver-side broadcast joi…
sameeragarwal Sep 11, 2016
7afab77
[SPARK-17486] Remove unused TaskMetricsUIData.updatedBlockStatuses field
JoshRosen Sep 12, 2016
d608f99
[SPARK-17171][WEB UI] DAG will list all partitions in the graph
cenyuhai Sep 12, 2016
10b1feb
[SPARK-17447] Performance improvement in Partitioner.defaultPartition…
codlife Sep 12, 2016
28f6379
[SPARK-16992][PYSPARK] use map comprehension in doc
gsemet Sep 12, 2016
7037d03
[SPARK CORE][MINOR] fix "default partitioner cannot partition array k…
WeichenXu123 Sep 12, 2016
cb6e59c
[SPARK-17503][CORE] Fix memory leak in Memory store when unable to ca…
clockfly Sep 12, 2016
1984289
[SPARK-17483] Refactoring in BlockManager status reporting and block …
JoshRosen Sep 12, 2016
1c60199
[SPARK-14818] Post-2.0 MiMa exclusion and build changes
JoshRosen Sep 12, 2016
671d8ec
[SPARK-17485] Prevent failed remote reads of cached blocks from faili…
JoshRosen Sep 12, 2016
77808e0
[SPARK-17474] [SQL] fix python udf in TakeOrderedAndProjectExec
Sep 12, 2016
67b0a5e
[SPARK-17515] CollectLimit.execute() should perform per-partition limits
JoshRosen Sep 13, 2016
2dda3bb
[SPARK-17142][SQL] Complex query triggers binding error in HashAggreg…
jiangxb1987 Sep 13, 2016
33fd9a7
[SPARK-17531] Don't initialize Hive Listeners for the Execution Client
brkyvz Sep 13, 2016
d020ea3
[SPARK-17530][SQL] Add Statistics into DESCRIBE FORMATTED
gatorsmile Sep 13, 2016
9b48546
[SPARK-17317][SPARKR] Add SparkR vignette
junyangq Sep 14, 2016
8cbdf79
[SPARK-17449][DOCUMENTATION] Relation between heartbeatInterval and…
jagadeesanas2 Sep 14, 2016
7cd75c0
[SPARK-17525][PYTHON] Remove SparkContext.clearFiles() from the PySpa…
sjakthol Sep 14, 2016
c37fda6
[CORE][DOC] remove redundant comment
wangmiao1981 Sep 14, 2016
84dced4
[SPARK-17480][SQL] Improve performance by removing or caching List.le…
seyfe Sep 14, 2016
25ca2de
[SPARK-17445][DOCS] Reference an ASF page as the main place to find t…
srowen Sep 14, 2016
2125957
[SPARK-17409][SQL] Do Not Optimize Query in CTAS More Than Once
gatorsmile Sep 14, 2016
f9f2c6b
[SPARK-17514] df.take(1) and df.limit(1).collect() should perform the…
JoshRosen Sep 14, 2016
08b9c75
[MINOR][SQL] Add missing functions for some options in SQLConf and us…
HyukjinKwon Sep 14, 2016
a1d246e
[SPARK-10747][SQL] Support NULLS FIRST|LAST clause in ORDER BY
xwu0226 Sep 14, 2016
a63556f
[SPARK-17511] Yarn Dynamic Allocation: Avoid marking released contain…
kishorvpatil Sep 14, 2016
e5814cc
[SPARK-17463][CORE] Make CollectionAccumulator and SetAccumulator's v…
zsxwing Sep 14, 2016
3b80d1f
[SPARK-17472] [PYSPARK] Better error message for serialization failur…
ericl Sep 14, 2016
795d83e
[SPARK-17465][SPARK CORE] Inappropriate memory management in `org.apa…
Sep 14, 2016
f1a0223
[SPARK-17440][SPARK-17441] Fixed Multiple Bugs in ALTER TABLE
gatorsmile Sep 15, 2016
de885a8
[SPARK-17507][ML][MLLIB] check weight vector size in ANN
WeichenXu123 Sep 15, 2016
5ee52aa
[SPARK-17524][TESTS] Use specified spark.buffer.pageSize
a-roberts Sep 15, 2016
037565f
[SPARK-17521] Error when I use sparkContext.makeRDD(Seq())
codlife Sep 15, 2016
6f0e760
[SPARK-17406][WEB UI] limit timeline executor events
cenyuhai Sep 15, 2016
74bf9a2
[SPARK-17536][SQL] Minor performance improvement to JDBC batch inserts
Sep 15, 2016
396a6ce
[SPARK-17406][BUILD][HOTFIX] MiMa excludes fix
srowen Sep 15, 2016
4b29340
[SPARK-17451][CORE] CoarseGrainedExecutorBackend should inform driver…
tejasapatil Sep 15, 2016
1430e3b
[SPARK-17379][BUILD] Upgrade netty-all to 4.0.41 final for bug fixes
a-roberts Sep 15, 2016
129e87b
[SPARK-17547] Ensure temp shuffle data file is cleaned up after error
JoshRosen Sep 15, 2016
be726e2
[SPARK-17114][SQL] Fix aggregates grouped by literals with empty input
hvanhovell Sep 15, 2016
17f7ce3
[SPARK-17429][SQL] use ImplicitCastInputTypes with function Length
cenyuhai Sep 15, 2016
609e6ce
[SPARK-17364][SQL] Antlr lexer wrongly treats full qualified identifi…
clockfly Sep 15, 2016
2dc869f
[SPARK-17484] Prevent invalid block locations from being reported aft…
JoshRosen Sep 15, 2016
2bb1a19
[SPARK-17458][SQL] Alias specified for aggregates in a pivot are not …
aray Sep 15, 2016
8098b29
[SPARK-17543] Missing log4j config file for tests in common/network-…
jagadeesanas2 Sep 16, 2016
fdb9154
[SPARK-17534][TESTS] Increase timeouts for DirectKafkaStreamSuite tests
a-roberts Sep 16, 2016
0ef4313
[SPARK-17426][SQL] Refactor `TreeNode.toJSON` to avoid OOM when conve…
clockfly Sep 16, 2016
ef7fa83
[SPARK-17558] Bump Hadoop 2.7 version from 2.7.2 to 2.7.3
rxin Sep 16, 2016
ccff86d
[SPARK-17561][DOCS] DataFrameWriter documentation formatting problems
srowen Sep 16, 2016
60c287f
[SPARK-17549][SQL] Only collect table size stat in driver for cached …
Sep 16, 2016
19f894e
Correct fetchsize property name in docs
darabos Sep 17, 2016
ae3b76b
[SPARK-17567][DOCS] Use valid url to Spark RDD paper
keypointt Sep 17, 2016
b7d1923
[SPARK-17548][MLLIB] Word2VecModel.findSynonyms no longer spuriously …
willb Sep 17, 2016
06684bb
[SPARK-17529][CORE] Implement BitSet.clearUntil and use it during mer…
Sep 17, 2016
19132d5
[SPARK-17575][DOCS] Remove extra table tags in configuration document
phalodi Sep 17, 2016
defe9aa
[SPARK-17480][SQL][FOLLOWUP] Fix more instances which calls List.leng…
HyukjinKwon Sep 17, 2016
21035a6
[SPARK-17491] Close serialization stream to fix wrong answer bug in p…
JoshRosen Sep 17, 2016
d6cbf8d
[SPARK-17518][SQL] Block Users to Specify the Internal Data Source Pr…
gatorsmile Sep 18, 2016
3357bc7
[SPARK-17541][SQL] fix some DDL bugs about table management when same…
cloud-fan Sep 18, 2016
7d24523
[SPARK-17506][SQL] Improve the check double values equality rule.
jiangxb1987 Sep 18, 2016
e460dcd
[SPARK-17546][DEPLOY] start-* scripts should use hostname -f
srowen Sep 18, 2016
032335e
[SPARK-17586][BUILD] Do not call static member via instance reference
HyukjinKwon Sep 18, 2016
5930e0b
[SPARK-16462][SPARK-16460][SPARK-15144][SQL] Make CSV cast null value…
lw-lin Sep 18, 2016
98dfd17
[SPARK-17571][SQL] AssertOnQuery.condition should always return Boole…
petermaxlee Sep 18, 2016
3b18214
[SPARK-17297][DOCS] Clarify window/slide duration as absolute time, n…
srowen Sep 19, 2016
2b7ebff
[SPARK-17473][SQL] fixing docker integration tests error due to diffe…
sureshthalamati Sep 19, 2016
e6a9a72
[SPARK-17438][WEBUI] Show Application.executorLimit in the applicatio…
zsxwing Sep 19, 2016
f6aeaf2
revert change
wgtmac Sep 19, 2016
9fc18a4
[SPARK-17477][SQL] SparkSQL cannot handle schema evolution from Int -…
wgtmac Sep 19, 2016
8efd4dd
[SPARK-16439] [SQL] bring back the separator in SQL UI
Sep 19, 2016
a1bdea0
[SPARK-17100] [SQL] fix Python udf in filter on top of outer join
Sep 19, 2016
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
[SPARK-17440][SPARK-17441] Fixed Multiple Bugs in ALTER TABLE
### 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 #15004 from gatorsmile/altertable.
  • Loading branch information
gatorsmile authored and wgtmac committed Sep 19, 2016
commit f1a022363b14dbd3f3a92ed9a53c2d7232000ed6
Original file line number Diff line number Diff line change
Expand Up @@ -230,8 +230,8 @@ case class AlterTableSetPropertiesCommand(

override def run(sparkSession: SparkSession): Seq[Row] = {
val catalog = sparkSession.sessionState.catalog
DDLUtils.verifyAlterTableType(catalog, tableName, isView)
val table = catalog.getTableMetadata(tableName)
DDLUtils.verifyAlterTableType(catalog, table, isView)
// This overrides old properties
val newTable = table.copy(properties = table.properties ++ properties)
catalog.alterTable(newTable)
Expand All @@ -258,8 +258,8 @@ case class AlterTableUnsetPropertiesCommand(

override def run(sparkSession: SparkSession): Seq[Row] = {
val catalog = sparkSession.sessionState.catalog
DDLUtils.verifyAlterTableType(catalog, tableName, isView)
val table = catalog.getTableMetadata(tableName)
DDLUtils.verifyAlterTableType(catalog, table, isView)
if (!ifExists) {
propKeys.foreach { k =>
if (!table.properties.contains(k)) {
Expand Down Expand Up @@ -299,6 +299,7 @@ case class AlterTableSerDePropertiesCommand(
override def run(sparkSession: SparkSession): Seq[Row] = {
val catalog = sparkSession.sessionState.catalog
val table = catalog.getTableMetadata(tableName)
DDLUtils.verifyAlterTableType(catalog, table, isView = false)
// For datasource tables, disallow setting serde or specifying partition
if (partSpec.isDefined && DDLUtils.isDatasourceTable(table)) {
throw new AnalysisException("Operation not allowed: ALTER TABLE SET " +
Expand Down Expand Up @@ -348,6 +349,7 @@ case class AlterTableAddPartitionCommand(
override def run(sparkSession: SparkSession): Seq[Row] = {
val catalog = sparkSession.sessionState.catalog
val table = catalog.getTableMetadata(tableName)
DDLUtils.verifyAlterTableType(catalog, table, isView = false)
if (DDLUtils.isDatasourceTable(table)) {
throw new AnalysisException(
"ALTER TABLE ADD PARTITION is not allowed for tables defined using the datasource API")
Expand Down Expand Up @@ -377,7 +379,14 @@ case class AlterTableRenamePartitionCommand(
extends RunnableCommand {

override def run(sparkSession: SparkSession): Seq[Row] = {
sparkSession.sessionState.catalog.renamePartitions(
val catalog = sparkSession.sessionState.catalog
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")
}
DDLUtils.verifyAlterTableType(catalog, table, isView = false)
catalog.renamePartitions(
tableName, Seq(oldPartition), Seq(newPartition))
Seq.empty[Row]
}
Expand Down Expand Up @@ -408,6 +417,7 @@ case class AlterTableDropPartitionCommand(
override def run(sparkSession: SparkSession): Seq[Row] = {
val catalog = sparkSession.sessionState.catalog
val table = catalog.getTableMetadata(tableName)
DDLUtils.verifyAlterTableType(catalog, table, isView = false)
if (DDLUtils.isDatasourceTable(table)) {
throw new AnalysisException(
"ALTER TABLE DROP PARTITIONS is not allowed for tables defined using the datasource API")
Expand Down Expand Up @@ -469,6 +479,7 @@ case class AlterTableRecoverPartitionsCommand(
s"Operation not allowed: $cmd on temporary tables: $tableName")
}
val table = catalog.getTableMetadata(tableName)
DDLUtils.verifyAlterTableType(catalog, table, isView = false)
if (DDLUtils.isDatasourceTable(table)) {
throw new AnalysisException(
s"Operation not allowed: $cmd on datasource tables: $tableName")
Expand Down Expand Up @@ -644,6 +655,7 @@ case class AlterTableSetLocationCommand(
override def run(sparkSession: SparkSession): Seq[Row] = {
val catalog = sparkSession.sessionState.catalog
val table = catalog.getTableMetadata(tableName)
DDLUtils.verifyAlterTableType(catalog, table, isView = false)
partitionSpec match {
case Some(spec) =>
// Partition spec is specified, so we set the location only for this partition
Expand Down Expand Up @@ -682,19 +694,26 @@ object DDLUtils {
/**
* If the command ALTER VIEW is to alter a table or ALTER TABLE is to alter a view,
* issue an exception [[AnalysisException]].
*
* Note: temporary views can be altered by both ALTER VIEW and ALTER TABLE commands,
* since temporary views can be also created by CREATE TEMPORARY TABLE. In the future,
* when we decided to drop the support, we should disallow users to alter temporary views
* by ALTER TABLE.
*/
def verifyAlterTableType(
catalog: SessionCatalog,
tableIdentifier: TableIdentifier,
tableMetadata: CatalogTable,
isView: Boolean): Unit = {
catalog.getTableMetadataOption(tableIdentifier).map(_.tableType match {
case CatalogTableType.VIEW if !isView =>
throw new AnalysisException(
"Cannot alter a view with ALTER TABLE. Please use ALTER VIEW instead")
case o if o != CatalogTableType.VIEW && isView =>
throw new AnalysisException(
s"Cannot alter a table with ALTER VIEW. Please use ALTER TABLE instead")
case _ =>
})
if (!catalog.isTemporaryTable(tableMetadata.identifier)) {
tableMetadata.tableType match {
case CatalogTableType.VIEW if !isView =>
throw new AnalysisException(
"Cannot alter a view with ALTER TABLE. Please use ALTER VIEW instead")
case o if o != CatalogTableType.VIEW && isView =>
throw new AnalysisException(
s"Cannot alter a table with ALTER VIEW. Please use ALTER TABLE instead")
case _ =>
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,8 @@ case class AlterTableRenameCommand(

override def run(sparkSession: SparkSession): Seq[Row] = {
val catalog = sparkSession.sessionState.catalog
DDLUtils.verifyAlterTableType(catalog, oldName, isView)
val table = catalog.getTableMetadata(oldName)
DDLUtils.verifyAlterTableType(catalog, table, isView)
// If this is a temp view, just rename the view.
// Otherwise, if this is a real table, we also need to uncache and invalidate the table.
val isTemporary = catalog.isTemporaryTable(oldName)
Expand All @@ -177,7 +178,6 @@ case class AlterTableRenameCommand(
}
}
// For datasource tables, we also need to update the "path" serde property
val table = catalog.getTableMetadata(oldName)
if (DDLUtils.isDatasourceTable(table) && table.tableType == CatalogTableType.MANAGED) {
val newPath = catalog.defaultTablePath(newTblName)
val newTable = table.withNewStorage(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -696,6 +696,18 @@ class DDLSuite extends QueryTest with SharedSQLContext with BeforeAndAfterEach {
assert(spark.table("teachers").collect().toSeq == df.collect().toSeq)
}

test("rename temporary table") {
withTempView("tab1", "tab2") {
spark.range(10).createOrReplaceTempView("tab1")
sql("ALTER TABLE tab1 RENAME TO tab2")
checkAnswer(spark.table("tab2"), spark.range(10).toDF())
intercept[NoSuchTableException] { spark.table("tab1") }
sql("ALTER VIEW tab2 RENAME TO tab1")
checkAnswer(spark.table("tab1"), spark.range(10).toDF())
intercept[NoSuchTableException] { spark.table("tab2") }
}
}

test("rename temporary table - destination table already exists") {
withTempView("tab1", "tab2") {
sql(
Expand Down Expand Up @@ -880,25 +892,16 @@ class DDLSuite extends QueryTest with SharedSQLContext with BeforeAndAfterEach {
test("alter table: rename partition") {
val catalog = spark.sessionState.catalog
val tableIdent = TableIdentifier("tab1", Some("dbx"))
val part1 = Map("a" -> "1", "b" -> "q")
val part2 = Map("a" -> "2", "b" -> "c")
val part3 = Map("a" -> "3", "b" -> "p")
createDatabase(catalog, "dbx")
createTable(catalog, tableIdent)
createTablePartition(catalog, part1, tableIdent)
createTablePartition(catalog, part2, tableIdent)
createTablePartition(catalog, part3, tableIdent)
assert(catalog.listPartitions(tableIdent).map(_.spec).toSet ==
Set(part1, part2, part3))
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')")
assert(catalog.listPartitions(tableIdent).map(_.spec).toSet ==
Set(Map("a" -> "100", "b" -> "p"), Map("a" -> "200", "b" -> "c"), part3))
Set(Map("a" -> "100", "b" -> "p"), Map("a" -> "20", "b" -> "c"), Map("a" -> "3", "b" -> "p")))
// rename without explicitly specifying database
catalog.setCurrentDatabase("dbx")
sql("ALTER TABLE tab1 PARTITION (a='100', b='p') RENAME TO PARTITION (a='10', b='p')")
assert(catalog.listPartitions(tableIdent).map(_.spec).toSet ==
Set(Map("a" -> "10", "b" -> "p"), Map("a" -> "200", "b" -> "c"), part3))
Set(Map("a" -> "10", "b" -> "p"), Map("a" -> "20", "b" -> "c"), Map("a" -> "3", "b" -> "p")))
// table to alter does not exist
intercept[NoSuchTableException] {
sql("ALTER TABLE does_not_exist PARTITION (c='3') RENAME TO PARTITION (c='333')")
Expand All @@ -909,6 +912,38 @@ class DDLSuite extends QueryTest with SharedSQLContext with BeforeAndAfterEach {
}
}

test("alter table: rename partition (datasource table)") {
createPartitionedTable(TableIdentifier("tab1", Some("dbx")), isDatasourceTable = true)
val e = intercept[AnalysisException] {
sql("ALTER TABLE dbx.tab1 PARTITION (a='1', b='q') RENAME TO PARTITION (a='100', b='p')")
}.getMessage
assert(e.contains(
"ALTER TABLE RENAME PARTITION is not allowed for tables defined using the datasource API"))
// table to alter does not exist
intercept[NoSuchTableException] {
sql("ALTER TABLE does_not_exist PARTITION (c='3') RENAME TO PARTITION (c='333')")
}
}

private def createPartitionedTable(
tableIdent: TableIdentifier,
isDatasourceTable: Boolean): Unit = {
val catalog = spark.sessionState.catalog
val part1 = Map("a" -> "1", "b" -> "q")
val part2 = Map("a" -> "2", "b" -> "c")
val part3 = Map("a" -> "3", "b" -> "p")
createDatabase(catalog, "dbx")
createTable(catalog, tableIdent)
createTablePartition(catalog, part1, tableIdent)
createTablePartition(catalog, part2, tableIdent)
createTablePartition(catalog, part3, tableIdent)
assert(catalog.listPartitions(tableIdent).map(_.spec).toSet ==
Set(part1, part2, part3))
if (isDatasourceTable) {
convertToDatasourceTable(catalog, tableIdent)
}
}

test("show tables") {
withTempView("show1a", "show2b") {
sql(
Expand Down Expand Up @@ -1255,7 +1290,7 @@ class DDLSuite extends QueryTest with SharedSQLContext with BeforeAndAfterEach {
}
// table to alter does not exist
intercept[AnalysisException] {
sql("ALTER TABLE does_not_exist SET SERDEPROPERTIES ('x' = 'y')")
sql("ALTER TABLE does_not_exist PARTITION (a=1, b=2) SET SERDEPROPERTIES ('x' = 'y')")
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -305,6 +305,16 @@ class HiveDDLSuite
}
}

private def assertErrorForAlterTableOnView(sqlText: String): Unit = {
val message = intercept[AnalysisException](sql(sqlText)).getMessage
assert(message.contains("Cannot alter a view with ALTER TABLE. Please use ALTER VIEW instead"))
}

private def assertErrorForAlterViewOnTable(sqlText: String): Unit = {
val message = intercept[AnalysisException](sql(sqlText)).getMessage
assert(message.contains("Cannot alter a table with ALTER VIEW. Please use ALTER TABLE instead"))
}

test("alter views and alter table - misuse") {
val tabName = "tab1"
withTable(tabName) {
Expand All @@ -317,45 +327,42 @@ class HiveDDLSuite

assert(catalog.tableExists(TableIdentifier(tabName)))
assert(catalog.tableExists(TableIdentifier(oldViewName)))
assert(!catalog.tableExists(TableIdentifier(newViewName)))

var message = intercept[AnalysisException] {
sql(s"ALTER VIEW $tabName RENAME TO $newViewName")
}.getMessage
assert(message.contains(
"Cannot alter a table with ALTER VIEW. Please use ALTER TABLE instead"))
assertErrorForAlterViewOnTable(s"ALTER VIEW $tabName RENAME TO $newViewName")

message = intercept[AnalysisException] {
sql(s"ALTER VIEW $tabName SET TBLPROPERTIES ('p' = 'an')")
}.getMessage
assert(message.contains(
"Cannot alter a table with ALTER VIEW. Please use ALTER TABLE instead"))
assertErrorForAlterTableOnView(s"ALTER TABLE $oldViewName RENAME TO $newViewName")

message = intercept[AnalysisException] {
sql(s"ALTER VIEW $tabName UNSET TBLPROPERTIES ('p')")
}.getMessage
assert(message.contains(
"Cannot alter a table with ALTER VIEW. Please use ALTER TABLE instead"))
assertErrorForAlterViewOnTable(s"ALTER VIEW $tabName SET TBLPROPERTIES ('p' = 'an')")

message = intercept[AnalysisException] {
sql(s"ALTER TABLE $oldViewName RENAME TO $newViewName")
}.getMessage
assert(message.contains(
"Cannot alter a view with ALTER TABLE. Please use ALTER VIEW instead"))
assertErrorForAlterTableOnView(s"ALTER TABLE $oldViewName SET TBLPROPERTIES ('p' = 'an')")

message = intercept[AnalysisException] {
sql(s"ALTER TABLE $oldViewName SET TBLPROPERTIES ('p' = 'an')")
}.getMessage
assert(message.contains(
"Cannot alter a view with ALTER TABLE. Please use ALTER VIEW instead"))
assertErrorForAlterViewOnTable(s"ALTER VIEW $tabName UNSET TBLPROPERTIES ('p')")

message = intercept[AnalysisException] {
sql(s"ALTER TABLE $oldViewName UNSET TBLPROPERTIES ('p')")
}.getMessage
assert(message.contains(
"Cannot alter a view with ALTER TABLE. Please use ALTER VIEW instead"))
assertErrorForAlterTableOnView(s"ALTER TABLE $oldViewName UNSET TBLPROPERTIES ('p')")

assertErrorForAlterTableOnView(s"ALTER TABLE $oldViewName SET LOCATION '/path/to/home'")

assertErrorForAlterTableOnView(s"ALTER TABLE $oldViewName SET SERDE 'whatever'")

assertErrorForAlterTableOnView(s"ALTER TABLE $oldViewName SET SERDEPROPERTIES ('x' = 'y')")

assertErrorForAlterTableOnView(
s"ALTER TABLE $oldViewName PARTITION (a=1, b=2) SET SERDEPROPERTIES ('x' = 'y')")

assertErrorForAlterTableOnView(
s"ALTER TABLE $oldViewName ADD IF NOT EXISTS PARTITION (a='4', b='8')")

assertErrorForAlterTableOnView(s"ALTER TABLE $oldViewName DROP IF EXISTS PARTITION (a='2')")

assertErrorForAlterTableOnView(s"ALTER TABLE $oldViewName RECOVER PARTITIONS")

assertErrorForAlterTableOnView(
s"ALTER TABLE $oldViewName PARTITION (a='1') RENAME TO PARTITION (a='100')")

assert(catalog.tableExists(TableIdentifier(tabName)))
assert(catalog.tableExists(TableIdentifier(oldViewName)))
assert(!catalog.tableExists(TableIdentifier(newViewName)))
}
}
}
Expand Down