Skip to content
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

Filtering and sorting #3230

Merged
merged 21 commits into from
Dec 13, 2024
Merged
Show file tree
Hide file tree
Changes from 19 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 44 additions & 2 deletions src/zenml/client.py

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@
from zenml.step_operators import BaseStepOperator

if TYPE_CHECKING:
from zenml.config.base_settings import BaseSettings
from zenml.config.step_run_info import StepRunInfo
from zenml.models import PipelineDeploymentBase

Expand Down
20 changes: 12 additions & 8 deletions src/zenml/models/v2/base/filter.py
Original file line number Diff line number Diff line change
Expand Up @@ -436,7 +436,6 @@ class BaseFilter(BaseModel):
le=PAGE_SIZE_MAXIMUM,
description="Page size",
)

id: Optional[Union[UUID, str]] = Field(
default=None,
description="Id for this resource",
Expand Down Expand Up @@ -491,13 +490,13 @@ def validate_sort_by(cls, value: Any) -> Any:
)
value = column

if column in cls.FILTER_EXCLUDE_FIELDS:
if column in cls.CUSTOM_SORTING_OPTIONS:
return value
elif column in cls.FILTER_EXCLUDE_FIELDS:
raise ValueError(
f"This resource can not be sorted by this field: '{value}'"
)
elif column in cls.model_fields:
return value
elif column in cls.CUSTOM_SORTING_OPTIONS:
if column in cls.model_fields:
return value
else:
raise ValueError(
Expand Down Expand Up @@ -759,7 +758,7 @@ def offset(self) -> int:
return self.size * (self.page - 1)

def generate_filter(
self, table: Type[SQLModel]
self, table: Type["AnySchema"]
) -> Union["ColumnElement[bool]"]:
"""Generate the filter for the query.
Expand All @@ -779,7 +778,7 @@ def generate_filter(
filters.append(
column_filter.generate_query_conditions(table=table)
)
for custom_filter in self.get_custom_filters():
for custom_filter in self.get_custom_filters(table):
filters.append(custom_filter)
if self.logical_operator == LogicalOperators.OR:
return or_(False, *filters)
Expand All @@ -788,12 +787,17 @@ def generate_filter(
else:
raise RuntimeError("No valid logical operator was supplied.")

def get_custom_filters(self) -> List["ColumnElement[bool]"]:
def get_custom_filters(
self, table: Type["AnySchema"]
) -> List["ColumnElement[bool]"]:
"""Get custom filters.
This can be overridden by subclasses to define custom filters that are
not based on the columns of the underlying table.
Args:
table: The query table.
Returns:
A list of custom filters.
"""
Expand Down
Loading
Loading