Skip to content

Conversation

@jackierwzhang
Copy link
Contributor

@jackierwzhang jackierwzhang commented Apr 19, 2022

What changes were proposed in this pull request?

This PR introduces the following:

  • Parser changes to have an IF EXISTS clause for DROP COLUMN.
  • Logic to silence the errors within parser and analyzer when encountering missing columns while using IF EXISTS
  • Ensure only resolving and dropping existing columns inside table schema

Why are the changes needed?

Currently ALTER TABLE ... DROP COLUMN(s) ... syntax will always throw error if the column doesn't exist. This PR would like to provide an (IF EXISTS) syntax to provide better user experience for downstream handlers (such as Delta with incoming column dropping support) that support it, and make consistent with some other DMLs such as DROP TABLE IF EXISTS.

Does this PR introduce any user-facing change?

User may now specify ALTER TABLE xxx DROP COLUMN(S) IF EXISTS a, a.b, c.d.

How was this patch tested?

Modified existing unit tests and new unit tests.

@cloud-fan @gengliangwang @MaxGekk

@github-actions github-actions bot added the SQL label Apr 19, 2022
@jackierwzhang jackierwzhang changed the title [SPARK-38939][SQL] Support DROP [IF EXISTS] COLUMN syntax [SPARK-38939][SQL] Support DROP COLUMN [IF EXISTS] syntax Apr 19, 2022
@AmplabJenkins
Copy link

Can one of the admins verify this patch?

@cloud-fan
Copy link
Contributor

thanks, merging to master!

@cloud-fan cloud-fan closed this in efa70e4 Apr 25, 2022
cloud-fan pushed a commit that referenced this pull request Apr 25, 2022
### What changes were proposed in this pull request?
This PR introduces the following:
- Parser changes to have an `IF EXISTS` clause for `DROP COLUMN`.
- Logic to silence the errors within parser and analyzer when encountering missing columns while using `IF EXISTS`
- Ensure only resolving and dropping existing columns inside table schema

### Why are the changes needed?
Currently `ALTER TABLE ... DROP COLUMN(s) ...` syntax will always throw error if the column doesn't exist. This PR would like to provide an (IF EXISTS) syntax to provide better user experience for downstream handlers (such as Delta with incoming column dropping support) that support it, and make consistent with some other DMLs such as `DROP TABLE IF EXISTS`.

### Does this PR introduce _any_ user-facing change?
User may now specify `ALTER TABLE xxx DROP COLUMN(S) IF EXISTS a, a.b, c.d`.

### How was this patch tested?
Modified existing unit tests and new unit tests.

cloud-fan gengliangwang MaxGekk

Closes #36252 from jackierwzhang/SPARK-38939.

Authored-by: jackierwzhang <[email protected]>
Signed-off-by: Wenchen Fan <[email protected]>
@cloud-fan
Copy link
Contributor

cloud-fan commented Apr 25, 2022

I also backported to 3.3 as it changes DS v2 API (DeleteColumn), so that it's possible to stabilize DS v2 API in 3.4. We can revert it if there are objections.

huaxingao pushed a commit that referenced this pull request May 9, 2022
…ReplaceColumns

### What changes were proposed in this pull request?

This PR aims to replace named parameter with comment in `ReplaceColumns`.

### Why are the changes needed?

#36252 changed signature of deleteColumn#**TableChange.java**, but this PR breaks sbt compilation in k8s integration test.
```shell
> build/sbt -Pkubernetes -Pkubernetes-integration-tests -Dtest.exclude.tags=r -Dspark.kubernetes.test.imageRepo=kubespark "kubernetes-integration-tests/test"
[error] /Users/IdeaProjects/spark/sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/plans/logical/v2AlterTableCommands.scala:147:45: not found: value ifExists
[error]       TableChange.deleteColumn(Array(name), ifExists = false)
[error]                                             ^
[error] /Users/IdeaProjects/spark/sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/plans/logical/v2AlterTableCommands.scala:159:19: value ++ is not a member of Array[Nothing]
[error]     deleteChanges ++ addChanges
[error]                   ^
[error] two errors found
[error] (catalyst / Compile / compileIncremental) Compilation failed
```

### Does this PR introduce _any_ user-facing change?

No

### How was this patch tested?

Pass the GA and k8s integration test.

Closes #36487 from dcoliversun/SPARK-38939.

Authored-by: Qian.Sun <[email protected]>
Signed-off-by: huaxingao <[email protected]>
(cherry picked from commit 16b5124)
Signed-off-by: huaxingao <[email protected]>
huaxingao pushed a commit that referenced this pull request May 9, 2022
…ReplaceColumns

### What changes were proposed in this pull request?

This PR aims to replace named parameter with comment in `ReplaceColumns`.

### Why are the changes needed?

#36252 changed signature of deleteColumn#**TableChange.java**, but this PR breaks sbt compilation in k8s integration test.
```shell
> build/sbt -Pkubernetes -Pkubernetes-integration-tests -Dtest.exclude.tags=r -Dspark.kubernetes.test.imageRepo=kubespark "kubernetes-integration-tests/test"
[error] /Users/IdeaProjects/spark/sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/plans/logical/v2AlterTableCommands.scala:147:45: not found: value ifExists
[error]       TableChange.deleteColumn(Array(name), ifExists = false)
[error]                                             ^
[error] /Users/IdeaProjects/spark/sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/plans/logical/v2AlterTableCommands.scala:159:19: value ++ is not a member of Array[Nothing]
[error]     deleteChanges ++ addChanges
[error]                   ^
[error] two errors found
[error] (catalyst / Compile / compileIncremental) Compilation failed
```

### Does this PR introduce _any_ user-facing change?

No

### How was this patch tested?

Pass the GA and k8s integration test.

Closes #36487 from dcoliversun/SPARK-38939.

Authored-by: Qian.Sun <[email protected]>
Signed-off-by: huaxingao <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants