Skip to content

Commit 34751cf

Browse files
authored
docs: add nested loop example (#6948)
1 parent 4f96f81 commit 34751cf

File tree

1 file changed

+55
-0
lines changed

1 file changed

+55
-0
lines changed

core/src/main/java/io/kestra/plugin/core/flow/ForEach.java

+55
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,61 @@
139139
- sleep {{ parent.taskrun.value }}
140140
"""
141141
),
142+
@Example(
143+
full = true,
144+
title = """
145+
This example demonstrates processing data across nested loops of S3 buckets, years, and months. \
146+
It generates structured identifiers (e.g., `bucket1_2025_March`) by combining values from each loop level, \
147+
while accessing parent loop values like years and buckets, which can be useful for partitioned \
148+
storage paths or time-based datasets. The flow uses dynamic expressions referencing parent context.""",
149+
code = """
150+
id: loop_multiple_times
151+
namespace: company.team
152+
153+
inputs:
154+
- id: s3_buckets
155+
type: ARRAY
156+
itemType: STRING
157+
defaults:
158+
- bucket1
159+
- bucket2
160+
161+
- id: years
162+
type: ARRAY
163+
itemType: INT
164+
defaults:
165+
- 2025
166+
- 2026
167+
168+
- id: months
169+
type: ARRAY
170+
itemType: STRING
171+
defaults:
172+
- March
173+
- April
174+
175+
tasks:
176+
- id: buckets
177+
type: io.kestra.plugin.core.flow.ForEach
178+
values: "{{inputs.s3_buckets}}"
179+
tasks:
180+
- id: year
181+
type: io.kestra.plugin.core.flow.ForEach
182+
values: "{{inputs.years}}"
183+
tasks:
184+
- id: month
185+
type: io.kestra.plugin.core.flow.ForEach
186+
values: "{{inputs.months}}"
187+
tasks:
188+
- id: full_table_name
189+
type: io.kestra.plugin.core.log.Log
190+
message: |
191+
Full table name: {{parents[1].taskrun.value }}_{{parent.taskrun.value}}_{{taskrun.value}}
192+
Direct/current loop (months): {{taskrun.value}}
193+
Value of loop one higher up (years): {{parents[0].taskrun.value}}
194+
Further up (table types): {{parents[1].taskrun.value}}
195+
"""
196+
),
142197
}
143198
)
144199
public class ForEach extends Sequential implements FlowableTask<VoidOutput> {

0 commit comments

Comments
 (0)