From 828e3253c706c8654e7023cf1310b9edc405bcb3 Mon Sep 17 00:00:00 2001 From: Luka Peschke Date: Tue, 12 Mar 2024 13:19:13 +0100 Subject: [PATCH] fix(server/condition): add InclusionConditionWithVariables (#2039) Signed-off-by: Luka Peschke --- server/CHANGELOG.md | 6 +++++- server/src/weaverbird/pipeline/conditions.py | 8 +++++++- server/tests/conftest.py | 1 + server/tests/steps/test_filter.py | 4 ++++ 4 files changed, 17 insertions(+), 2 deletions(-) diff --git a/server/CHANGELOG.md b/server/CHANGELOG.md index dd0afce381..e920eec4b4 100644 --- a/server/CHANGELOG.md +++ b/server/CHANGELOG.md @@ -2,11 +2,15 @@ ## Unreleased +### Fixed + +- A `FilterStepWithVariables` can now contain an `InclusionConditionWithVariables` + ## [0.42.1] - 2024-03-05 ### Fixed -- Google Biq Query: ToDate step now produces datetime columns, not timestamp +- Google Big Query: ToDate step now produces datetime columns, not timestamp - Mongo: Fixed the `ifthenelse` step which generated "$and" clauses instead of "$or" - Mongo: Fixed the `evolution` step when several index columns are used. The generated pipeline now filters on all of them rather than just the last one. diff --git a/server/src/weaverbird/pipeline/conditions.py b/server/src/weaverbird/pipeline/conditions.py index eb4fb9fc3a..438165532b 100644 --- a/server/src/weaverbird/pipeline/conditions.py +++ b/server/src/weaverbird/pipeline/conditions.py @@ -23,6 +23,12 @@ class InclusionCondition(BaseCondition): value: list[Any] +class InclusionConditionWithVariables(BaseCondition): + column: ColumnName + operator: Literal["in", "nin"] + value: list[Any] | str + + class NullCondition(BaseCondition): column: ColumnName operator: Literal["isnull", "notnull"] @@ -50,7 +56,7 @@ class DateBoundConditionWithVariables(BaseModel): ComparisonCondition | InclusionCondition | NullCondition | MatchCondition | DateBoundCondition, Field(discriminator="operator"), # noqa: F821 ] -SimpleConditionWithVariables = DateBoundConditionWithVariables | SimpleCondition +SimpleConditionWithVariables = DateBoundConditionWithVariables | InclusionConditionWithVariables | SimpleCondition class BaseConditionCombo(BaseCondition, ABC): diff --git a/server/tests/conftest.py b/server/tests/conftest.py index 3dd5733f7f..93b4f3c0f4 100644 --- a/server/tests/conftest.py +++ b/server/tests/conftest.py @@ -10,4 +10,5 @@ def available_variables(): "ONE": 1, "ONE_POINT_ONE": 1.1, "TRUE": True, + "INTEGER_LIST": [1, 2, 3], } diff --git a/server/tests/steps/test_filter.py b/server/tests/steps/test_filter.py index 8732b7385a..1347f34cbd 100644 --- a/server/tests/steps/test_filter.py +++ b/server/tests/steps/test_filter.py @@ -460,3 +460,7 @@ def test_render_filter_step_with_variables(available_variables: dict[str, Any]) step = FilterStepWithVariables(condition={"or": [step.model_dump()["condition"]]}) rendered = step.render(available_variables, nosql_apply_parameters_to_query) assert rendered.condition.or_[0].value.date == available_variables["TODAY"] + + step = FilterStepWithVariables(condition={"column": "int_column", "operator": "in", "value": "{{ INTEGER_LIST }}"}) + rendered = step.render(available_variables, nosql_apply_parameters_to_query) + assert rendered.condition.value == available_variables["INTEGER_LIST"] == [1, 2, 3]