-
Notifications
You must be signed in to change notification settings - Fork 202
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Update like statements to reflect sql behaviors #91
Merged
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
9da77de
Update like statements to reflect sql behaciors
danielcweeks f07e21f
Codestyle
danielcweeks 94b7354
Codestyle
danielcweeks d36c82a
Handle NotStartsWith
danielcweeks cf7087c
Update pyiceberg/expressions/parser.py
danielcweeks 4794b60
Update tests/expressions/test_parser.py
danielcweeks File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -168,12 +168,30 @@ def test_multiple_and_or() -> None: | |
) == parser.parse("foo is not null and foo < 5 or (foo > 10 and foo < 100 and bar is null)") | ||
|
||
|
||
def test_like_equality() -> None: | ||
assert EqualTo("foo", "data") == parser.parse("foo LIKE 'data'") | ||
assert EqualTo("foo", "data%") == parser.parse("foo LIKE 'data\\%'") | ||
|
||
|
||
def test_starts_with() -> None: | ||
assert StartsWith("foo", "data") == parser.parse("foo LIKE 'data'") | ||
assert StartsWith("foo", "data") == parser.parse("foo LIKE 'data%'") | ||
assert StartsWith("foo", "some % data") == parser.parse("foo LIKE 'some \\% data%'") | ||
assert StartsWith("foo", "some data%") == parser.parse("foo LIKE 'some data\\%%'") | ||
|
||
|
||
def test_invalid_likes() -> None: | ||
invalid_statements = ["foo LIKE '%data%'", "foo LIKE 'da%ta'", "foo LIKE '%data'"] | ||
|
||
for statement in invalid_statements: | ||
with pytest.raises(ValueError) as exc_info: | ||
parser.parse(statement) | ||
|
||
assert "LIKE expressions only supports wildcard, '%', at the end of a string" in str(exc_info) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nice one, this was one of my concerns 👍 |
||
|
||
|
||
def test_not_starts_with() -> None: | ||
assert NotStartsWith("foo", "data") == parser.parse("foo NOT LIKE 'data'") | ||
assert NotEqualTo("foo", "data") == parser.parse("foo NOT LIKE 'data'") | ||
assert NotStartsWith("foo", "data") == parser.parse("foo NOT LIKE 'data%'") | ||
|
||
|
||
def test_with_function() -> None: | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
My first choice would not be a regex, but it works well 👍
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I didn't want to complicate the parser, so this seemed like the most straightforward path.