rdblue commented on code in PR #5030:
URL: https://github.com/apache/iceberg/pull/5030#discussion_r896940204
##########
python/src/iceberg/utils/decimal.py:
##########
@@ -75,3 +75,16 @@ def decimal_to_bytes(value: Decimal) -> bytes:
"""
unscaled_value = decimal_to_unscaled(value)
return unscaled_value.to_bytes(bytes_required(unscaled_value),
byteorder="big", signed=True)
+
+
+def truncate_decimal(value: Decimal, width: int) -> Decimal:
+ """Get a truncated Decimal value given a decimal value and a width
+ Args:
+ value (Decimal): a decimal value
+ width (int): A width for the returned Decimal instance
+ Returns:
+ Decimal: A truncated Decimal instance
+ """
+ unscaled_value = decimal_to_unscaled(value)
+ applied_value = unscaled_value - (((unscaled_value % width) + width) %
width)
+ return Decimal(f"{applied_value}e{value.as_tuple().exponent}")
Review Comment:
This should create a decimal from the truncated unscaled value, rather than
parsing.
--
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]