Extending the filtering API #848
Replies: 2 comments 4 replies
-
@dmos62 I don't think we can use For eg., In
This is the current modal I've been implementing on the frontend: {
...,
[DB_TYPES.Char]: {
category: ABSTRACT_TYPE_CATEGORIES.Text,
input: { type: 'string' },
validation: {
method: 'length',
op: 'lte',
value: 255,
}
},
...,
[DB_TYPES.MATHESAR.Email]: {
category: ABSTRACT_TYPE_CATEGORIES.Email,
input: { type: 'string' },
validation: {
conjunction: 'and',
terms: [
{
method: 'regex',
op: 'apply',
value: REGEXP.Email,
},
{
method: 'length',
op: 'lte',
value: 256,
},
],
},
},
...
} ABSTRACT_TYPES {
...,
[ABSTRACT_TYPE_CATEGORIES.Text]: {
filters: [
{
op: 'equals',
parameters: 'single'
},
{
op: 'is_empty',
parameters: 'none'
},
{
op: 'in',
parameters: 'multiple'
}
],
groups: [
...,
],
},
...,
} |
Beta Was this translation helpful? Give feedback.
-
@dmos62 This comment is for the proposed filter format.
|
Beta Was this translation helpful? Give feedback.
-
I'm working on a backend record/row filtering PR that, amongst other things, seeks to programmatically expose what filtering options are available for what Mathesar type. To that end I used a predicate hierarchy that looks something like this:
The used mixins hold almost all information necessary to construct a predicate on the frontend. These are exposed on the REST API like this:
Notice that the endpoint knows not to say that you can use a predicate that relies on the type being comparable (such predicate is identified by mixin
ReliesOnComparability
), if that type is not comparable, because Mathesar types' comparability is being declared as well. So for exampleBoolean
above does not list the predicate/filtergreater
as supported.As a side note, I think we could consider extending our Mathesar type definitions so that they could hold interesting information (like whether they are comparable) similarly to how the predicate classes hold information in this PR (through composition and dataclass fields).
Above changes imply a new middlelayer for interpreting the filter specification passed by the frontend. Here I had to either mimick the SQLAlchemy format or create something else. I opted for a new format, because I couldn't see any significant incentive to maintain compatibility with SA. The formats' fundamental structure is similar enough to be an easy change on the frontend, in my opinion.
Here's what the new filter specification format looks like:
It is more strict than the SA format. Only one root predicate: it does not support ambiguity about whether the implict branch [0] is an
or
or anand
. It's careful with plurality: there's only leaf [0] parameters that can only be a single value (they use the singular keyparameter
) and those that can only have a list of values (that use the plural keyparameters
). Same with the branch predicates:not
will always have one sub-predicate, whileor
andand
will have a list.A feature of the format I'm not sure about is to only use the
not
branch predicate to negate a predicate, i.e. not supportnot-equal
, but use{"not": {"equal": {...}}}
instead. I liked it initially because it reduces the size of the definition, but I now see that supporting "pre-negated leaves" is just a dozen lines of trivial code. The definition size might be a concern if we want to eventually support a lot of predicates, which might effectively double the definition size.Could you provide feedback on these proposed changes?
[0] There's two types of predicates,
branch
es andleaf
es. Branches (and
,or
,not
) contain (are parametrized on) other predicates, while leaves (e.g.empty
,equal
,greater
) are the remaining predicates.Beta Was this translation helpful? Give feedback.
All reactions