-
Notifications
You must be signed in to change notification settings - Fork 2.1k
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
Python: Allow to pass in a string as filter #6657
Conversation
Often I have to look up the exact of the operator, I think it would be nice to allow the end user to provide a string that we'll parse with the excellent parser that we already have.
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.
Just a nit comment, overall this makes sense to me, it would be really nice to just pass in a string predicate. Thanks @Fokko !
python/pyiceberg/table/__init__.py
Outdated
if row_filter is None: | ||
self.row_filter = AlwaysTrue() | ||
else: | ||
self.row_filter = parser.parse(row_filter) |
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.
Nit: Maybe we could use a ternary operator here?
self.row_filter = parser.parse(row_filter) if row_filter else AlwaysTrue()
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.
Good suggestion, I've split it into a separate method for now, that also takes care of the parsing.
@@ -232,6 +233,9 @@ def handle_or(result: ParseResults) -> Or: | |||
).set_name("expr") | |||
|
|||
|
|||
def parse(expr: str) -> BooleanExpression: | |||
def parse(expr: Union[str, BooleanExpression]) -> BooleanExpression: |
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 can see why you'd do this, but it seems better to make the caller check before calling parse
. It's a bit confusing to accept an expression here and do nothing.
Thanks for the update, @Fokko! Looks good now so I merged. |
Often I have to look up the name of the operator, I think it would be nice to allow the end user to provide a string that we'll parse with the excellent parser that we already have.
Works both: