datalens-tech / datalens-backend

Data processing backend for DataLens
https://datalens.tech
Apache License 2.0
127 stars 25 forks source link

Error when ordering by a LAG formula field #531

Open MCPN opened 1 month ago

MCPN commented 1 month ago

Example formula: LAG([SUM([int_field]), 1)

Traceback ```python Traceback (most recent call last): File "/data/mainrepo/lib/dl_query_processing/dl_query_processing/compilation/formula_compiler.py", line 238, in handle yield File "/data/mainrepo/lib/dl_query_processing/dl_query_processing/compilation/formula_compiler.py", line 308, in wrapper formula_obj = func(self, field, collect_errors) File "/data/mainrepo/lib/dl_query_processing/dl_query_processing/compilation/formula_compiler.py", line 921, in _process_field_stage_dep_generation self._make_dependencies_for_field(field=field, formula_obj=formula_obj) File "/data/mainrepo/lib/dl_query_processing/dl_query_processing/compilation/formula_compiler.py", line 595, in _make_dependencies_for_field raise dl_query_processing.exc.FormulaHandlingError( dl_query_processing.exc.FormulaHandlingError: Recursion detected in field The above exception was the direct cause of the following exception: Traceback (most recent call last): File "/data/mainrepo/lib/dl_query_processing/dl_query_processing/compilation/formula_compiler.py", line 238, in handle yield File "/data/mainrepo/lib/dl_query_processing/dl_query_processing/compilation/formula_compiler.py", line 308, in wrapper formula_obj = func(self, field, collect_errors) File "/data/mainrepo/lib/dl_query_processing/dl_query_processing/compilation/formula_compiler.py", line 926, in _process_field_stage_substitution formula_obj = self._process_field_stage_dep_generation(field, collect_errors=collect_errors) File "/data/mainrepo/lib/dl_query_processing/dl_query_processing/compilation/formula_compiler.py", line 306, in wrapper with self._stage_manager.handle(field=field, stage=stage, collect=collect_errors): File "/usr/lib/python3.10/contextlib.py", line 153, in __exit__ self.gen.throw(typ, value, traceback) File "/data/mainrepo/lib/dl_query_processing/dl_query_processing/compilation/formula_compiler.py", line 256, in handle raise dl_query_processing.exc.FormulaHandlingError(*pass_on_errors, stage=stage, field=field) from err dl_query_processing.exc.FormulaHandlingError: Recursion detected in field The above exception was the direct cause of the following exception: Traceback (most recent call last): File "/data/mainrepo/lib/dl_query_processing/dl_query_processing/compilation/formula_compiler.py", line 238, in handle yield File "/data/mainrepo/lib/dl_query_processing/dl_query_processing/compilation/formula_compiler.py", line 308, in wrapper formula_obj = func(self, field, collect_errors) File "/data/mainrepo/lib/dl_query_processing/dl_query_processing/compilation/formula_compiler.py", line 931, in _process_field_stage_casting formula_obj = self._process_field_stage_substitution(field, collect_errors=collect_errors) File "/data/mainrepo/lib/dl_query_processing/dl_query_processing/compilation/formula_compiler.py", line 306, in wrapper with self._stage_manager.handle(field=field, stage=stage, collect=collect_errors): File "/usr/lib/python3.10/contextlib.py", line 153, in __exit__ self.gen.throw(typ, value, traceback) File "/data/mainrepo/lib/dl_query_processing/dl_query_processing/compilation/formula_compiler.py", line 256, in handle raise dl_query_processing.exc.FormulaHandlingError(*pass_on_errors, stage=stage, field=field) from err dl_query_processing.exc.FormulaHandlingError: Recursion detected in field The above exception was the direct cause of the following exception: Traceback (most recent call last): File "/data/mainrepo/lib/dl_query_processing/dl_query_processing/compilation/formula_compiler.py", line 238, in handle yield File "/data/mainrepo/lib/dl_query_processing/dl_query_processing/compilation/formula_compiler.py", line 308, in wrapper formula_obj = func(self, field, collect_errors) File "/data/mainrepo/lib/dl_query_processing/dl_query_processing/compilation/formula_compiler.py", line 940, in _process_field_stage_aggregation formula_obj = self._process_field_stage_casting(field, collect_errors=collect_errors) File "/data/mainrepo/lib/dl_query_processing/dl_query_processing/compilation/formula_compiler.py", line 306, in wrapper with self._stage_manager.handle(field=field, stage=stage, collect=collect_errors): File "/usr/lib/python3.10/contextlib.py", line 153, in __exit__ self.gen.throw(typ, value, traceback) File "/data/mainrepo/lib/dl_query_processing/dl_query_processing/compilation/formula_compiler.py", line 256, in handle raise dl_query_processing.exc.FormulaHandlingError(*pass_on_errors, stage=stage, field=field) from err dl_query_processing.exc.FormulaHandlingError: Recursion detected in field The above exception was the direct cause of the following exception: Traceback (most recent call last): File "/data/mainrepo/lib/dl_query_processing/dl_query_processing/compilation/formula_compiler.py", line 238, in handle yield File "/data/mainrepo/lib/dl_query_processing/dl_query_processing/compilation/formula_compiler.py", line 308, in wrapper formula_obj = func(self, field, collect_errors) File "/data/mainrepo/lib/dl_query_processing/dl_query_processing/compilation/formula_compiler.py", line 948, in _process_field_stage_mutation formula_obj = self._process_field_stage_aggregation(field, collect_errors=collect_errors) File "/data/mainrepo/lib/dl_query_processing/dl_query_processing/compilation/formula_compiler.py", line 306, in wrapper with self._stage_manager.handle(field=field, stage=stage, collect=collect_errors): File "/usr/lib/python3.10/contextlib.py", line 153, in __exit__ self.gen.throw(typ, value, traceback) File "/data/mainrepo/lib/dl_query_processing/dl_query_processing/compilation/formula_compiler.py", line 256, in handle raise dl_query_processing.exc.FormulaHandlingError(*pass_on_errors, stage=stage, field=field) from err dl_query_processing.exc.FormulaHandlingError: Recursion detected in field The above exception was the direct cause of the following exception: Traceback (most recent call last): File "/data/mainrepo/lib/dl_query_processing/dl_query_processing/compilation/formula_compiler.py", line 238, in handle yield File "/data/mainrepo/lib/dl_query_processing/dl_query_processing/compilation/formula_compiler.py", line 308, in wrapper formula_obj = func(self, field, collect_errors) File "/data/mainrepo/lib/dl_query_processing/dl_query_processing/compilation/formula_compiler.py", line 953, in _process_field_stage_validation formula_obj = self._process_field_stage_mutation(field, collect_errors=collect_errors) File "/data/mainrepo/lib/dl_query_processing/dl_query_processing/compilation/formula_compiler.py", line 306, in wrapper with self._stage_manager.handle(field=field, stage=stage, collect=collect_errors): File "/usr/lib/python3.10/contextlib.py", line 153, in __exit__ self.gen.throw(typ, value, traceback) File "/data/mainrepo/lib/dl_query_processing/dl_query_processing/compilation/formula_compiler.py", line 256, in handle raise dl_query_processing.exc.FormulaHandlingError(*pass_on_errors, stage=stage, field=field) from err dl_query_processing.exc.FormulaHandlingError: Recursion detected in field The above exception was the direct cause of the following exception: Traceback (most recent call last): File "/data/mainrepo/lib/dl_query_processing/dl_query_processing/compilation/formula_compiler.py", line 238, in handle yield File "/data/mainrepo/lib/dl_query_processing/dl_query_processing/compilation/formula_compiler.py", line 308, in wrapper formula_obj = func(self, field, collect_errors) File "/data/mainrepo/lib/dl_query_processing/dl_query_processing/compilation/formula_compiler.py", line 959, in _process_field_stage_final return self._process_field_stage_validation(field, collect_errors=collect_errors) File "/data/mainrepo/lib/dl_query_processing/dl_query_processing/compilation/formula_compiler.py", line 306, in wrapper with self._stage_manager.handle(field=field, stage=stage, collect=collect_errors): File "/usr/lib/python3.10/contextlib.py", line 153, in __exit__ self.gen.throw(typ, value, traceback) File "/data/mainrepo/lib/dl_query_processing/dl_query_processing/compilation/formula_compiler.py", line 256, in handle raise dl_query_processing.exc.FormulaHandlingError(*pass_on_errors, stage=stage, field=field) from err dl_query_processing.exc.FormulaHandlingError: Recursion detected in field The above exception was the direct cause of the following exception: Traceback (most recent call last): File "/data/mainrepo/lib/dl_api_lib/dl_api_lib/dataset/base_wrapper.py", line 368, in compile_and_translate_query compiled_query = query_compiler.make_compiled_query(query_spec=query_spec) File "/data/mainrepo/lib/dl_query_processing/dl_query_processing/compilation/query_compiler.py", line 209, in make_compiled_query select = self._make_select(query_spec) File "/data/mainrepo/lib/dl_query_processing/dl_query_processing/compilation/query_compiler.py", line 141, in _make_select formula = self._make_compiled_formula( File "/data/mainrepo/lib/dl_query_processing/dl_query_processing/compilation/query_compiler.py", line 106, in _make_compiled_formula formula = self._formula_compiler.compile_field_formula(field=field) File "/data/mainrepo/lib/dl_query_processing/dl_query_processing/compilation/formula_compiler.py", line 1115, in compile_field_formula formula_obj = self._compile_field_formula(field=field, collect_errors=collect_errors) File "/data/mainrepo/lib/dl_query_processing/dl_query_processing/compilation/formula_compiler.py", line 962, in _compile_field_formula return self._process_field_stage_final(field=field, collect_errors=collect_errors) File "/data/mainrepo/lib/dl_query_processing/dl_query_processing/compilation/formula_compiler.py", line 306, in wrapper with self._stage_manager.handle(field=field, stage=stage, collect=collect_errors): File "/usr/lib/python3.10/contextlib.py", line 153, in __exit__ self.gen.throw(typ, value, traceback) File "/data/mainrepo/lib/dl_query_processing/dl_query_processing/compilation/formula_compiler.py", line 256, in handle raise dl_query_processing.exc.FormulaHandlingError(*pass_on_errors, stage=stage, field=field) from err dl_query_processing.exc.FormulaHandlingError: Recursion detected in field The above exception was the direct cause of the following exception: Traceback (most recent call last): File "/data/mainrepo/lib/dl_api_lib/dl_api_lib/app/data_api/resources/dataset/base.py", line 381, in execute_query exec_info = ds_view.build_exec_info() File "/data/mainrepo/lib/dl_api_lib/dl_api_lib/dataset/view.py", line 200, in build_exec_info translated_multi_query = self.compile_and_translate_query(query_spec=self.query_spec) File "/data/mainrepo/lib/dl_api_lib/dl_api_lib/dataset/base_wrapper.py", line 377, in compile_and_translate_query raise dl_query_processing.exc.FormulaHandlingError(*err.errors) from err dl_query_processing.exc.FormulaHandlingError: Recursion detected in field