[英]Counting rows and saving the result in array (map) in Talend Open Studio
I have a job in Talend Open Studio. 我在Talend Open Studio工作。 It supposed to be counting filtered input rows and storing it in adequate variable.
它应该对已过滤的输入行进行计数并将其存储在适当的变量中。 The input file is csv.
输入文件为csv。 Later I use tMap to take only rows from selected day:
稍后,我使用tMap仅选择所选日期的行:
And then I'm stuck. 然后我被卡住了。 I just need an array (or array map?) with 24hrs (values 0-23) and increment them everytime the time matches.
我只需要一个具有24小时(值0-23)的数组(或数组映射?),并在每次时间匹配时递增它们。
How do I implement an array in Talend which I can use inside tMap (I can use third party library)? 如何在Talend中实现可在tMap内部使用的数组(可以使用第三方库)? Or is there some other way of doing that?
还是有其他方法可以做到这一点? I want to output those variables values to csv.
我想将这些变量值输出到csv。
I would suggest you to write a user defined function and call it in tmap.. something like below 我建议您编写一个用户定义的函数并在tmap中调用它。
public static String loop_cntr(Int cntr){
String ARR = "" ;
for(int i=0;i<cntr;i++){
<your logic to build the array>
ARR = ARR + cntr (something like this)
}
return ARR
)
now you can use this function in tMap like loop_cntr(20) 现在您可以在tMap中使用该功能,例如loop_cntr(20)
I am assuming that you know how to write custom function Code-->Routines. 我假设您知道如何编写自定义函数Code-> Routines。 Please let me know how it goes.
请让我知道如何。
If I understand your description correctly, you want to sum all columns which do have a specific hour value. 如果我正确理解了您的描述,则希望对确实具有特定小时值的所有列求和。 You could use a combination of tMap and tAggregateRow .
您可以结合使用tMap和tAggregateRow 。
First, you would define a tMap with 24 columns on the right side. 首先,您将定义一个在右侧具有24列的tMap。 Row for row, this would only be filled if a condition is met, eg
一行一行,只有在满足条件的情况下才可以填写,例如
TalendDate.getPartOfDate("HOUR",row1.Time_Stamp) == 0
into columnHour0 , 进入columnHour0 ,
TalendDate.getPartOfDate("HOUR",row1.Time_Stamp) == 1
into columnHour1 etc. up to columnHour23 . 进入columnHour1等,直到columnHour23 。
Now connect the tAggregateRow and sum every hour column in the "Operations" box. 现在,连接tAggregateRow并在“操作”框中的“每小时”列进行求和。 This should result in only one row with all the counted hour entries.
这样只会导致所有已计算小时数条目的一行。
您知道tflowmeter和tflowmetercatcher的组件吗?
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.