diff --git a/lib/dl_api_lib/dl_api_lib_tests/db/data_api/result/complex_queries/test_window_functions.py b/lib/dl_api_lib/dl_api_lib_tests/db/data_api/result/complex_queries/test_window_functions.py index 041f945e3..e2d5f8d12 100644 --- a/lib/dl_api_lib/dl_api_lib_tests/db/data_api/result/complex_queries/test_window_functions.py +++ b/lib/dl_api_lib/dl_api_lib_tests/db/data_api/result/complex_queries/test_window_functions.py @@ -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, diff --git a/lib/dl_query_processing/dl_query_processing/compilation/formula_compiler.py b/lib/dl_query_processing/dl_query_processing/compilation/formula_compiler.py index e5d017b52..9df28ad4b 100644 --- a/lib/dl_query_processing/dl_query_processing/compilation/formula_compiler.py +++ b/lib/dl_query_processing/dl_query_processing/compilation/formula_compiler.py @@ -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