Skip to content
Merged
Changes from all 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
19 changes: 15 additions & 4 deletions packages/gooddata-sdk/src/gooddata_sdk/compute/model/filter.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

from datetime import datetime
from importlib.util import find_spec
from typing import Any, Optional, Union, cast
from typing import Any, Literal, Optional, TypeAlias, Union, cast

import attrs
from gooddata_api_client.model.inline_filter_definition_inline import InlineFilterDefinitionInline
Expand Down Expand Up @@ -64,6 +64,17 @@
"NOT_EQUAL_TO": "!=",
}

ComparisonOperator: TypeAlias = Literal[
"GREATER_THAN",
"GREATER_THAN_OR_EQUAL_TO",
"LESS_THAN",
"LESS_THAN_OR_EQUAL_TO",
"EQUAL_TO",
"NOT_EQUAL_TO",
]

RangeOperator: TypeAlias = Literal["BETWEEN", "NOT_BETWEEN"]


def _extract_id_or_local_id(val: Union[ObjId, Attribute, Metric, str]) -> Union[ObjId, str]:
if isinstance(val, (str, ObjId)):
Expand Down Expand Up @@ -488,7 +499,7 @@ def description(self, labels: dict[str, str], format_locale: Optional[str] = Non

@attrs.define(frozen=True, slots=True)
class MetricValueComparisonCondition:
operator: str
operator: ComparisonOperator
value: Union[int, float]

def as_api_model(self) -> afm_models.MeasureValueCondition:
Expand All @@ -505,7 +516,7 @@ def description(self) -> str:

@attrs.define(frozen=True, slots=True)
class MetricValueRangeCondition:
operator: str
operator: RangeOperator
from_value: Union[int, float]
to_value: Union[int, float]

Expand All @@ -519,7 +530,7 @@ def as_api_model(self) -> afm_models.MeasureValueCondition:
return afm_models.MeasureValueCondition(range=range_body, _check_type=False)

def description(self) -> str:
not_between = "not" if self.operator == "NOT_BETWEEN" else ""
not_between = "not " if self.operator == "NOT_BETWEEN" else ""
return f"{not_between}between {float(self.from_value)} - {float(self.to_value)}"


Expand Down
Loading