From b368a86bb6acb3e2b0515c934a264da8dcff9dc6 Mon Sep 17 00:00:00 2001 From: Daniel Weeks Date: Sat, 21 Oct 2023 11:54:44 -0700 Subject: [PATCH 1/3] Require full expression parse match --- pyiceberg/expressions/parser.py | 2 +- tests/expressions/test_parser.py | 5 +++++ 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/pyiceberg/expressions/parser.py b/pyiceberg/expressions/parser.py index d6d5bdb794..6b3eba91ac 100644 --- a/pyiceberg/expressions/parser.py +++ b/pyiceberg/expressions/parser.py @@ -252,4 +252,4 @@ def handle_or(result: ParseResults) -> Or: def parse(expr: str) -> BooleanExpression: """Parse a boolean expression.""" - return boolean_expression.parse_string(expr)[0] + return boolean_expression.parse_string(expr, parse_all=True)[0] diff --git a/tests/expressions/test_parser.py b/tests/expressions/test_parser.py index f4bebca066..7bc9c5e5be 100644 --- a/tests/expressions/test_parser.py +++ b/tests/expressions/test_parser.py @@ -166,3 +166,8 @@ def test_starts_with() -> None: def test_not_starts_with() -> None: assert NotStartsWith("foo", "data") == parser.parse("foo NOT LIKE 'data'") + + +def test_with_function() -> None: + with pytest.raises(ParseException): + parser.parse("foo = 1 and lower(bar) = '2") \ No newline at end of file From 4a0c32e625018f6f90d98618c9623965ea26b9f5 Mon Sep 17 00:00:00 2001 From: Daniel Weeks Date: Sat, 21 Oct 2023 11:56:14 -0700 Subject: [PATCH 2/3] Codestyle --- tests/expressions/test_parser.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/expressions/test_parser.py b/tests/expressions/test_parser.py index 7bc9c5e5be..bd0cdd2ec4 100644 --- a/tests/expressions/test_parser.py +++ b/tests/expressions/test_parser.py @@ -170,4 +170,4 @@ def test_not_starts_with() -> None: def test_with_function() -> None: with pytest.raises(ParseException): - parser.parse("foo = 1 and lower(bar) = '2") \ No newline at end of file + parser.parse("foo = 1 and lower(bar) = '2") From 748ce387545ef592030a6a9f62150d5d514ff3b7 Mon Sep 17 00:00:00 2001 From: Daniel Weeks Date: Sat, 21 Oct 2023 12:47:41 -0700 Subject: [PATCH 3/3] Update tests/expressions/test_parser.py Co-authored-by: Fokko Driesprong --- tests/expressions/test_parser.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/tests/expressions/test_parser.py b/tests/expressions/test_parser.py index bd0cdd2ec4..fdfdcf55fc 100644 --- a/tests/expressions/test_parser.py +++ b/tests/expressions/test_parser.py @@ -169,5 +169,7 @@ def test_not_starts_with() -> None: def test_with_function() -> None: - with pytest.raises(ParseException): - parser.parse("foo = 1 and lower(bar) = '2") + with pytest.raises(ParseException) as exc_info: + parser.parse("foo = 1 and lower(bar) = '2'") + + assert "Expected end of text, found 'and'" in str(exc_info)