Open giovanni-prestipino opened 5 months ago
Maybe the problem is that the loop parameter should be passed to the Map as a side input:
def main():
with beam.Pipeline() as p:
p_f = p | beam.Create([1, 2, 3, 4, 5])
for i in range(0, 3):
p_f = p_f | f"{i}" >> beam.Map(lambda x, k: x + k, k=i)
p_f | beam.Map(print)
if __name__ == "__main__":
main()
``
For your first example, I think this is expected. the pipeline won't be executed after the entire pipeline is construct. After that, the variable i
has the final value, which will be passed in for the final execution.
What happened?
When using for loop, to execute PTransform, all loops seem to use the last value of an iterator.
As a result of the code, I expected to print
But I got:
Moreover, I found a workaround defining a new sum function:
I am using the following versions:
apache_beam==2.55.0
python==3.10.12
Issue Priority
Priority: 2 (default / most bugs should be filed as P2)
Issue Components