-
-
Notifications
You must be signed in to change notification settings - Fork 316
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
Backend filtering refactor #837
Backend filtering refactor #837
Conversation
Also includes implementation for converting to SA filter spec.
Apparently dataclass defaults don't carry over from mixins.
I was wrong. Apparently I just got the order of mixin application wrong.
There's nothing faux about it.
@dmos62 I see that you're working off of a fork still, you have write access to the repo now so I recommend switching to a branch instead. |
At the moment possible predicates are exposed in the REST API like this:
|
Couple of quick comments:
|
@kgodey thanks for noticing the casing conflict. I'm using the tree abstraction for predicates. The
|
I figured that out, I meant specifically that the "super type" nomenclature is a little confusing, if I was just paying attention to the key names, seems like it's a superset of the "type" key somehow (which it's not). Is there a more obvious name for it? Or are you using some standard set of names derived from something else? |
db/filters/base.py
Outdated
|
||
def not_empty(l): return len(l) > 0 | ||
|
||
def assertPredicateCorrect(predicate): |
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.
@dmos62 we use snake case for Python functions and variables too. We only use camel case (capitalized) for class names.
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.
Fixed it. Thanks for pointing that out.
I'm open to suggestions. Calling it a parent type would have a similar meaning. That's pretty much talking about the underlying class/mixin hierarchy. We could also have nomenclature that talks about predicate names (e.g. empty, greater, and) and positions in predicate trees (leaf or branch). |
API users will probably not know or care about how it's implemented, I think the nomenclature should prioritize API readability.
I like this. How about |
Since @mathemancer is still making changes on the dependency PR (#862), I'll hold off on merging it into this one. |
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'll review this more detail later.
Have we decided on using dataclasses and typing in our codebase? |
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.
First pass review. I'll be more precise once this is more stabilized. However, I have some broader comments to make. Overall, I really like the tree concept. I do think there's a false dichotomy introduced; there are branches and leaves, but you can't assume that an "and" is a branch (since it could be an "and" between two boolean columns). I.e., the dichotomy isn't between types exactly.
My biggest concern is the specificity. I really think we need to take a try and see what happens approach to some of these things, rather than trying to check everything beforehand. Let the DB tell you if a given proposition makes no sense, and handle the error. This will be more flexible, and avoid having to define things in multiple places. Long run, I really think it'll be easier to maintain that way. For example, avoiding specifying branch vs. leaf is more flexible for composition. I acknowledge that it would sometimes run into issues, but that can be handled by really good feedback and errors.
Final note for this round: we need to come to some kind of team-wide agreement about type hints (and by implication dataclasses). I'm ambivalent on these issues, but I suspect I'm the only one.
I think we should take the discussion about dataclasses and type hints to a GitHub discussion so as to not clutter up this PR. @dmos62, I think it would make sense for you to start this. |
@dmos62 This is a large PR. I think it would help me review the code if you could do a write up of the changes. Topics I think would be useful:
I'm having a hard time grokking the code because it doesn't seem Pythonic somehow. That's probably not useful but I can't articulate any more specifics, I'm hoping reading through your explanation will help me either understand the code or articulate why it's hard for me to understand. |
WriteupI'm collapsing this write-up; please see its copy-pasted (and possibly updated) version on the initial post of the new thread for this PR. Collapsed### FeaturesNotice that I might use the terms filter specification and predicate interchangeably. Some of the things this new predicate data structure does is:
What it does not (currently) do:
Technical detailsI organized the relevant pieces in the predicate data structure into a mixin hierarchy and also used this PR as a testbed for frozen dataclasses. Some of my objectives with the basic structure were:
How to extend with new predicate
@frozen_dataclass
class Greater(ReliesOnComparability, SingleParameter, Leaf):
type: LeafPredicateType = static(LeafPredicateType.GREATER)
name: str = static("Greater")
def to_sa_filter(self):
return column(self.column) > self.parameter
def _is_ma_type_comparable(ma_type: MathesarTypeIdentifier) -> bool:
return ma_type in comparable_mathesar_types
def is_ma_type_supported_by_predicate(ma_type: MathesarTypeIdentifier, predicate: Type[Predicate]):
if relies_on_comparability(predicate):
return _is_ma_type_comparable(ma_type)
else:
return True Notice that
|
Fixes #385, fixes #846
Sets up the backend infrastructure for filtering.
Technical details
Uses our fork of
sqlalchemy-filters
.Checklist
Update index.md
).master
branch of the repositoryvisible errors.
My TODO
Developer Certificate of Origin
Developer Certificate of Origin