rahulsmahadev commented on code in PR #4371:
URL: https://github.com/apache/iceberg-python/pull/4371#discussion_r4762984586


##########
tests/expressions/test_parser.py:
##########
@@ -146,6 +149,62 @@ def test_not_in_different_types() -> None:
         parser.parse("foo not in (5, 'a')")
 
 
+def test_in_mixed_numbers() -> None:
+    for values in ("5, 6.5", "6.5, 5"):
+        result = parser.parse(f"foo in ({values})")
+        assert result == In("foo", {LongLiteral(5), 
DecimalLiteral(Decimal("6.5"))}), values
+        assert isinstance(result, In)
+        assert {type(value) for value in result.literals} == {LongLiteral, 
DecimalLiteral}, values
+
+    result = parser.parse("foo not in (5, 6.5, 1e3)")
+    assert result == NotIn("foo", {LongLiteral(5), 
DecimalLiteral(Decimal("6.5")), DoubleLiteral(1000.0)})
+    assert isinstance(result, NotIn)
+    assert {type(value) for value in result.literals} == {LongLiteral, 
DecimalLiteral, DoubleLiteral}
+
+
+def test_scientific_notation() -> None:
+    # A number with an exponent is a double, as in ANSI SQL
+    for expression, expected in [
+        ("foo > 1e-3", GreaterThan("foo", 0.001)),
+        ("1e-3 < foo", GreaterThan("foo", 0.001)),
+        ("foo < -1.5E3", LessThan("foo", -1500.0)),
+        ("foo = 2e2", EqualTo("foo", 200.0)),
+        ("foo = .5e1", EqualTo("foo", 5.0)),
+    ]:
+        result = parser.parse(expression)
+        assert result == expected, expression
+        assert isinstance(result.literal, DoubleLiteral), expression
+
+    assert And(GreaterThanOrEqual("foo", 10.0), LessThanOrEqual("foo", 25.0)) 
== parser.parse("foo between 1e1 and 2.5e1")
+
+
+def test_bind_numeric_literals() -> None:
+    schema = Schema(
+        NestedField(1, "dec", DecimalType(9, 2), required=False),
+        NestedField(2, "lng", LongType(), required=False),
+        NestedField(3, "dbl", DoubleType(), required=False),
+    )
+    for expression, expected in [
+        ("dec = 1e3", DecimalLiteral(Decimal("1000.00"))),
+        ("dec > 2.5e-1", DecimalLiteral(Decimal("0.25"))),

Review Comment:
   I kept the half-up rounding, since it matches Java's 
`DoubleLiteral.to(DECIMAL)` and what `LessThanOrEqual("dec", 0.005)` already 
does on main. Failing on a scale mismatch would also change that expression API 
for Python floats, so I'd do it in a separate PR if we want it. 
`test_bind_numeric_literals` now checks that `dec <= 5e-3` binds as `dec <= 
0.01` (b1572b37).
   



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