Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
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
Original file line number Diff line number Diff line change
Expand Up @@ -3705,7 +3705,7 @@ class AstBuilder extends SqlBaseBaseVisitor[AnyRef] with SQLConfHelper with Logg
}

/**
* Create an [[AlterTableRecoverPartitionsStatement]]
* Create an [[AlterTableRecoverPartitions]]
*
* For example:
* {{{
Expand All @@ -3714,7 +3714,10 @@ class AstBuilder extends SqlBaseBaseVisitor[AnyRef] with SQLConfHelper with Logg
*/
override def visitRecoverPartitions(
ctx: RecoverPartitionsContext): LogicalPlan = withOrigin(ctx) {
AlterTableRecoverPartitionsStatement(visitMultipartIdentifier(ctx.multipartIdentifier))
AlterTableRecoverPartitions(
UnresolvedTable(
visitMultipartIdentifier(ctx.multipartIdentifier),
"ALTER TABLE ... RECOVER PARTITIONS"))
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -292,12 +292,6 @@ case class AlterTableSetLocationStatement(
partitionSpec: Option[TablePartitionSpec],
location: String) extends ParsedStatement

/**
* ALTER TABLE ... RECOVER PARTITIONS command, as parsed from SQL.
*/
case class AlterTableRecoverPartitionsStatement(
tableName: Seq[String]) extends ParsedStatement

/**
* ALTER TABLE ... RENAME PARTITION command, as parsed from SQL.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -673,6 +673,13 @@ case class AlterTableDropPartition(
override def children: Seq[LogicalPlan] = child :: Nil
}

/**
* The logical plan of the ALTER TABLE ... RECOVER PARTITIONS command.
*/
case class AlterTableRecoverPartitions(child: LogicalPlan) extends Command {
override def children: Seq[LogicalPlan] = child :: Nil
}

/**
* The logical plan of the LOAD DATA INTO TABLE command.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2076,7 +2076,8 @@ class DDLParserSuite extends AnalysisTest {
test("alter table: recover partitions") {
comparePlans(
parsePlan("ALTER TABLE a.b.c RECOVER PARTITIONS"),
AlterTableRecoverPartitionsStatement(Seq("a", "b", "c")))
AlterTableRecoverPartitions(
UnresolvedTable(Seq("a", "b", "c"), "ALTER TABLE ... RECOVER PARTITIONS")))
}

test("alter view: add partition (not supported)") {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -449,10 +449,9 @@ class ResolveSessionCatalog(
}
ShowColumnsCommand(db, v1TableName)

case AlterTableRecoverPartitionsStatement(tbl) =>
val v1TableName = parseV1Table(tbl, "ALTER TABLE RECOVER PARTITIONS")
case AlterTableRecoverPartitions(ResolvedV1TableIdentifier(ident)) =>
AlterTableRecoverPartitionsCommand(
v1TableName.asTableIdentifier,
ident.asTableIdentifier,
"ALTER TABLE RECOVER PARTITIONS")

case AlterTableAddPartition(ResolvedV1TableIdentifier(ident), partSpecsAndLocs, ifNotExists) =>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -330,6 +330,10 @@ class DataSourceV2Strategy(session: SparkSession) extends Strategy with Predicat
AlterTableDropPartitionExec(
table, parts.asResolvedPartitionSpecs, ignoreIfNotExists) :: Nil

case AlterTableRecoverPartitions(_: ResolvedTable) =>
throw new AnalysisException(
"ALTER TABLE ... RECOVER PARTITIONS is not supported for v2 tables.")

case LoadData(_: ResolvedTable, _, _, _, _) =>
throw new AnalysisException("LOAD DATA is not supported for v2 tables.")

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,8 @@ class AlterTablePartitionV2SQLSuite extends DatasourceV2SQLBase {
val e = intercept[AnalysisException] {
sql(s"ALTER TABLE $t RECOVER PARTITIONS")
}
assert(e.message.contains("ALTER TABLE RECOVER PARTITIONS is only supported with v1 tables"))
assert(e.message.contains(
"ALTER TABLE ... RECOVER PARTITIONS is not supported for v2 tables."))
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,9 @@ abstract class SQLViewSuite extends QueryTest with SQLTestUtils {
assertNoSuchTable(s"ALTER TABLE $viewName PARTITION (a=1, b=2) SET SERDE 'whatever'")
assertNoSuchTable(s"ALTER TABLE $viewName SET SERDEPROPERTIES ('p' = 'an')")
assertNoSuchTable(s"ALTER TABLE $viewName PARTITION (a='4') RENAME TO PARTITION (a='5')")
assertNoSuchTable(s"ALTER TABLE $viewName RECOVER PARTITIONS")
assertAnalysisError(
s"ALTER TABLE $viewName RECOVER PARTITIONS",
s"$viewName is a temp view. 'ALTER TABLE ... RECOVER PARTITIONS' expects a table")

// For v2 ALTER TABLE statements, we have better error message saying view is not supported.
assertAnalysisError(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -899,7 +899,9 @@ class HiveDDLSuite
assertErrorForAlterTableOnView(
s"ALTER TABLE $oldViewName PARTITION (a=1, b=2) SET SERDEPROPERTIES ('x' = 'y')")

assertErrorForAlterTableOnView(s"ALTER TABLE $oldViewName RECOVER PARTITIONS")
assertAnalysisError(
s"ALTER TABLE $oldViewName RECOVER PARTITIONS",
s"$oldViewName is a view. 'ALTER TABLE ... RECOVER PARTITIONS' expects a table.")

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