-
Notifications
You must be signed in to change notification settings - Fork 29.3k
[SPARK-30814][SQL] ALTER TABLE ... ADD COLUMN position should be able to reference columns being added #27584
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 2 commits
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 |
|---|---|---|
|
|
@@ -474,6 +474,7 @@ trait CheckAnalysis extends PredicateHelper { | |
| } | ||
|
|
||
| val colsToDelete = mutable.Set.empty[Seq[String]] | ||
| val colsToAdd = mutable.Set.empty[Seq[String]] | ||
|
|
||
| alter.changes.foreach { | ||
| case add: AddColumn => | ||
|
|
@@ -483,8 +484,16 @@ trait CheckAnalysis extends PredicateHelper { | |
| checkColumnNotExists("add", add.fieldNames(), table.schema) | ||
| } | ||
| val parent = findParentStruct("add", add.fieldNames()) | ||
| positionArgumentExists(add.position(), parent) | ||
| add.position match { | ||
| case after: After => | ||
| // Handle the case where column position is referencing new columns being added. | ||
| if (!colsToAdd.contains(add.fieldNames().init :+ after.column)) { | ||
| positionArgumentExists(add.position(), parent) | ||
|
Contributor
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. shall we just add one more parameter to
Contributor
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. just want to make sure all the caller side of |
||
| } | ||
| case _ => | ||
| } | ||
| TypeUtils.failWithIntervalType(add.dataType()) | ||
| colsToAdd += add.fieldNames() | ||
| case update: UpdateColumnType => | ||
| val field = findField("update", update.fieldNames) | ||
| val fieldName = update.fieldNames.quoted | ||
|
|
||
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.
Can we be more clear here? For example, if we add a column
a.b.c.d, which part should be the key?a.b.cora.b?