@@ -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+
21912221def 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