Justin Essert
03/17/2021, 8:33 PMfrom prefect import Flow, task
@task
def add_ten(x):
return x + 10
with Flow('iterated map') as flow:
mapped_result = add_ten.map([1, 2, 3])
mapped_result_2 = add_ten.map(mapped_result)
This allows you to map the first add_ten call to the three elements in the list, and then to map the second add_ten call to the three outputs from the first call.
Instead of returning a single int from the add_ten function, we want it to return an list of ints and continue to fan-out (to 6 elements in the example below):
@task
def add_ten(x):
return [x + 10, x]
with Flow('iterated map') as flow:
mapped_result = add_ten.map([1, 2, 3])
mapped_result_2 = add_ten.map(mapped_result)
Is this something that is supported by Prefect, or can you only have 1 fan-out per map/reduce?Jim Crist-Harif
03/17/2021, 8:35 PMJim Crist-Harif
03/17/2021, 8:36 PMfrom prefect import flatten
@task
def add_ten(x):
return [x + 10, x]
with Flow('iterated map') as flow:
mapped_result = add_ten.map([1, 2, 3])
mapped_result_2 = add_ten.map(flatten(mapped_result))
Justin Essert
03/17/2021, 8:39 PM