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


##########
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:
   How do you feel about:
   ```python
       def increment(self) -> Literal[Decimal]:
           inc_value = 1 / (10 ** abs(self.value.as_tuple().exponent))
           return DecimalLiteral(self.value + Decimal(str(inc_value)))
   
       def decrement(self) -> Literal[Decimal]:
           inc_value = 1 / (10 ** abs(self.value.as_tuple().exponent))
           return DecimalLiteral(self.value - Decimal(str(inc_value)))
   ```
   Added tests as well:
   ```python
   def test_decimal_literal_increment():
       dec = DecimalLiteral(Decimal('10.123'))
       # Twice to check that we don't mutate the value
       assert dec.increment() == DecimalLiteral(Decimal('10.124'))
       assert dec.increment() == DecimalLiteral(Decimal('10.124'))
       # To check that the scale is still the same
       assert dec.increment().value.as_tuple() == Decimal('10.124').as_tuple()
   
   def test_decimal_literal_dencrement():
       dec = DecimalLiteral(Decimal('10.123'))
       # Twice to check that we don't mutate the value
       assert dec.decrement() == DecimalLiteral(Decimal('10.122'))
       assert dec.decrement() == DecimalLiteral(Decimal('10.122'))
       # To check that the scale is still the same
       assert dec.decrement().value.as_tuple() == Decimal('10.122').as_tuple()
   ```



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