-
Notifications
You must be signed in to change notification settings - Fork 194
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
Implement column projection #1443
base: main
Are you sure you want to change the base?
Conversation
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.
Added a few comments, please take a look! The PR looks great already. Thanks for working on this!
…tion logic to helper method, changed test to use high-level table scan
file: DataFile, | ||
projected_schema: Schema, | ||
projected_field_ids: Set[int], | ||
file_project_schema: Schema, |
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.
Since we only need the IDs, I'd rather just pass in those for clarity:
file_project_schema: Schema, | |
file_project_schema: Set[int], |
if partition_spec is not None: | ||
for partition_field in partition_spec.fields_by_source_id(field_id): | ||
if isinstance(partition_field.transform, IdentityTransform) and partition_field.name in file.partition.__dict__: | ||
projected_missing_fields[partition_field.name] = file.partition.__dict__[partition_field.name] |
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.
This is my mistake, the lookup should never be done by name, but by field-id
. I've added the lookup by name to the record, but this should not be used outside of tests.
Instead, we want to create a lookup table from the field:
iceberg-python/pyiceberg/schema.py
Lines 1224 to 1233 in e646500
def build_position_accessors(schema_or_type: Union[Schema, IcebergType]) -> Dict[int, Accessor]: | |
"""Generate an index of field IDs to schema position accessors. | |
Args: | |
schema_or_type (Union[Schema, IcebergType]): A schema or type to index. | |
Returns: | |
Dict[int, Accessor]: An index of field IDs to accessors. | |
""" | |
return visit(schema_or_type, _BuildPositionAccessors()) |
It should be used something like:
accessors = build_position_accessors(table_schema)
projected_missing_fields[partition_field.name] = record[accessors[partition_field.field_id]]
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.
Thanks for the input! thats right, the partition field shouldn't be accessed with the name. But, if I'm understanding correctly, the partition record position in the manifest file is not the same as the position of the field in the schema.
For example, lets say I have this schema
schema {
1 field1: string
2 partition_field: int
}
And a DataFile like this:
DataFile {
...
partition: Record(partittion_field: 1)
...
}
Running build_position_accessor with the schema
defined earlier will result in:
{
1: Accessor(position=0,inner=None),
2: Accessor(position=1,inner=None),
}
Then, doing accessor[partition_field.id]
will result in Accessor(position=1,inner=None)
but the partition record in the manifest would be in position 0.
This is a fix for issue #1401. In which table scans needed to infer partition column by following the column projection rules
Fixes #1401