rdblue commented on code in PR #5030:
URL: https://github.com/apache/iceberg/pull/5030#discussion_r907885385
##########
python/tests/test_transforms.py:
##########
@@ -177,6 +177,61 @@ def test_identity_method(type_var):
assert identity_transform.apply("test") == "test"
[email protected]("type_var", [IntegerType(), LongType()])
[email protected](
+ "input_var,expected",
+ [(1, 0), (5, 0), (9, 0), (10, 10), (11, 10), (-1, -10), (-10, -10), (-12,
-20)],
+)
+def test_truncate_integer(type_var, input_var, expected):
+ trunc = transforms.truncate(type_var, 10)
+ assert trunc.apply(input_var) == expected
+
+
[email protected](
+ "input_var,expected",
+ [
+ (Decimal("12.34"), Decimal("12.30")),
+ (Decimal("12.30"), Decimal("12.30")),
+ (Decimal("12.29"), Decimal("12.20")),
+ (Decimal("0.05"), Decimal("0.00")),
+ (Decimal("-0.05"), Decimal("-0.10")),
+ ],
+)
+def test_truncate_decimal(input_var, expected):
+ trunc = transforms.truncate(DecimalType(9, 2), 10)
+ assert trunc.apply(input_var) == expected
+
+
[email protected]("input_var,expected", [("abcdefg", "abcde"), ("abc",
"abc")])
+def test_truncate_string(input_var, expected):
+ trunc = transforms.truncate(StringType(), 5)
+ assert trunc.apply(input_var) == expected
+
+
[email protected](
+ "type_var,value,expected_human_str,expected",
+ [
+ (BinaryType(), b"\x00\x01\x02\x03", "AAECAw==", b"\x00"),
Review Comment:
This should include the test cases I posted in comments above to validate
that a `bytes` is truncated by the number of bytes and `str` is truncated by
the number of unicode code points.
--
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]