Skip to content

Commit a30b7e9

Browse files
committed
add test
1 parent 2de947a commit a30b7e9

2 files changed

Lines changed: 31 additions & 1 deletion

File tree

pyiceberg/io/pyarrow.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2090,7 +2090,7 @@ def __init__(self, iceberg_type: PrimitiveType, physical_type_string: str, trunc
20902090
):
20912091
pass
20922092
# Allow DECIMAL to be stored as FIXED_LEN_BYTE_ARRAY
2093-
if (physical_type_string == "FIXED_LEN_BYTE_ARRAY" and expected_physical_type in ("INT32", "INT64")):
2093+
elif physical_type_string == "FIXED_LEN_BYTE_ARRAY" and expected_physical_type in ("INT32", "INT64"):
20942094
pass
20952095
else:
20962096
raise ValueError(

tests/io/test_pyarrow.py

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2188,6 +2188,36 @@ def test_stats_aggregator_update_max(vals: List[Any], primitive_type: PrimitiveT
21882188
assert stats.current_max == expected_result
21892189

21902190

2191+
@pytest.mark.parametrize(
2192+
"iceberg_type, physical_type_string, should_succeed",
2193+
[
2194+
# Exact match
2195+
(IntegerType(), "INT32", True),
2196+
# Allowed INT32 -> INT64 promotion
2197+
(LongType(), "INT32", True),
2198+
# Allowed FLOAT -> DOUBLE promotion
2199+
(DoubleType(), "FLOAT", True),
2200+
# Allowed FIXED_LEN_BYTE_ARRAY -> INT32
2201+
(DecimalType(precision=2, scale=2), "FIXED_LEN_BYTE_ARRAY", True),
2202+
# Allowed FIXED_LEN_BYTE_ARRAY -> INT64
2203+
(DecimalType(precision=12, scale=2), "FIXED_LEN_BYTE_ARRAY", True),
2204+
# Fail case: INT64 cannot be cast to INT32
2205+
(IntegerType(), "INT64", False),
2206+
],
2207+
)
2208+
def test_stats_aggregator_conditionally_allowed_types(
2209+
iceberg_type: PrimitiveType, physical_type_string: str, should_succeed: bool
2210+
) -> None:
2211+
if should_succeed:
2212+
stats = StatsAggregator(iceberg_type, physical_type_string)
2213+
assert stats.primitive_type == iceberg_type
2214+
assert stats.current_min is None
2215+
assert stats.current_max is None
2216+
else:
2217+
with pytest.raises(ValueError, match="Unexpected physical type"):
2218+
StatsAggregator(iceberg_type, physical_type_string)
2219+
2220+
21912221
def test_bin_pack_arrow_table(arrow_table_with_null: pa.Table) -> None:
21922222
# default packs to 1 bin since the table is small
21932223
bin_packed = bin_pack_arrow_table(

0 commit comments

Comments
 (0)