-
Notifications
You must be signed in to change notification settings - Fork 29k
[SPARK-27857][SQL] Move ALTER TABLE parsing into Catalyst #24723
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
Changes from all commits
62c161e
98bac21
d9694ba
5aa3b60
7e2369e
1a3810a
c558499
bd7d8c8
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -113,14 +113,27 @@ statement | |
| LIKE source=tableIdentifier locationSpec? #createTableLike | ||
| | ANALYZE TABLE tableIdentifier partitionSpec? COMPUTE STATISTICS | ||
| (identifier | FOR COLUMNS identifierSeq | FOR ALL COLUMNS)? #analyze | ||
| | ALTER TABLE tableIdentifier | ||
| ADD COLUMNS '(' columns=colTypeList ')' #addTableColumns | ||
| | ALTER TABLE multipartIdentifier | ||
| ADD (COLUMN | COLUMNS) | ||
| columns=qualifiedColTypeWithPositionList #addTableColumns | ||
| | ALTER TABLE multipartIdentifier | ||
| ADD (COLUMN | COLUMNS) | ||
| '(' columns=qualifiedColTypeWithPositionList ')' #addTableColumns | ||
| | ALTER TABLE multipartIdentifier | ||
| RENAME COLUMN from=qualifiedName TO to=identifier #renameTableColumn | ||
| | ALTER TABLE multipartIdentifier | ||
| DROP (COLUMN | COLUMNS) '(' columns=qualifiedNameList ')' #dropTableColumns | ||
| | ALTER TABLE multipartIdentifier | ||
| DROP (COLUMN | COLUMNS) columns=qualifiedNameList #dropTableColumns | ||
| | ALTER (TABLE | VIEW) from=tableIdentifier | ||
| RENAME TO to=tableIdentifier #renameTable | ||
| | ALTER (TABLE | VIEW) tableIdentifier | ||
| | ALTER (TABLE | VIEW) multipartIdentifier | ||
| SET TBLPROPERTIES tablePropertyList #setTableProperties | ||
| | ALTER (TABLE | VIEW) tableIdentifier | ||
| | ALTER (TABLE | VIEW) multipartIdentifier | ||
| UNSET TBLPROPERTIES (IF EXISTS)? tablePropertyList #unsetTableProperties | ||
| | ALTER TABLE multipartIdentifier | ||
| (ALTER | CHANGE) COLUMN? qualifiedName | ||
| (TYPE dataType)? (COMMENT comment=STRING)? colPosition? #alterTableColumn | ||
| | ALTER TABLE tableIdentifier partitionSpec? | ||
| CHANGE COLUMN? identifier colType colPosition? #changeColumn | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. How will we handle this version of
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think we need to discuss deprecating this form of the command, which is why I haven't updated it. The problem is that this requires the user to specify too much of a column's metadata when it isn't changing. For example, if I'm updating an int to a long, I also need to specify that it should have the same name ( I think that this form of the command should not be supported in v2. We can decide that later because all this is doing is updating the parser to add commands that we need to support. |
||
| | ALTER TABLE tableIdentifier (partitionSpec)? | ||
|
|
@@ -137,7 +150,8 @@ statement | |
| DROP (IF EXISTS)? partitionSpec (',' partitionSpec)* PURGE? #dropTablePartitions | ||
| | ALTER VIEW tableIdentifier | ||
| DROP (IF EXISTS)? partitionSpec (',' partitionSpec)* #dropTablePartitions | ||
| | ALTER TABLE tableIdentifier partitionSpec? SET locationSpec #setTableLocation | ||
| | ALTER TABLE multipartIdentifier SET locationSpec #setTableLocation | ||
| | ALTER TABLE tableIdentifier partitionSpec SET locationSpec #setPartitionLocation | ||
| | ALTER TABLE tableIdentifier RECOVER PARTITIONS #recoverPartitions | ||
| | DROP TABLE (IF EXISTS)? multipartIdentifier PURGE? #dropTable | ||
| | DROP VIEW (IF EXISTS)? multipartIdentifier #dropView | ||
|
|
@@ -720,7 +734,7 @@ intervalUnit | |
| ; | ||
|
|
||
| colPosition | ||
| : FIRST | AFTER identifier | ||
| : FIRST | AFTER qualifiedName | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Do we need to modify this? I'm not sure what happens if something like:
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes, this is needed because columns are identified by
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I should also add that it is valid to reorder nested fields: |
||
| ; | ||
|
|
||
| dataType | ||
|
|
@@ -730,6 +744,14 @@ dataType | |
| | identifier ('(' INTEGER_VALUE (',' INTEGER_VALUE)* ')')? #primitiveDataType | ||
| ; | ||
|
|
||
| qualifiedColTypeWithPositionList | ||
| : qualifiedColTypeWithPosition (',' qualifiedColTypeWithPosition)* | ||
| ; | ||
|
|
||
| qualifiedColTypeWithPosition | ||
| : name=qualifiedName dataType (COMMENT comment=STRING)? colPosition? | ||
| ; | ||
|
|
||
| colTypeList | ||
| : colType (',' colType)* | ||
| ; | ||
|
|
@@ -782,6 +804,10 @@ frameBound | |
| | expression boundType=(PRECEDING | FOLLOWING) | ||
| ; | ||
|
|
||
| qualifiedNameList | ||
| : qualifiedName (',' qualifiedName)* | ||
| ; | ||
|
|
||
| qualifiedName | ||
| : identifier ('.' identifier)* | ||
| ; | ||
|
|
@@ -1244,6 +1270,7 @@ nonReserved | |
| | TRANSFORM | ||
| | TRUE | ||
| | TRUNCATE | ||
| | TYPE | ||
|
||
| | UNARCHIVE | ||
| | UNBOUNDED | ||
| | UNCACHE | ||
|
|
@@ -1499,6 +1526,7 @@ TRANSACTIONS: 'TRANSACTIONS'; | |
| TRANSFORM: 'TRANSFORM'; | ||
| TRUE: 'TRUE'; | ||
| TRUNCATE: 'TRUNCATE'; | ||
| TYPE: 'TYPE'; | ||
| UNARCHIVE: 'UNARCHIVE'; | ||
| UNBOUNDED: 'UNBOUNDED'; | ||
| UNCACHE: 'UNCACHE'; | ||
|
|
||
| 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 |
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.
Have you checked other databases/SQL standard that the parentheses can be omitted in the ALTER TABLE statement?
Uh oh!
There was an error while loading. Please reload this page.
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.
Yes. PostgreSQL, MySQL, and Oracle support this for a single column. PosgreSQL doesn't allow multiple columns. MySQL allows multiple columns without parens. And Oracle requires parens to add multiple columns. These don't assist parsing, which is why I think it is better to optionally support them.
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.
Looks like DB2 and SQL server also allow adding multiple columns without parens.