【问题标题】:Create Increment Counter Everytime Running A Job In Talend Using tMap每次使用 tMap 在 Talend 中运行作业时创建增量计数器
【发布时间】:2019-04-22 07:10:36
【问题描述】:

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

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

餐桌动物
动物计数器
斑马 0
斑马 0
斑马 0
斑马 0
斑马 0

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

餐桌动物:最终结果
动物计数器
斑马 0
斑马 0
斑马 0
斑马 0
斑马 0
斑马 1
斑马 1
斑马 1
斑马 1
斑马 1

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

问候

【问题讨论】:

    标签: database postgresql triggers talend


    【解决方案1】:

    我看到的两个选项是:

    1. 使用存储在文件中的上下文变量。您需要在每个作业之前加载此文件并在完成之前对其进行更新。在 Tmap 中它看起来像这样: Integer.parseInt(context.Counter) + 1

    2. 假设您正在将记录加载到数据库中,请查找最大计数器值并将其分配给 TMap 中的变量

    【讨论】:

    • 从最终结果中选择动物,max(counter)+1,然后对其进行 tMap。
    【解决方案2】:

    我想向您展示一种替代方法来满足您的需求。

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

    作业正在通过 tFileInputDelimited 从 .csv 读取,它得到了下一个 data

    接下来你会看到一个 tJavaRow 组件,里面是 java 代码,最后是一个 tlogRow 组件来显示最终的数据集。 - Job Image -

    tJavaRow 内的代码

    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;
          }
    }
    

    这里有the image of the final result

    \(ToT)/

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2019-07-30
      • 2011-01-20
      • 1970-01-01
      • 1970-01-01
      • 2023-03-28
      • 2020-02-23
      相关资源
      最近更新 更多