[SPARK-30814][SQL] ALTER TABLE ... ADD COLUMN position should be able to reference columns being added #27584
[SPARK-30814][SQL] ALTER TABLE ... ADD COLUMN position should be able to reference columns being added #27584imback82 wants to merge 5 commits intoapache:masterfrom
Conversation
|
Test build #118443 has finished for PR 27584 at commit
|
|
Test build #118451 has finished for PR 27584 at commit
|
| def apply(plan: LogicalPlan): LogicalPlan = plan.resolveOperatorsUp { | ||
| case a @ AlterTable(_, _, t: NamedRelation, changes) if t.resolved => | ||
| // Keeps track of new columns being added. Keys are normalized parent names and | ||
| // values are field names that belong to their parent. |
There was a problem hiding this comment.
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.c or a.b?
| 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) |
There was a problem hiding this comment.
shall we just add one more parameter to positionArgumentExists for the newly added columns?
There was a problem hiding this comment.
just want to make sure all the caller side of positionArgumentExists take care of newly added columns.
cloud-fan
left a comment
There was a problem hiding this comment.
LGTM except one comment
|
Test build #118544 has finished for PR 27584 at commit
|
|
retest this please |
|
Test build #118556 has finished for PR 27584 at commit
|
|
LGTM as well! Thanks @imback82 for the quick fix :) |
|
Test build #118599 has finished for PR 27584 at commit
|
|
thanks, merging to master/3.0! |
… able to reference columns being added (Backport of #27584 + partial #27482) ### What changes were proposed in this pull request? In ALTER TABLE, a column in ADD COLUMNS can depend on the position of a column that is just being added. For example, for a table with the following schema: ``` root: - a: string - b: long ``` , the following should work: ``` ALTER TABLE t ADD COLUMNS (x int AFTER a, y int AFTER x) ``` Currently, the above statement will throw an exception saying that AFTER x cannot be resolved, because x doesn't exist yet. This PR proposes to fix this issue. ### Why are the changes needed? To fix a bug described above. ### Does this PR introduce any user-facing change? Yes, now ``` ALTER TABLE t ADD COLUMNS (x int AFTER a, y int AFTER x) ``` works as expected. ### How was this patch tested? Added new tests Closes #27624 from imback82/backport_27584. Authored-by: Terry Kim <yuminkim@gmail.com> Signed-off-by: Wenchen Fan <wenchen@databricks.com>
… to reference columns being added ### What changes were proposed in this pull request? In ALTER TABLE, a column in ADD COLUMNS can depend on the position of a column that is just being added. For example, for a table with the following schema: ``` root: - a: string - b: long ``` , the following should work: ``` ALTER TABLE t ADD COLUMNS (x int AFTER a, y int AFTER x) ``` Currently, the above statement will throw an exception saying that AFTER x cannot be resolved, because x doesn't exist yet. This PR proposes to fix this issue. ### Why are the changes needed? To fix a bug described above. ### Does this PR introduce any user-facing change? Yes, now ``` ALTER TABLE t ADD COLUMNS (x int AFTER a, y int AFTER x) ``` works as expected. ### How was this patch tested? Added new tests Closes apache#27584 from imback82/alter_table_pos_fix. Authored-by: Terry Kim <yuminkim@gmail.com> Signed-off-by: Wenchen Fan <wenchen@databricks.com>
What changes were proposed in this pull request?
In ALTER TABLE, a column in ADD COLUMNS can depend on the position of a column that is just being added. For example, for a table with the following schema:
, the following should work:
Currently, the above statement will throw an exception saying that AFTER x cannot be resolved, because x doesn't exist yet. This PR proposes to fix this issue.
Why are the changes needed?
To fix a bug described above.
Does this PR introduce any user-facing change?
Yes, now
works as expected.
How was this patch tested?
Added new tests