This page covers filters from an engineering/architecture perspective. Please see the “Filters” product concepts page for a user-facing looking at filters.
In Mathesar, filters are a subset of functions that take in a set of row or a relation as input and return only the rows that satisfy some condition.
To be considered a filter, a function has to only consider a single row at a time. It should have no knowledge of any other rows in the relation. This means that filters are commutative.
Consider this table:
As an example, here’s a table:
ID | Title | Year | Favorite |
---|---|---|---|
1 | Dante’s Peak | 1997 | FALSE |
2 | Forrest Gump | 1994 | TRUE |
3 | The Karate Kid | 1984 | TRUE |
4 | Dante’s Peak | 1997 | TRUE |
5 | The Karate Kid | 1984 | TRUE |
Here are some examples of correct and wrong filters. The emoji indicates whether they are correct.
"Year" > 1990
"ID" = 5
"Favorite" is TRUE
You might be wondering why filter scope is limited to a single row. This is to allow filters to be applied in any order (to ensure filters are commutative). Otherwise, we will need to introduce users to the concept of a pipeline of operations and that seems more complicated to design. We plan to have a separate user-facing concept for operations that will have different results depending on the ordering.
This can be illustrated with treating “is a duplicate” as a filter below and observing how the results change based on ordering. This uses the table from the example above.
Imagine the user applies filters in this order:
"Year" > 1993
"Favorite" is TRUE
"Title" is a duplicate
"Year" > 1993
After filtering:
ID | Title | Year | Favorite |
---|---|---|---|
1 | Dante’s Peak | 1997 | FALSE |
2 | Forrest Gump | 1994 | TRUE |
4 | Dante’s Peak | 1997 | TRUE |
"Favorite" is TRUE
After filtering:
ID | Title | Year | Favorite |
---|---|---|---|
2 | Forrest Gump | 1994 | TRUE |
4 | Dante’s Peak | 1997 | TRUE |
"Title" is a duplicate
After filtering: 0 results.
But instead if the user applies filter in this order
"Year" > 1993
"Title" is a duplicate
"Favorite" is TRUE
"Year" > 1993
After filtering:
ID | Title | Year | Favorite |
---|---|---|---|
1 | Dante’s Peak | 1997 | FALSE |
2 | Forrest Gump | 1994 | TRUE |
4 | Dante’s Peak | 1997 | TRUE |
"Title" is a duplicate
After filtering:
ID | Title | Year | Favorite |
---|---|---|---|
1 | Dante’s Peak | 1997 | FALSE |
4 | Dante’s Peak | 1997 | TRUE |
"Favorite" is TRUE
After filtering:
ID | Title | Year | Favorite |
---|---|---|---|
4 | Dante’s Peak | 1997 | TRUE |