-
Notifications
You must be signed in to change notification settings - Fork 209
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
Remove initial_change
when CreateTableTransaction apply table updates on an empty metadata
#1219
Merged
Merged
Changes from all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
c936c41
make table metadata without validaiton
HonahX 07ac53c
update deletes test
HonahX b8adf4d
remove info
HonahX 6c98bb0
add deprecation message
HonahX 50df890
Merge branch 'main' into honahx_remove_initial_changes
HonahX 20f6a94
revert lib version updates
HonahX 37c5ae7
remove initial_changes usage in code
HonahX dce2b49
move test to integration
HonahX f512cb6
fix typo
HonahX cdeb0e6
update error string
HonahX d3ea218
Merge branch 'main' into honahx_remove_initial_changes
HonahX 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 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 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 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 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 |
---|---|---|
|
@@ -18,7 +18,6 @@ | |
|
||
import uuid | ||
from abc import ABC, abstractmethod | ||
from copy import copy | ||
from datetime import datetime | ||
from functools import singledispatch | ||
from typing import TYPE_CHECKING, Any, Dict, Generic, List, Literal, Optional, Tuple, TypeVar, Union | ||
|
@@ -45,6 +44,7 @@ | |
transform_dict_value_to_str, | ||
) | ||
from pyiceberg.utils.datetime import datetime_to_millis | ||
from pyiceberg.utils.deprecated import deprecation_notice | ||
from pyiceberg.utils.properties import property_as_int | ||
|
||
if TYPE_CHECKING: | ||
|
@@ -90,7 +90,13 @@ class AddSchemaUpdate(IcebergBaseModel): | |
# This field is required: https://github.com/apache/iceberg/pull/7445 | ||
last_column_id: int = Field(alias="last-column-id") | ||
|
||
initial_change: bool = Field(default=False, exclude=True) | ||
initial_change: bool = Field( | ||
default=False, | ||
exclude=True, | ||
deprecated=deprecation_notice( | ||
deprecated_in="0.8.0", removed_in="0.9.0", help_message="CreateTableTransaction can work without this field" | ||
), | ||
) | ||
|
||
|
||
class SetCurrentSchemaUpdate(IcebergBaseModel): | ||
|
@@ -104,7 +110,13 @@ class AddPartitionSpecUpdate(IcebergBaseModel): | |
action: Literal["add-spec"] = Field(default="add-spec") | ||
spec: PartitionSpec | ||
|
||
initial_change: bool = Field(default=False, exclude=True) | ||
initial_change: bool = Field( | ||
default=False, | ||
exclude=True, | ||
deprecated=deprecation_notice( | ||
deprecated_in="0.8.0", removed_in="0.9.0", help_message="CreateTableTransaction can work without this field" | ||
), | ||
) | ||
|
||
|
||
class SetDefaultSpecUpdate(IcebergBaseModel): | ||
|
@@ -118,7 +130,13 @@ class AddSortOrderUpdate(IcebergBaseModel): | |
action: Literal["add-sort-order"] = Field(default="add-sort-order") | ||
sort_order: SortOrder = Field(alias="sort-order") | ||
|
||
initial_change: bool = Field(default=False, exclude=True) | ||
initial_change: bool = Field( | ||
default=False, | ||
exclude=True, | ||
deprecated=deprecation_notice( | ||
deprecated_in="0.8.0", removed_in="0.9.0", help_message="CreateTableTransaction can work without this field" | ||
), | ||
) | ||
|
||
|
||
class SetDefaultSortOrderUpdate(IcebergBaseModel): | ||
|
@@ -267,11 +285,10 @@ def _( | |
elif update.format_version == base_metadata.format_version: | ||
return base_metadata | ||
|
||
updated_metadata_data = copy(base_metadata.model_dump()) | ||
updated_metadata_data["format-version"] = update.format_version | ||
updated_metadata = base_metadata.model_copy(update={"format_version": update.format_version}) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nice! |
||
|
||
context.add_update(update) | ||
return TableMetadataUtil.parse_obj(updated_metadata_data) | ||
return TableMetadataUtil._construct_without_validation(updated_metadata) | ||
|
||
|
||
@_apply_table_update.register(SetPropertiesUpdate) | ||
|
@@ -306,7 +323,7 @@ def _(update: AddSchemaUpdate, base_metadata: TableMetadata, context: _TableMeta | |
|
||
metadata_updates: Dict[str, Any] = { | ||
"last_column_id": update.last_column_id, | ||
"schemas": [update.schema_] if update.initial_change else base_metadata.schemas + [update.schema_], | ||
"schemas": base_metadata.schemas + [update.schema_], | ||
} | ||
|
||
context.add_update(update) | ||
|
@@ -336,11 +353,11 @@ def _(update: SetCurrentSchemaUpdate, base_metadata: TableMetadata, context: _Ta | |
@_apply_table_update.register(AddPartitionSpecUpdate) | ||
def _(update: AddPartitionSpecUpdate, base_metadata: TableMetadata, context: _TableMetadataUpdateContext) -> TableMetadata: | ||
for spec in base_metadata.partition_specs: | ||
if spec.spec_id == update.spec.spec_id and not update.initial_change: | ||
if spec.spec_id == update.spec.spec_id: | ||
raise ValueError(f"Partition spec with id {spec.spec_id} already exists: {spec}") | ||
|
||
metadata_updates: Dict[str, Any] = { | ||
"partition_specs": [update.spec] if update.initial_change else base_metadata.partition_specs + [update.spec], | ||
"partition_specs": base_metadata.partition_specs + [update.spec], | ||
"last_partition_id": max( | ||
max([field.field_id for field in update.spec.fields], default=0), | ||
base_metadata.last_partition_id or PARTITION_FIELD_ID_START - 1, | ||
|
@@ -448,7 +465,7 @@ def _(update: AddSortOrderUpdate, base_metadata: TableMetadata, context: _TableM | |
context.add_update(update) | ||
return base_metadata.model_copy( | ||
update={ | ||
"sort_orders": [update.sort_order] if update.initial_change else base_metadata.sort_orders + [update.sort_order], | ||
"sort_orders": base_metadata.sort_orders + [update.sort_order], | ||
} | ||
) | ||
|
||
|
This file contains 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 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
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It is clean to go through the validation cycle, but I would be surprised if anyone would be relying on these properties