-
Notifications
You must be signed in to change notification settings - Fork 3
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
Allow complex filters being set #1401
Comments
Reminder: the action of merging two filter sets together is now also implemented in fractal-web (ref fractal-analytics-platform/fractal-web#442). When we change the filter structure, we should either change it in both places or offer a dedicated endpoint for the merge operation. |
Here is the latest update. Images subpackageThe current class Filters(BaseModel, extra=Extra.forbid):
attributes: dict[str, Any] = Field(default_factory=dict)
types: dict[str, bool] = Field(default_factory=dict)
# Validators
_attributes = validator("attributes", allow_reuse=True)(
valdictkeys("attributes")
)
_types = validator("types", allow_reuse=True)(valdictkeys("types"))
@validator("attributes")
def validate_attributes(
cls, v: dict[str, Any]
) -> dict[str, Union[int, float, str, bool, None]]:
for key, value in v.items():
if not isinstance(value, (int, float, str, bool, type(None))):
raise ValueError(
f"Filters.attributes[{key}] must be a scalar "
"(int, float, str, bool, or None). "
f"Given {value} ({type(value)})"
)
return v The new one should look like The current `Filters` model looks like
```python
class Filters(BaseModel, extra=Extra.forbid):
attributes_include: dict[str, list[Any]] = Field(default_factory=dict)
attributes_exclude: dict[str, list[Any]] = Field(default_factory=dict)
types: dict[str, bool] = Field(default_factory=dict)
... + validators where the lists are meant as internally joined by a logical OR. Validators will now apply to the list elements:
The Examples:
DBCurrent version input_filters: dict[
Literal["attributes", "types"], dict[str, Any]
] = Field(
sa_column=Column(
JSON,
nullable=False,
server_default='{"attributes": {}, "types": {}}',
)
) to be updated accordingly. APIChanges are the expected ones (that is, using the new Data migration for current DB valuesExisting relevant db columns are
A data-migration script is required, and it will make this change:
Backwards-compatibility for importing old workflows/datasets from JSONIf a workflow was exported in the past, and it has some filters set, these would be in the "old" version. This model class WorkflowTaskImportV2(BaseModel, extra=Extra.forbid):
...
input_filters: Optional[Filters] = None should become something like class WorkflowTaskImportV2(BaseModel, extra=Extra.forbid):
...
input_filters: Optional[Union[Filters, FiltersLegacy]] = None We should double check that:
The same applies to |
Let's not invest too much into handling older attribute filters. Suggested behavior for workflow import: If any attribute filters are set in a workflow, upon import show a warning that it's dropped. Suggested behavior for dataset import: TBD. Could raise an informative NotImplementedError |
Two additions:
|
If my understanding is correct, we currently can filter for the following:
Inclusion only
AND combination of filters
Single filter per attribute / type
For types: Filter for boolean true vs. false
For attributes: Filter for exact match of the attribute
Correct me if I'm wrong and we already support more in V2 @tcompa
Because it comes up in web discussions, I'll try to give a larger perspective of where this could go in the future. This is not meant as blocking for the v2 release.
There are many areas where we could expand the filters to allow for more complex filters, ordered by approximate importance:
Important:
Nice to have:
I don't currently see the value in:
Support OR filters between attributes: Look for well B03 or acquisition 1
The text was updated successfully, but these errors were encountered: