Skip to content

Commit

Permalink
fix(server/condition): add InclusionConditionWithVariables (#2039)
Browse files Browse the repository at this point in the history
Signed-off-by: Luka Peschke <[email protected]>
  • Loading branch information
lukapeschke authored Mar 12, 2024
1 parent dd79a9e commit 828e325
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 2 deletions.
6 changes: 5 additions & 1 deletion server/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
8 changes: 7 additions & 1 deletion server/src/weaverbird/pipeline/conditions.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"]
Expand Down Expand Up @@ -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):
Expand Down
1 change: 1 addition & 0 deletions server/tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,5 @@ def available_variables():
"ONE": 1,
"ONE_POINT_ONE": 1.1,
"TRUE": True,
"INTEGER_LIST": [1, 2, 3],
}
4 changes: 4 additions & 0 deletions server/tests/steps/test_filter.py
Original file line number Diff line number Diff line change
Expand Up @@ -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]

0 comments on commit 828e325

Please sign in to comment.