maxdebayser commented on code in PR #7831:
URL: https://github.com/apache/iceberg/pull/7831#discussion_r1267112518
##########
python/pyiceberg/io/pyarrow.py:
##########
@@ -1013,3 +1025,271 @@ def map_key_partner(self, partner_map:
Optional[pa.Array]) -> Optional[pa.Array]
def map_value_partner(self, partner_map: Optional[pa.Array]) ->
Optional[pa.Array]:
return partner_map.items if isinstance(partner_map, pa.MapArray) else
None
+
+
+class StatsAggregator:
+ def __init__(self, type_string: str, trunc_length: Optional[int] = None)
-> None:
+ self.current_min: Any = None
+ self.current_max: Any = None
+ self.trunc_length = trunc_length
+ self.primitive_type: Optional[PrimitiveType] = None
+
+ if type_string == "BOOLEAN":
+ self.primitive_type = BooleanType()
+ elif type_string == "INT32":
+ self.primitive_type = IntegerType()
+ elif type_string == "INT64":
+ self.primitive_type = LongType()
+ elif type_string == "INT96":
+ raise NotImplementedError("Statistics not implemented for INT96
physical type")
+ elif type_string == "FLOAT":
+ self.primitive_type = FloatType()
+ elif type_string == "DOUBLE":
+ self.primitive_type = DoubleType()
+ elif type_string == "BYTE_ARRAY":
+ self.primitive_type = BinaryType()
+ elif type_string == "FIXED_LEN_BYTE_ARRAY":
+ self.primitive_type = BinaryType()
+ else:
+ raise AssertionError(f"Unknown physical type {type_string}")
+
+ def serialize(self, value: Any) -> bytes:
+ if type(value) == str:
+ value = value.encode()
+ assert self.primitive_type is not None # appease mypy
+ return to_bytes(self.primitive_type, value)
+
+ def add_min(self, val: Any) -> None:
+ if self.current_min is None:
+ self.current_min = val
+ else:
+ self.current_min = min(val, self.current_min)
+
+ def add_max(self, val: Any) -> None:
+ if self.current_max is None:
+ self.current_max = val
+ else:
+ self.current_max = max(self.current_max, val)
+
+ def get_min(self) -> bytes:
+ return self.serialize(self.current_min)[: self.trunc_length]
+
+ def get_max(self) -> bytes:
+ return self.serialize(self.current_max)[: self.trunc_length]
Review Comment:
Thanks for pointing that out. I've just read the UnicodeUtil code and it
seems to me that the truncation length there is interpreted as length in
characters and not in bytes. Is that understanding correct?
And should primitive types be truncated at all? I don't think it makes a lot
of sense.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]