Skip to content

Commit

Permalink
fix(formula): BI-5959 apply mutations before adding formula to global…
Browse files Browse the repository at this point in the history
… dimensions during validation (#733)

* fix(formula): BI-5959 apply mutations before adding formula to global dimensions during validation

* cq

* remove comment
  • Loading branch information
KonstantAnxiety authored Dec 2, 2024
1 parent 62ce5bf commit f7e591c
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -432,6 +432,38 @@ def test_dimensions_in_window_function_identical_to_dims_in_query(self, control_

assert result_resp.status_code == HTTPStatus.OK, result_resp.json

def test_const_ops_in_window_ordering_dimension(self, control_api, data_api, saved_dataset):
ds = add_formulas_to_dataset(
api_v1=control_api,
dataset=saved_dataset,
formulas={
"order_day_in_year": "[order_date] - DATETRUNC([order_date], 'year')",
"order_period": """
IF [order_day_in_year] <= (365 * 1 / 2) THEN "H1"
ELSE "H2"
END
""",
"Group Sales": "SUM([sales])",
"RSum": "RSUM([Group Sales])",
},
)

result_resp = data_api.get_result(
dataset=ds,
fields=[
ds.find_field(title="order_period"),
ds.find_field(title="RSum"),
],
order_by=[
ds.find_field(title="order_period"),
],
fail_ok=True,
)
assert result_resp.status_code == HTTPStatus.OK, result_resp.json

data_rows = get_data_rows(result_resp) # [['H1', '161667.14076359986'], ['H2', '228798.99612549983']]
assert len(data_rows) == 2

def test_order_by_multilevel_window_function(self, control_api, data_api, saved_dataset):
ds = add_formulas_to_dataset(
api_v1=control_api,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -868,7 +868,7 @@ def _validate_field_formula(
for dim_field_id in self._group_by_ids:
dim_field = self._fields.get(id=dim_field_id)
try:
dim_formula_obj = self._process_field_stage_aggregation(dim_field, collect_errors=collect_errors)
dim_formula_obj = self._process_field_stage_mutation(dim_field, collect_errors=collect_errors)
except formula_exc.FormulaError:
# error has been registered, so when the field will be rendered explicitly the error will be raised
# here we can just skip it since there's nothing to register as a dimension
Expand Down

0 comments on commit f7e591c

Please sign in to comment.