cccs-eric commented on a change in pull request #4263:
URL: https://github.com/apache/iceberg/pull/4263#discussion_r826131533



##########
File path: python/tests/test_conversions.py
##########
@@ -0,0 +1,329 @@
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements.  See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership.  The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License.  You may obtain a copy of the License at
+#
+#   http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied.  See the License for the
+# specific language governing permissions and limitations
+# under the License.
+
+import uuid
+from decimal import Decimal
+
+import pytest
+
+from iceberg import conversions
+from iceberg.types import (
+    BinaryType,
+    BooleanType,
+    DateType,
+    DecimalType,
+    DoubleType,
+    FixedType,
+    FloatType,
+    IntegerType,
+    LongType,
+    StringType,
+    TimestampType,
+    TimestamptzType,
+    TimeType,
+    UUIDType,
+)
+
+
[email protected](
+    "primitive_type, partition_value_as_str, expected_result",
+    [
+        (BooleanType(), "true", True),
+        (BooleanType(), "false", False),
+        (BooleanType(), "TRUE", True),
+        (BooleanType(), "FALSE", False),
+        (BooleanType(), None, False),
+        (IntegerType(), "1", 1),
+        (IntegerType(), "9999", 9999),
+        (LongType(), "123456789", 123456789),
+        (FloatType(), "1.1", 1.1),
+        (DoubleType(), "99999.9", 99999.9),
+        (DecimalType(5, 2), "123.45", Decimal("123.45")),
+        (StringType(), "foo", "foo"),
+        (UUIDType(), "f79c3e09-677c-4bbd-a479-3f349cb785e7", 
uuid.UUID("f79c3e09-677c-4bbd-a479-3f349cb785e7")),
+        (FixedType(3), "foo", bytearray(b"foo")),
+        (BinaryType(), "foo", b"foo"),
+        (None, None, None),
+    ],
+)
+def test_from_partition_value_to_py(primitive_type, partition_value_as_str, 
expected_result):
+    """Test converting a partition value to a python built-in"""
+    assert conversions.from_partition_value_to_py(primitive_type, 
partition_value_as_str) == expected_result
+
+
[email protected](
+    "primitive_type, b, result",
+    [
+        (BooleanType(), b"\x00", False),
+        (BooleanType(), b"\x01", True),
+        (IntegerType(), b"\xd2\x04\x00\x00", 1234),
+        (LongType(), b"\xd2\x04\x00\x00\x00\x00\x00\x00", 1234),
+        (DoubleType(), b"\x8d\x97\x6e\x12\x83\xc0\xf3\x3f", 1.2345),
+        (DateType(), b"\xd2\x04\x00\x00", 1234),
+        (TimeType(), b"\x00\xe8vH\x17\x00\x00\x00", 100000000000),
+        (TimestamptzType(), b"\x00\xe8vH\x17\x00\x00\x00", 100000000000),
+        (TimestampType(), b"\x00\xe8vH\x17\x00\x00\x00", 100000000000),
+        (StringType(), b"foo", "foo"),
+        (UUIDType(), b"\xf7\x9c>\tg|K\xbd\xa4y?4\x9c\xb7\x85\xe7", 
uuid.UUID("f79c3e09-677c-4bbd-a479-3f349cb785e7")),
+        (FixedType(3), b"foo", b"foo"),
+        (BinaryType(), b"foo", b"foo"),
+        (DecimalType(5, 2), b"\x30\x39", Decimal("123.45")),
+        (DecimalType(7, 4), b"\x00\x12\xd6\x87", Decimal("123.4567")),

Review comment:
       Suggestion: when I migrated the Java tests to python_legacy, I really 
appreciated the [test 
comments](https://github.com/apache/iceberg/blob/master/python_legacy/tests/api/test_conversions.py#L205)
 as it helped me understand what I was actually testing.  For some tests, it 
might not always be obvious.  For example, the test with `Decimal("123.4567")` 
is not a random value, but a value that stored on 3 bytes, which is not a power 
of 2 (which is usually used for int/long, etc...).  The Iceberg spec states to 
use the minimum number of bytes to store the value.  
   
   It doesn't add value to the code, but it can be very helpful for a new dev 
when things go sideways...  Again, just a suggestion since I found it useful 
when I had to play in that code.




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