You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@iceberg.apache.org by GitBox <gi...@apache.org> on 2022/02/06 22:33:23 UTC

[GitHub] [iceberg] rdblue commented on a change in pull request #3988: Python: Add Decimal type conversion

rdblue commented on a change in pull request #3988:
URL: https://github.com/apache/iceberg/pull/3988#discussion_r800242361



##########
File path: python_legacy/tests/api/test_conversions.py
##########
@@ -79,3 +87,9 @@ def test_to_bytes(self):
                          Literal.of(uuid.UUID("f79c3e09-677c-4bbd-a479-3f349cb785e7")).to_byte_buffer())
         self.assertEqual(b'foo', Literal.of(bytes(b'foo')).to_byte_buffer())
         self.assertEqual(b'foo', Literal.of(bytearray(b'foo')).to_byte_buffer())
+        # Decimal on 2-bytes
+        self.assertEqual(b'\x30\x39', Literal.of(123.45).to(DecimalType.of(5, 2)).to_byte_buffer())
+        # Decimal on 3-bytes to test that we use the minimum number of bytes
+        self.assertEqual(b'\x12\xd6\x87', Literal.of(123.4567).to(DecimalType.of(7, 4)).to_byte_buffer())
+        # Negative decimal to test two's complement
+        self.assertEqual(b'\xed\x29\x79', Literal.of(-123.4567).to(DecimalType.of(7, 4)).to_byte_buffer())

Review comment:
       Can you make sure the test cases are shared between the Java implementation and here? There's a test for Java in `TestConversions` but it would be good to add these cases and ensure that they match. I'd also like to have a case that requires an empty byte, like `Literal.of(0.11).to(DecimalType.of(10, 2)).to_byte_buffer()`, as well as one for negative numbers.




-- 
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: issues-unsubscribe@iceberg.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For additional commands, e-mail: issues-help@iceberg.apache.org