-
Notifications
You must be signed in to change notification settings - Fork 3k
Python: Add boolean expression parser #6259
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
Conversation
| assert And(NotNull("x"), Or(LessThan("x", 5), GreaterThan("x", 10))) == parser.parse("x is not null and (x < 5 or 10 < x)") | ||
| assert Or(IsNull("x"), And(GreaterThanOrEqual("x", 5), Not(LessThan("x", 10)))) == parser.parse( | ||
| "(x is null) or (5 <= x) and not(x < 10)" | ||
| ) |
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 verified that the result of these complex cases matches Spark.
Fokko
left a comment
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.
Some cosmetic changes, but apart from that it looks great. I think this is a great addition to the library
| return hash(self.value) | ||
|
|
||
| def __eq__(self, other: Any) -> bool: | ||
| if not isinstance(other, Literal): |
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.
If we get something else, we could wrap it in a literal and compare it. This would allow literal(1) == 1.
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 don't think that we want to do that. Then equality would not be symmetric.
| return GreaterThanOrEqual(result.column, result.literal) | ||
| if result.op in ("=", "=="): | ||
| return EqualTo(result.column, result.literal) | ||
| if result.op in ("!=", "<>"): |
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.
| if result.op in ("!=", "<>"): | |
| elif result.op in ("!=", "<>"): |
Co-authored-by: Fokko Driesprong <fokko@apache.org>
Co-authored-by: Fokko Driesprong <fokko@apache.org>
Co-authored-by: Fokko Driesprong <fokko@apache.org>
|
Merged. Thanks for reviewing, @Fokko! |
This adds a simple expression parser based on pyparsing.