使用tMap创建每次在Talend中运行作业的增量计数器

问题描述 投票:0回答:2

我想问一下如果在使用tMap组件时在Talend Data Integration中运行一个作业,如何在每一行创建一个特定的计数器

例如,这是每行中有5个数据具有0个计数器的结果

表动物 动物柜台 斑马0 斑马0 斑马0 斑马0 斑马0

当我使用tMap运行一个作业时,我想要这样的最终结果

表动物:最终结果 动物柜台 斑马0 斑马0 斑马0 斑马0 斑马0 斑马1 斑马1 斑马1 斑马1 斑马1

每次运行作业时,计数器上的字段总是递增一,数据总是插入

问候

database postgresql triggers talend
2个回答
0
投票

我看到的两个选项是:

  1. 使用存储在文件中的上下文变量。您需要在每个作业之前加载此文件并在完成之前更新它。在Tmap中,它看起来像这样:Integer.parseInt(context.Counter)+ 1
  2. 假设您要将记录加载到数据库中,请对最大计数器值执行查找并将其分配给TMap中的变量

0
投票

我想告诉你另一种做你想要的东西。

而不是使用tMap,我使用的是tJavaRow组件,结果将与您要求的相同,但是使用java代码实现。

这份工作从.csv读取通过tFileInputDelimited,它已经获得了下一个qazxsw poi。

下面你将看到一个tJavaRow组件,其中inside是java代码,最后是tlogRow组件来显示最终数据集。 - data -

代码里面的tJavaRow

Job Image

在这里你有output_row.Animal = input_row.Animal; /*Code generated according to input schema and output schema*/ if (context.counter == -1){ /*Conditional to hold just the first row interaction*/ context.counter=0; /*Initialization of the context variable (Counter)*/ output_row.Counter = context.counter; context.previousRecord = row1.Animal; /*Store the previous animal name*/ }else{ /*the java thread execution takes this way after the first interaction*/ if(row1.Animal.equals(context.previousRecord)){ /*compare the actual animal (row1.Animal) vs the previous one*/ output_row.Counter = context.counter; context.previousRecord = row1.Animal; }else{ context.counter++; output_row.Counter = context.counter; context.previousRecord = row1.Animal; } }

\(ToT)/

© www.soinside.com 2019 - 2024. All rights reserved.