[BUGFIX] Fix recursion limit when applying large reduce functions
This commit is contained in:
parent
b8fb119f21
commit
ff54876bda
3 changed files with 62 additions and 16 deletions
|
|
@ -232,20 +232,25 @@ class BuiltInFunction(Function, BuiltInFunctionType):
|
||||||
if len(lambda_array.value) == 1:
|
if len(lambda_array.value) == 1:
|
||||||
return lambda_array.value[0]
|
return lambda_array.value[0]
|
||||||
|
|
||||||
reduced = self._instantiate_lambda(
|
reduced: Resolvable = self._resolve_argument_type(
|
||||||
lambda_function_name=lambda_function_name,
|
arg=self._instantiate_lambda(
|
||||||
args=[lambda_array.value[0], lambda_array.value[1]],
|
lambda_function_name=lambda_function_name,
|
||||||
)
|
args=[lambda_array.value[0], lambda_array.value[1]],
|
||||||
for idx in range(2, len(lambda_array.value)):
|
),
|
||||||
reduced = self._instantiate_lambda(
|
|
||||||
lambda_function_name=lambda_function_name, args=[reduced, lambda_array.value[idx]]
|
|
||||||
)
|
|
||||||
|
|
||||||
return self._resolve_argument_type(
|
|
||||||
arg=reduced,
|
|
||||||
resolved_variables=resolved_variables,
|
resolved_variables=resolved_variables,
|
||||||
custom_functions=custom_functions,
|
custom_functions=custom_functions,
|
||||||
)
|
)
|
||||||
|
for idx in range(2, len(lambda_array.value)):
|
||||||
|
reduced = self._resolve_argument_type(
|
||||||
|
arg=self._instantiate_lambda(
|
||||||
|
lambda_function_name=lambda_function_name,
|
||||||
|
args=[reduced, lambda_array.value[idx]],
|
||||||
|
),
|
||||||
|
resolved_variables=resolved_variables,
|
||||||
|
custom_functions=custom_functions,
|
||||||
|
)
|
||||||
|
|
||||||
|
return reduced
|
||||||
|
|
||||||
def resolve(
|
def resolve(
|
||||||
self,
|
self,
|
||||||
|
|
|
||||||
|
|
@ -19,12 +19,14 @@ class Scriptable(ABC):
|
||||||
Shared class between Entry and Overrides to manage their underlying Script.
|
Shared class between Entry and Overrides to manage their underlying Script.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
def __init__(self):
|
_BASE_SCRIPT: Script = Script(
|
||||||
self.script = Script(
|
ScriptUtils.add_sanitized_variables(
|
||||||
ScriptUtils.add_sanitized_variables(
|
dict(copy.deepcopy(VARIABLE_SCRIPTS), **copy.deepcopy(CUSTOM_FUNCTION_SCRIPTS))
|
||||||
dict(copy.deepcopy(VARIABLE_SCRIPTS), **copy.deepcopy(CUSTOM_FUNCTION_SCRIPTS))
|
|
||||||
)
|
|
||||||
)
|
)
|
||||||
|
)
|
||||||
|
|
||||||
|
def __init__(self):
|
||||||
|
self.script = copy.deepcopy(Scriptable._BASE_SCRIPT)
|
||||||
self.unresolvable: Set[str] = copy.deepcopy(UNRESOLVED_VARIABLES)
|
self.unresolvable: Set[str] = copy.deepcopy(UNRESOLVED_VARIABLES)
|
||||||
|
|
||||||
def update_script(self) -> None:
|
def update_script(self) -> None:
|
||||||
|
|
|
||||||
|
|
@ -58,6 +58,45 @@ class TestArrayFunctions:
|
||||||
output = single_variable_output("{%array_reduce([1, 2, 3, 4], %add)}")
|
output = single_variable_output("{%array_reduce([1, 2, 3, 4], %add)}")
|
||||||
assert output == 10
|
assert output == 10
|
||||||
|
|
||||||
|
def test_array_reduce_complex(self):
|
||||||
|
output = (
|
||||||
|
Script(
|
||||||
|
{
|
||||||
|
"%custom_get": """{
|
||||||
|
%if(
|
||||||
|
%bool(siblings_array),
|
||||||
|
%array_apply_fixed(
|
||||||
|
siblings_array,
|
||||||
|
%string($0),
|
||||||
|
%map_get
|
||||||
|
)
|
||||||
|
[]
|
||||||
|
)
|
||||||
|
}""",
|
||||||
|
"siblings_array": """{
|
||||||
|
[
|
||||||
|
{'upload_date': '20200101'},
|
||||||
|
{'upload_date': '19940101'}
|
||||||
|
]
|
||||||
|
}""",
|
||||||
|
"upload_date": "20230101",
|
||||||
|
"output": """{
|
||||||
|
%array_reduce(
|
||||||
|
%if_passthrough(
|
||||||
|
%custom_get('upload_date'),
|
||||||
|
[ upload_date ]
|
||||||
|
),
|
||||||
|
%max
|
||||||
|
)
|
||||||
|
}""",
|
||||||
|
}
|
||||||
|
)
|
||||||
|
.resolve(update=True)
|
||||||
|
.get("output")
|
||||||
|
.native
|
||||||
|
)
|
||||||
|
assert output == "20200101"
|
||||||
|
|
||||||
def test_array_enumerate(self):
|
def test_array_enumerate(self):
|
||||||
output = (
|
output = (
|
||||||
Script(
|
Script(
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue