Skip to content

Conversation

Clearvive
Copy link
Contributor

What changes were proposed in this pull request?

When 'ifExisting' is set to true in the 'deleteColumn' function, it will validate the existence of the specified column. If the column does not exist, it will throw an exception.

Why are the changes needed?

Fix: #1112

Does this PR introduce any user-facing change?

Users should be aware that when using 'deleteColumn,' it may throw a new exception, 'IllegalArgumentException.'

How was this patch tested?

UT

@Clearvive Clearvive added this to the Gravitino 0.4.0 milestone Dec 19, 2023
@Clearvive Clearvive self-assigned this Dec 19, 2023
@Clearvive Clearvive added branch-0.3 bug Something isn't working and removed bug Something isn't working labels Dec 19, 2023
@yuqi1129 yuqi1129 added the need backport Issues that need to backport to another branch label Dec 20, 2023
.anyMatch(s -> StringUtils.equals(col, s));
if (!colExists) {
if (BooleanUtils.isTrue(deleteColumn.getIfExists())) {
return "";
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does MySQL support ALTER TABLE table_name syntax if we get a empty string here directly?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

image

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

MySQL supports such statements

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

suggest to add a check to skip execute if Alter SQL content is empty.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In that case, there will be more code modifications, and all upper layers need to make a judgment once

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have modified this part of the code. Could you please help me review it

@Clearvive Clearvive requested review from yuqi1129 and FANNG1 December 20, 2023 06:53
@@ -322,7 +323,8 @@ protected String generateAlterTableSql(
updateColumnPositionFieldDefinition(updateColumnPosition, lazyLoadCreateTable));
} else if (change instanceof TableChange.DeleteColumn) {
TableChange.DeleteColumn deleteColumn = (TableChange.DeleteColumn) change;
alterSql.add(deleteColumnFieldDefinition(deleteColumn));
lazyLoadCreateTable = getOrCreateTable(databaseName, tableName, lazyLoadCreateTable);
alterSql.add(deleteColumnFieldDefinition(deleteColumn, lazyLoadCreateTable));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think you can judge whether the return value of deleteColumnFieldDefinition is empty, if it's not empty, we can then put it into alterSql;

Line 358 would not work if we do multiple changes at the same time.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok

@Clearvive Clearvive requested a review from yuqi1129 December 21, 2023 03:46
yuqi1129
yuqi1129 previously approved these changes Dec 21, 2023
Copy link
Contributor

@yuqi1129 yuqi1129 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@jerryshao jerryshao changed the title [#1112] bugfix(jdbc): deleteColumn throws exception for table with ifExisting = true. [#1112] fix(jdbc): deleteColumn throws exception for table with ifExisting = true. Dec 21, 2023
if (BooleanUtils.isTrue(deleteColumn.getIfExists())) {
return "";
} else {
throw new IllegalArgumentException("delete column not exists: " + col);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"Delete column does not exist: "

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok

if (BooleanUtils.isTrue(deleteColumn.getIfExists())) {
return "";
} else {
throw new IllegalArgumentException("delete column not exists: " + col);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"Delete column does not exist: ".

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok

Copy link
Contributor

@jerryshao jerryshao left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM.

@jerryshao jerryshao merged commit 972747e into apache:main Dec 21, 2023
github-actions bot pushed a commit that referenced this pull request Dec 21, 2023
…sting = true. (#1200)

### What changes were proposed in this pull request?
When 'ifExisting' is set to true in the 'deleteColumn' function, it will
validate the existence of the specified column. If the column does not
exist, it will throw an exception.


### Why are the changes needed?
Fix: #1112 

### Does this PR introduce _any_ user-facing change?
Users should be aware that when using 'deleteColumn,' it may throw a new
exception, 'IllegalArgumentException.'

### How was this patch tested?
UT

---------

Co-authored-by: Clearvive <clearvive@datastrato.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
need backport Issues that need to backport to another branch
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Bug report] deleteColumn throws expection for Iceberg table with ifExisting = true
4 participants