|
5 | 5 | from importlib.util import find_spec
|
6 | 6 | from typing import Optional, Union
|
7 | 7 |
|
| 8 | +from gooddata_api_client.model.inline_filter_definition_inline import InlineFilterDefinitionInline |
| 9 | + |
8 | 10 | if find_spec("icu") is not None:
|
9 | 11 | from icu import Locale, SimpleDateFormat # type: ignore[import-not-found]
|
10 | 12 |
|
@@ -503,3 +505,38 @@ def description(self, labels: dict[str, str], format_locale: Optional[str] = Non
|
503 | 505 | return (
|
504 | 506 | f"{self.operator.capitalize()} {self.value}{dimensionality_str} {labels.get(metric_ids[0], metric_ids[0])}"
|
505 | 507 | )
|
| 508 | + |
| 509 | + |
| 510 | +class InlineFilter(Filter): |
| 511 | + """Filter using a custom MAQL expression. |
| 512 | +
|
| 513 | + Automatically decides, whether to create or update. |
| 514 | +
|
| 515 | + Args: |
| 516 | + maql (str): The MAQL expression string that defines the filter condition. |
| 517 | +
|
| 518 | + Example: |
| 519 | + ```python |
| 520 | + from gooddata_sdk import InlineFilter |
| 521 | + from gooddata_pandas import GoodPandas |
| 522 | +
|
| 523 | + gp = GoodPandas.create_from_profile() |
| 524 | + factory = gp.data_frames("demo") |
| 525 | +
|
| 526 | + filter_by = InlineFilter('{label/region} = "West"') |
| 527 | +
|
| 528 | + factory.not_indexed(columns=dict(order_amount="metric/order_amount"), filter_by=filter_by) |
| 529 | + ``` |
| 530 | + """ |
| 531 | + |
| 532 | + def __init__(self, maql: str): |
| 533 | + super().__init__() |
| 534 | + |
| 535 | + self.maql = maql |
| 536 | + |
| 537 | + def is_noop(self) -> bool: |
| 538 | + return False |
| 539 | + |
| 540 | + def as_api_model(self) -> afm_models.InlineFilterDefinition: |
| 541 | + body = InlineFilterDefinitionInline(self.maql) |
| 542 | + return afm_models.InlineFilterDefinition(body, _check_type=False) |
0 commit comments