Skip to content

Commit cabf28e

Browse files
committed
feat: add MatchAttributeFilter to ExecutionContext
This reflects the filter type recently added on the backend. JIRA: CQ-2005 risk: low
1 parent 32e8a28 commit cabf28e

File tree

4 files changed

+96
-0
lines changed

4 files changed

+96
-0
lines changed

packages/gooddata-flexconnect/json_schemas/execution-context/filter.json

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,44 @@
5959
"values"
6060
]
6161
},
62+
{
63+
"type": "object",
64+
"description": "Filter for matching label values using a literal string pattern.",
65+
"properties": {
66+
"filterType": {
67+
"const": "matchAttributeFilter"
68+
},
69+
"labelIdentifier": {
70+
"type": "string",
71+
"description": "Identifier of the label used."
72+
},
73+
"matchType": {
74+
"type": "string",
75+
"enum": ["CONTAINS", "STARTS_WITH", "ENDS_WITH"],
76+
"description": "The type of string match to apply."
77+
},
78+
"literal": {
79+
"type": "string",
80+
"description": "The literal value to match against."
81+
},
82+
"negate": {
83+
"type": "boolean",
84+
"default": false,
85+
"description": "Whether to negate the match."
86+
},
87+
"caseSensitive": {
88+
"type": "boolean",
89+
"default": false,
90+
"description": "Whether the match is case-sensitive."
91+
}
92+
},
93+
"required": [
94+
"filterType",
95+
"labelIdentifier",
96+
"matchType",
97+
"literal"
98+
]
99+
},
62100
{
63101
"type": "object",
64102
"description": "Filter for relative date ranges.",

packages/gooddata-flexconnect/src/gooddata_flexconnect/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
ExecutionContextAttribute,
1212
ExecutionContextAttributeSorting,
1313
ExecutionContextFilter,
14+
ExecutionContextMatchAttributeFilter,
1415
ExecutionContextNegativeAttributeFilter,
1516
ExecutionContextPositiveAttributeFilter,
1617
ExecutionContextRelativeDateFilter,

packages/gooddata-flexconnect/src/gooddata_flexconnect/function/execution_context.py

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -176,6 +176,38 @@ class ExecutionContextNegativeAttributeFilter:
176176
"""
177177

178178

179+
@dataclass
180+
class ExecutionContextMatchAttributeFilter:
181+
"""
182+
Information about the match attribute filter.
183+
"""
184+
185+
label_identifier: str
186+
"""
187+
Identifier of the label used.
188+
"""
189+
190+
literal: str
191+
"""
192+
Value to filter by.
193+
"""
194+
195+
match_type: str
196+
"""
197+
Match type of the filter.
198+
"""
199+
200+
negate: bool
201+
"""
202+
Whether the filter should keep values NOT matching the literal.
203+
"""
204+
205+
case_sensitive: bool
206+
"""
207+
Whether the matching should be made in a case-sensitive way.
208+
"""
209+
210+
179211
@dataclass
180212
class ExecutionContextRelativeDateFilter:
181213
"""
@@ -228,6 +260,7 @@ class ExecutionContextAbsoluteDateFilter:
228260
ExecutionContextFilter: TypeAlias = Union[
229261
ExecutionContextPositiveAttributeFilter,
230262
ExecutionContextNegativeAttributeFilter,
263+
ExecutionContextMatchAttributeFilter,
231264
ExecutionContextRelativeDateFilter,
232265
ExecutionContextAbsoluteDateFilter,
233266
]
@@ -564,6 +597,15 @@ def _dict_to_filter(d: dict) -> ExecutionContextFilter:
564597
if filter_type == "negativeAttributeFilter":
565598
return ExecutionContextNegativeAttributeFilter(label_identifier=d["labelIdentifier"], values=d["values"])
566599

600+
if filter_type == "matchAttributeFilter":
601+
return ExecutionContextMatchAttributeFilter(
602+
label_identifier=d["labelIdentifier"],
603+
literal=d["literal"],
604+
match_type=d["matchType"],
605+
negate=d.get("negate", False),
606+
case_sensitive=d.get("caseSensitive", False),
607+
)
608+
567609
if filter_type == "relativeDateFilter":
568610
return ExecutionContextRelativeDateFilter(
569611
dataset_identifier=d["datasetIdentifier"],

packages/gooddata-flexconnect/tests/json_schemas/test_filter_schema.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,12 @@
1616
"labelIdentifier": "attribute1",
1717
"values": ["id1", "id2", "id3", None],
1818
},
19+
{
20+
"filterType": "matchAttributeFilter",
21+
"labelIdentifier": "attribute1",
22+
"literal": "foo",
23+
"matchType": "CONTAINS",
24+
},
1925
{
2026
"filterType": "relativeDateFilter",
2127
"from": -5,
@@ -42,6 +48,15 @@ def test_valid_filter_schema(value, get_validator):
4248
{"filterType": "negativeAttributeFilter", "labelIdentifier": "attribute1"}, # missing values
4349
{"filterType": "relativeDateFilter", "from": -5, "to": 0, "granularity": "DAY"}, # missing datasetIdentifier
4450
{"filterType": "absoluteDateFilter", "from": "2021-01-01", "to": "2021-12-31"}, # missing datasetIdentifier
51+
# missing match type
52+
{"filterType": "matchAttributeFilter", "labelIdentifier": "attribute1", "literal": "foo"},
53+
# invalid match type
54+
{
55+
"filterType": "matchAttributeFilter",
56+
"labelIdentifier": "attribute1",
57+
"literal": "foo",
58+
"matchType": "INVALID",
59+
},
4560
],
4661
)
4762
def test_invalid_filter_schema(value, get_validator):

0 commit comments

Comments
 (0)