Skip to content

Comments

[SPARK-30814][SQL][3.0] ALTER TABLE ... ADD COLUMN position should be able to reference columns being added#27624

Closed
imback82 wants to merge 1 commit intoapache:branch-3.0from
imback82:backport_27584
Closed

[SPARK-30814][SQL][3.0] ALTER TABLE ... ADD COLUMN position should be able to reference columns being added#27624
imback82 wants to merge 1 commit intoapache:branch-3.0from
imback82:backport_27584

Conversation

@imback82
Copy link
Contributor

(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

@imback82
Copy link
Contributor Author

cc @cloud-fan

@SparkQA
Copy link

SparkQA commented Feb 18, 2020

Test build #118649 has finished for PR 27624 at commit 169a07e.

  • This patch passes all tests.
  • This patch merges cleanly.
  • This patch adds no public classes.

@cloud-fan
Copy link
Contributor

thanks, merging to 3.0!

cloud-fan pushed a commit that referenced this pull request Feb 19, 2020
… 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>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants