Talend - 如何循环tmap的输出

时间:2017-06-19 15:14:29

标签: talend

我有一个要求是我从tmap获得 min_age max_age 。我想循环遍历这两个输入,即从 min_age max_age ,并在每次迭代值时将记录插入到cassandra表中

例如 - min_age 为10且 max_age 为15,然后我想在cassandra表中插入10,11,12,13,14和15的记录。

我尝试找出一个解决方案,但无法成功。 tloop组件似乎是最合适的,但不幸的是tmap没有迭代器连接器。

任何人都可以帮到这里。

2 个答案:

答案 0 :(得分:1)

你可以有这样一个subjob:[inputflow] --> tFlowToIterate-->tLoop-->tFixedFlowInput--> DBInsert

在tLoop中,只需使用由tFlowToIterate构造的globalMap变量来填充“from”和“to”字段(在这些字段中使用ctrl空格来查找由tFlowToIterate构造的变量)。 在tFixedFlow中,您可以构建要插入的数据:它是您的tloop的当前值:((Integer)globalMap.get("tLoop_1_CURRENT_VALUE"))

答案 1 :(得分:1)

您可以使用tFlowToIterate将输入流行转换为迭代。然后在每个迭代行上添加一个循环,以进一步迭代最小/最大值。然后,您可以使用tIteratetoFlow将迭代转换回流。

这是一份测试工作:

enter image description here

这就是我设置tRowGenerator以尝试模拟输入流的方法(如果需要,可以使用多行):

enter image description here

循环的组件设置:

enter image description here

用于将迭代转换回流程的组件设置:

enter image description here

这是日志输出:

Starting job testjob at 11:35 19/06/2017.

[statistics] connecting to socket on port 3914
[statistics] connected
10
11
12
13
14
15
[statistics] disconnected
Job testjob ended at 11:35 19/06/2017. [exit code=0]