Skip to content
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

Test transform function consistency for all transforms #1573

Merged
merged 2 commits into from
Jan 30, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 28 additions & 4 deletions tests/table/test_partitioning.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,15 @@

from pyiceberg.partitioning import UNPARTITIONED_PARTITION_SPEC, PartitionField, PartitionSpec
from pyiceberg.schema import Schema
from pyiceberg.transforms import BucketTransform, IdentityTransform, TruncateTransform
from pyiceberg.transforms import (
BucketTransform,
DayTransform,
HourTransform,
IdentityTransform,
MonthTransform,
TruncateTransform,
YearTransform,
)
from pyiceberg.typedef import Record
from pyiceberg.types import (
BinaryType,
Expand Down Expand Up @@ -186,11 +194,27 @@ def test_partition_type(table_schema_simple: Schema) -> None:
(BinaryType(), b"\x8e\xd1\x87\x01"),
],
)
def test_bucketing_function(source_type: PrimitiveType, value: Any) -> None:
bucket = BucketTransform(2) # type: ignore
def test_transform_consistency_with_pyarrow_transform(source_type: PrimitiveType, value: Any) -> None:
import pyarrow as pa

assert bucket.transform(source_type)(value) == bucket.pyarrow_transform(source_type)(pa.array([value])).to_pylist()[0]
all_transforms = [ # type: ignore
IdentityTransform(),
BucketTransform(10),
TruncateTransform(10),
YearTransform(),
MonthTransform(),
DayTransform(),
HourTransform(),
]
for t in all_transforms:
if t.can_transform(source_type):
try:
assert t.transform(source_type)(value) == t.pyarrow_transform(source_type)(pa.array([value])).to_pylist()[0]
except ValueError as e:
# Skipping unsupported feature
if "FeatureUnsupported => Unsupported data type for truncate transform" in str(e):
Copy link
Contributor

Choose a reason for hiding this comment

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

This feels contradictive, since it passes t.can_transform

Copy link
Contributor Author

Choose a reason for hiding this comment

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

yea good point, let me dig into this a little more, i think the main error comes from rust

Copy link
Contributor

Choose a reason for hiding this comment

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

Looks like binary is not supported: apache/iceberg-rust#920

continue
raise


def test_deserialize_partition_field_v2() -> None:
Expand Down