Skip to content

Commit dbd27bc

Browse files
benkeannaclaude
andcommitted
feat(gooddata-pipelines): make workspace data filter fields optional
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
1 parent efc6b2a commit dbd27bc

4 files changed

Lines changed: 76 additions & 19 deletions

File tree

docs/content/en/latest/pipelines/ldm_extension/_index.md

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,15 +43,17 @@ The custom dataset represents a new dataset appended to the child LDM. It is def
4343
| parent_dataset_reference_attribute_id | string | ID of the attribute used for creating the relationship in the parent dataset. |
4444
| dataset_reference_source_column | string | Name of the column used for creating the relationship in the custom dataset. |
4545
| dataset_reference_source_column_data_type | [ColumnDataType](#columndatatype) | Column data type. |
46-
| workspace_data_filter_id | string | ID of the workspace data filter to use. |
47-
| workspace_data_filter_column_name | string | Name of the column in custom dataset used for filtering. |
46+
| workspace_data_filter_id | string \| None | ID of the workspace data filter to use. Optional; when omitted the dataset participates in no workspace data filter. |
47+
| workspace_data_filter_column_name | string \| None | Name of the column in custom dataset used for filtering. Optional; must be set whenever `workspace_data_filter_id` is set. |
4848
| dataset_description | string \| None | Optional declarative description on the custom dataset. |
4949
| dataset_tags | string[] \| None | Optional tag list; when omitted, defaults to a single tag derived from the dataset display name. |
5050

5151
#### Validity constraints
5252

5353
Either `dataset_source_table` or `dataset_source_sql` must be specified with a truthy value, but not both. An exception will be raised if both parameters are falsy or if both have truthy values.
5454

55+
`workspace_data_filter_id` and `workspace_data_filter_column_name` must be provided together or both left unset. Setting only one of them raises a `ValidationError`. When both are unset, the resulting dataset is emitted without a workspace data filter binding.
56+
5557
### Custom Field Definitions
5658

5759
The custom fields define the individual fields in the custom datasets defined above. Each custom field needs to be specified with the following parameters:

packages/gooddata-pipelines/src/gooddata_pipelines/ldm_extension/input_processor.py

Lines changed: 31 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -253,6 +253,35 @@ def datasets_to_ldm(
253253
# Get the data source info
254254
dataset_source_table_id, dataset_sql = self._get_sources(dataset)
255255

256+
wdf_columns: (
257+
list[CatalogDeclarativeWorkspaceDataFilterColumn] | None
258+
) = None
259+
wdf_references: (
260+
list[CatalogDeclarativeWorkspaceDataFilterReferences] | None
261+
) = None
262+
wdf_id = dataset.definition.workspace_data_filter_id
263+
wdf_column_name = (
264+
dataset.definition.workspace_data_filter_column_name
265+
)
266+
# `check_wdf_pair` on the model guarantees both fields are set
267+
# together or both omitted.
268+
if wdf_id is not None and wdf_column_name is not None:
269+
wdf_columns = [
270+
CatalogDeclarativeWorkspaceDataFilterColumn(
271+
name=wdf_column_name,
272+
data_type=ColumnDataType.STRING.value,
273+
)
274+
]
275+
wdf_references = [
276+
CatalogDeclarativeWorkspaceDataFilterReferences(
277+
filter_id=CatalogDatasetWorkspaceDataFilterIdentifier(
278+
id=wdf_id
279+
),
280+
filter_column=wdf_column_name,
281+
filter_column_data_type=ColumnDataType.STRING.value,
282+
)
283+
]
284+
256285
# Construct the declarative dataset object and append it to the list.
257286
declarative_datasets.append(
258287
CatalogDeclarativeDataset(
@@ -283,21 +312,8 @@ def datasets_to_ldm(
283312
facts=facts,
284313
data_source_table_id=dataset_source_table_id,
285314
sql=dataset_sql,
286-
workspace_data_filter_columns=[
287-
CatalogDeclarativeWorkspaceDataFilterColumn(
288-
name=dataset.definition.workspace_data_filter_column_name,
289-
data_type=ColumnDataType.STRING.value,
290-
)
291-
],
292-
workspace_data_filter_references=[
293-
CatalogDeclarativeWorkspaceDataFilterReferences(
294-
filter_id=CatalogDatasetWorkspaceDataFilterIdentifier(
295-
id=dataset.definition.workspace_data_filter_id
296-
),
297-
filter_column=dataset.definition.workspace_data_filter_column_name,
298-
filter_column_data_type=ColumnDataType.STRING.value,
299-
)
300-
],
315+
workspace_data_filter_columns=wdf_columns,
316+
workspace_data_filter_references=wdf_references,
301317
tags=_effective_dataset_tags(dataset.definition),
302318
)
303319
)

packages/gooddata-pipelines/src/gooddata_pipelines/ldm_extension/models/custom_data_object.py

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -74,8 +74,8 @@ class CustomDatasetDefinition(BaseModel):
7474
parent_dataset_reference_attribute_id: str
7575
dataset_reference_source_column: str
7676
dataset_reference_source_column_data_type: ColumnDataType
77-
workspace_data_filter_id: str
78-
workspace_data_filter_column_name: str
77+
workspace_data_filter_id: str | None = None
78+
workspace_data_filter_column_name: str | None = None
7979
dataset_description: str | None = Field(
8080
default=None,
8181
description="Declarative description on the custom dataset.",
@@ -98,6 +98,18 @@ def check_source(self) -> "CustomDatasetDefinition":
9898
)
9999
return self
100100

101+
@model_validator(mode="after")
102+
def check_wdf_pair(self) -> "CustomDatasetDefinition":
103+
"""Workspace data filter id and column name must be provided together or both omitted."""
104+
has_id = self.workspace_data_filter_id is not None
105+
has_col = self.workspace_data_filter_column_name is not None
106+
if has_id != has_col:
107+
raise ValueError(
108+
"workspace_data_filter_id and workspace_data_filter_column_name "
109+
"must both be set or both be omitted"
110+
)
111+
return self
112+
101113

102114
class CustomDataset(BaseModel):
103115
"""Custom dataset with its definition and custom fields."""

packages/gooddata-pipelines/tests/test_ldm_extension/test_models/test_custom_data_object.py

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,3 +100,30 @@ def test_custom_dataset_model():
100100
assert dataset.definition.dataset_id == "ds1"
101101
assert len(dataset.custom_fields) == 1
102102
assert dataset.custom_fields[0].custom_field_id == "cf1"
103+
104+
105+
def test_custom_dataset_definition_wdf_optional_both_none():
106+
data = make_valid_dataset_def(
107+
workspace_data_filter_id=None, workspace_data_filter_column_name=None
108+
)
109+
ds = CustomDatasetDefinition(**data)
110+
assert ds.workspace_data_filter_id is None
111+
assert ds.workspace_data_filter_column_name is None
112+
113+
114+
def test_custom_dataset_definition_wdf_only_id_raises():
115+
data = make_valid_dataset_def(
116+
workspace_data_filter_id="wdf1", workspace_data_filter_column_name=None
117+
)
118+
with pytest.raises(ValidationError) as exc:
119+
CustomDatasetDefinition(**data)
120+
assert "both be set or both be omitted" in str(exc.value)
121+
122+
123+
def test_custom_dataset_definition_wdf_only_column_raises():
124+
data = make_valid_dataset_def(
125+
workspace_data_filter_id=None, workspace_data_filter_column_name="col1"
126+
)
127+
with pytest.raises(ValidationError) as exc:
128+
CustomDatasetDefinition(**data)
129+
assert "both be set or both be omitted" in str(exc.value)

0 commit comments

Comments
 (0)