From 34751cfdd4b80273dc94f8112ddfdc8dfd052873 Mon Sep 17 00:00:00 2001 From: Anna Geller Date: Sun, 26 Jan 2025 21:56:44 +0100 Subject: [PATCH] docs: add nested loop example (#6948) --- .../io/kestra/plugin/core/flow/ForEach.java | 55 +++++++++++++++++++ 1 file changed, 55 insertions(+) diff --git a/core/src/main/java/io/kestra/plugin/core/flow/ForEach.java b/core/src/main/java/io/kestra/plugin/core/flow/ForEach.java index 88c0de70e0c..ba29d8978bb 100644 --- a/core/src/main/java/io/kestra/plugin/core/flow/ForEach.java +++ b/core/src/main/java/io/kestra/plugin/core/flow/ForEach.java @@ -139,6 +139,61 @@ - sleep {{ parent.taskrun.value }} """ ), + @Example( + full = true, + title = """ + This example demonstrates processing data across nested loops of S3 buckets, years, and months. \ + It generates structured identifiers (e.g., `bucket1_2025_March`) by combining values from each loop level, \ + while accessing parent loop values like years and buckets, which can be useful for partitioned \ + storage paths or time-based datasets. The flow uses dynamic expressions referencing parent context.""", + code = """ + id: loop_multiple_times + namespace: company.team + + inputs: + - id: s3_buckets + type: ARRAY + itemType: STRING + defaults: + - bucket1 + - bucket2 + + - id: years + type: ARRAY + itemType: INT + defaults: + - 2025 + - 2026 + + - id: months + type: ARRAY + itemType: STRING + defaults: + - March + - April + + tasks: + - id: buckets + type: io.kestra.plugin.core.flow.ForEach + values: "{{inputs.s3_buckets}}" + tasks: + - id: year + type: io.kestra.plugin.core.flow.ForEach + values: "{{inputs.years}}" + tasks: + - id: month + type: io.kestra.plugin.core.flow.ForEach + values: "{{inputs.months}}" + tasks: + - id: full_table_name + type: io.kestra.plugin.core.log.Log + message: | + Full table name: {{parents[1].taskrun.value }}_{{parent.taskrun.value}}_{{taskrun.value}} + Direct/current loop (months): {{taskrun.value}} + Value of loop one higher up (years): {{parents[0].taskrun.value}} + Further up (table types): {{parents[1].taskrun.value}} + """ + ), } ) public class ForEach extends Sequential implements FlowableTask {