jackylee-ch commented on code in PR #4371:
URL: https://github.com/apache/iceberg-python/pull/4371#discussion_r4598835386
##########
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:
`dec <= 5e-3` binds to `dec <= 0.01` (and `dec = 1e-3` to `dec = 0.00`)
because `DoubleLiteral.to(DecimalType)` rounds half-up to the column scale, so
a 0.01 row matches a 0.005 bound. Should exponent forms on a decimal column
fail on a scale mismatch like `DecimalLiteral` does, and can this case get a
test?
--
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]