-
Notifications
You must be signed in to change notification settings - Fork 426
Block schema field drop if it is reference by an active partition or sort field #2410
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
5 commits
Select commit
Hold shift + click to select a range
e12f66e
check partition and sort order and implement sort_order in table_meta…
gabeiglio ac66149
Update pyiceberg/partitioning.py
kevinjqliu de93cea
Update pyiceberg/partitioning.py
kevinjqliu 26660eb
make lint
kevinjqliu a72f5ee
fix test msg
kevinjqliu 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
Some comments aren't visible on the classic Files Changed page.
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -32,6 +32,7 @@ | |
| model_validator, | ||
| ) | ||
|
|
||
| from pyiceberg.exceptions import ValidationError | ||
| from pyiceberg.schema import Schema | ||
| from pyiceberg.transforms import ( | ||
| BucketTransform, | ||
|
|
@@ -249,6 +250,39 @@ def partition_to_path(self, data: Record, schema: Schema) -> str: | |
| path = "/".join([field_str + "=" + value_str for field_str, value_str in zip(field_strs, value_strs, strict=True)]) | ||
| return path | ||
|
|
||
| def check_compatible(self, schema: Schema, allow_missing_fields: bool = False) -> None: | ||
| # if the underlying field is dropped, we cannot check they are compatible -- continue | ||
| schema_fields = schema._lazy_id_to_field | ||
| parents = schema._lazy_id_to_parent | ||
|
|
||
| for field in self.fields: | ||
| source_field = schema_fields.get(field.source_id) | ||
|
|
||
| if allow_missing_fields and source_field is None: | ||
| continue | ||
|
|
||
| if isinstance(field.transform, VoidTransform): | ||
| continue | ||
|
|
||
| if not source_field: | ||
| raise ValidationError(f"Cannot find source column for partition field: {field}") | ||
|
|
||
| source_type = source_field.field_type | ||
| if not source_type.is_primitive: | ||
| raise ValidationError(f"Cannot partition by non-primitive source field: {source_field}") | ||
| if not field.transform.can_transform(source_type): | ||
| raise ValidationError( | ||
| f"Invalid source field {source_field.name} with type {source_type} " + f"for transform: {field.transform}" | ||
| ) | ||
|
|
||
| # The only valid parent types for a PartitionField are StructTypes. This must be checked recursively | ||
| parent_id = parents.get(field.source_id) | ||
| while parent_id: | ||
| parent_type = schema.find_type(parent_id) | ||
| if not parent_type.is_struct: | ||
| raise ValidationError(f"Invalid partition field parent: {parent_type}") | ||
|
Contributor
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. maybe a bit more info here too |
||
| parent_id = parents.get(parent_id) | ||
|
|
||
|
|
||
| UNPARTITIONED_PARTITION_SPEC = PartitionSpec(spec_id=0) | ||
|
|
||
|
|
||
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
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
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.
nit: doesnt look like
allow_missing_fieldsis used anywhere, should we still keep it?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.
check_compatible in Java its only used with
allowMissingField=true(ctx) when reading metadata tables. Since here we only use this check (for now) at write path only, I think we could remove this field.