forked from apache/spark
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[SPARK-27857][SQL] Move ALTER TABLE parsing into Catalyst
## What changes were proposed in this pull request? This moves parsing logic for `ALTER TABLE` into Catalyst and adds parsed logical plans for alter table changes that use multi-part identifiers. This PR is similar to SPARK-27108, PR apache#24029, that created parsed logical plans for create and CTAS. * Create parsed logical plans * Move parsing logic into Catalyst's AstBuilder * Convert to DataSource plans in DataSourceResolution * Parse `ALTER TABLE ... SET LOCATION ...` separately from the partition variant * Parse `ALTER TABLE ... ALTER COLUMN ... [TYPE dataType] [COMMENT comment]` [as discussed on the dev list](http://apache-spark-developers-list.1001551.n3.nabble.com/DISCUSS-Syntax-for-table-DDL-td25197.html#a25270) * Parse `ALTER TABLE ... RENAME COLUMN ... TO ...` * Parse `ALTER TABLE ... DROP COLUMNS ...` ## How was this patch tested? * Added new tests in Catalyst's `DDLParserSuite` * Moved converted plan tests from SQL `DDLParserSuite` to `PlanResolutionSuite` * Existing tests for regressions Closes apache#24723 from rdblue/SPARK-27857-add-alter-table-statements-in-catalyst. Authored-by: Ryan Blue <blue@apache.org> Signed-off-by: gatorsmile <gatorsmile@gmail.com>
- Loading branch information
1 parent
2213da0
commit 339cd29
Showing
11 changed files
with
635 additions
and
141 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
78 changes: 78 additions & 0 deletions
78
...src/main/scala/org/apache/spark/sql/catalyst/plans/logical/sql/AlterTableStatements.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
/* | ||
* Licensed to the Apache Software Foundation (ASF) under one or more | ||
* contributor license agreements. See the NOTICE file distributed with | ||
* this work for additional information regarding copyright ownership. | ||
* The ASF licenses this file to You under the Apache License, Version 2.0 | ||
* (the "License"); you may not use this file except in compliance with | ||
* the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package org.apache.spark.sql.catalyst.plans.logical.sql | ||
|
||
import org.apache.spark.sql.types.DataType | ||
|
||
/** | ||
* Column data as parsed by ALTER TABLE ... ADD COLUMNS. | ||
*/ | ||
case class QualifiedColType(name: Seq[String], dataType: DataType, comment: Option[String]) | ||
|
||
/** | ||
* ALTER TABLE ... ADD COLUMNS command, as parsed from SQL. | ||
*/ | ||
case class AlterTableAddColumnsStatement( | ||
tableName: Seq[String], | ||
columnsToAdd: Seq[QualifiedColType]) extends ParsedStatement | ||
|
||
/** | ||
* ALTER TABLE ... CHANGE COLUMN command, as parsed from SQL. | ||
*/ | ||
case class AlterTableAlterColumnStatement( | ||
tableName: Seq[String], | ||
column: Seq[String], | ||
dataType: Option[DataType], | ||
comment: Option[String]) extends ParsedStatement | ||
|
||
/** | ||
* ALTER TABLE ... RENAME COLUMN command, as parsed from SQL. | ||
*/ | ||
case class AlterTableRenameColumnStatement( | ||
tableName: Seq[String], | ||
column: Seq[String], | ||
newName: String) extends ParsedStatement | ||
|
||
/** | ||
* ALTER TABLE ... DROP COLUMNS command, as parsed from SQL. | ||
*/ | ||
case class AlterTableDropColumnsStatement( | ||
tableName: Seq[String], | ||
columnsToDrop: Seq[Seq[String]]) extends ParsedStatement | ||
|
||
/** | ||
* ALTER TABLE ... SET TBLPROPERTIES command, as parsed from SQL. | ||
*/ | ||
case class AlterTableSetPropertiesStatement( | ||
tableName: Seq[String], | ||
properties: Map[String, String]) extends ParsedStatement | ||
|
||
/** | ||
* ALTER TABLE ... UNSET TBLPROPERTIES command, as parsed from SQL. | ||
*/ | ||
case class AlterTableUnsetPropertiesStatement( | ||
tableName: Seq[String], | ||
propertyKeys: Seq[String], | ||
ifExists: Boolean) extends ParsedStatement | ||
|
||
/** | ||
* ALTER TABLE ... SET LOCATION command, as parsed from SQL. | ||
*/ | ||
case class AlterTableSetLocationStatement( | ||
tableName: Seq[String], | ||
location: String) extends ParsedStatement |
Oops, something went wrong.