rdblue commented on code in PR #6128:
URL: https://github.com/apache/iceberg/pull/6128#discussion_r1022188092


##########
python/pyiceberg/expressions/literals.py:
##########
@@ -376,6 +407,12 @@ class DecimalLiteral(Literal[Decimal]):
     def __init__(self, value: Decimal):
         super().__init__(value, Decimal)
 
+    def increment(self) -> DecimalLiteral:
+        return DecimalLiteral(self.value + 1)

Review Comment:
   We actually want to increment by the smallest amount possible, since what is 
actually happening is adjusting the boundary to closed rather than actually 
incrementing. That is, `literal("12.34").to(DecimalType(9, 2).increment())` 
should result in `12.35`, not `13.35`.
   
   We do this in Java by converting to the unscaled value, incrementing, and 
then converting back. I think we should do the same thing here:
   
   ```
   def increment_unscaled(d: Decimal):
       (_, _, original_scale) = d.to_tuple()
       unscaled = decimal_to_unscaled(self.value) + 1
       return unscaled_to_decimal(unscaled, original_scale)
   ```



-- 
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]

Reply via email to