-
Notifications
You must be signed in to change notification settings - Fork 8.3k
Add support for renaming columns in Iceberg storage #97455
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
Merged
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
72 changes: 72 additions & 0 deletions
72
tests/integration/test_storage_iceberg_no_spark/test_writes_rename_column.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,72 @@ | ||
| import pytest | ||
|
|
||
| from helpers.iceberg_utils import ( | ||
| create_iceberg_table, | ||
| get_uuid_str, | ||
| ) | ||
|
|
||
| INSERT_SETTINGS = {"allow_insert_into_iceberg": 1} | ||
|
|
||
|
|
||
| @pytest.mark.parametrize("format_version", [1, 2]) | ||
| @pytest.mark.parametrize("storage_type", ["local", "s3"]) | ||
| def test_rename_column_basic(started_cluster_iceberg_no_spark, format_version, storage_type): | ||
| """Rename a column: existing rows are readable under the new name, and new inserts work.""" | ||
| instance = started_cluster_iceberg_no_spark.instances["node1"] | ||
| TABLE_NAME = "test_rename_column_basic_" + storage_type + "_" + get_uuid_str() | ||
|
|
||
| create_iceberg_table( | ||
| storage_type, | ||
| instance, | ||
| TABLE_NAME, | ||
| started_cluster_iceberg_no_spark, | ||
| "(id Int32, value Nullable(String))", | ||
| format_version, | ||
| ) | ||
|
|
||
| instance.query(f"INSERT INTO {TABLE_NAME} VALUES (1, 'hello'), (2, 'world');", settings=INSERT_SETTINGS) | ||
| assert instance.query(f"SELECT id, value FROM {TABLE_NAME} ORDER BY id") == "1\thello\n2\tworld\n" | ||
|
|
||
| instance.query(f"ALTER TABLE {TABLE_NAME} RENAME COLUMN value TO label;", settings=INSERT_SETTINGS) | ||
|
|
||
| # existing rows readable under the new name | ||
| assert instance.query(f"SELECT id, label FROM {TABLE_NAME} ORDER BY id") == "1\thello\n2\tworld\n" | ||
|
|
||
| # new inserts work under the new name | ||
| instance.query(f"INSERT INTO {TABLE_NAME} VALUES (3, 'foo');", settings=INSERT_SETTINGS) | ||
| assert instance.query(f"SELECT id, label FROM {TABLE_NAME} ORDER BY id") == "1\thello\n2\tworld\n3\tfoo\n" | ||
|
|
||
|
|
||
| @pytest.mark.parametrize("format_version", [1, 2]) | ||
| @pytest.mark.parametrize("storage_type", ["local", "s3"]) | ||
| def test_rename_column_errors(started_cluster_iceberg_no_spark, format_version, storage_type): | ||
| """Renaming a non-existent column or renaming to an already-used name must raise BAD_ARGUMENTS.""" | ||
| instance = started_cluster_iceberg_no_spark.instances["node1"] | ||
| TABLE_NAME = "test_rename_column_errors_" + storage_type + "_" + get_uuid_str() | ||
|
|
||
| create_iceberg_table( | ||
| storage_type, | ||
| instance, | ||
| TABLE_NAME, | ||
| started_cluster_iceberg_no_spark, | ||
| "(id Int32, value Nullable(String))", | ||
| format_version, | ||
| ) | ||
|
|
||
| # rename a column that does not exist — rejected by AlterCommands::validate (NOT_FOUND_COLUMN_IN_BLOCK) | ||
| error = instance.query_and_get_error( | ||
| f"ALTER TABLE {TABLE_NAME} RENAME COLUMN nonexistent TO other;", | ||
| settings=INSERT_SETTINGS, | ||
| ) | ||
| assert "nonexistent" in error | ||
|
|
||
| # rename to a name already used by another column — rejected by AlterCommands::validate (DUPLICATE_COLUMN) | ||
| error = instance.query_and_get_error( | ||
| f"ALTER TABLE {TABLE_NAME} RENAME COLUMN value TO id;", | ||
| settings=INSERT_SETTINGS, | ||
| ) | ||
| assert "DUPLICATE_COLUMN" in error | ||
| assert "id" in error | ||
|
|
||
| # table structure must be unchanged after both failed renames | ||
| assert instance.query(f"SELECT name FROM system.columns WHERE database = currentDatabase() AND table = '{TABLE_NAME}' ORDER BY name") == "id\nvalue\n" |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.