简体   繁体   中英

Counting rows and saving the result in array (map) in Talend Open Studio

I have a job in Talend Open Studio. It supposed to be counting filtered input rows and storing it in adequate variable. The input file is csv. Later I use tMap to take only rows from selected day:

地图

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.

How do I implement an array in Talend which I can use inside tMap (I can use third party library)? Or is there some other way of doing that? I want to output those variables values to csv.

I would suggest you to write a user defined function and call it in tmap.. something like below

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)

I am assuming that you know how to write custom function 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 .

First, you would define a tMap with 24 columns on the right side. Row for row, this would only be filled if a condition is met, eg

TalendDate.getPartOfDate("HOUR",row1.Time_Stamp) == 0

into columnHour0 ,

TalendDate.getPartOfDate("HOUR",row1.Time_Stamp) == 1

into columnHour1 etc. up to columnHour23 .

Now connect the tAggregateRow and sum every hour column in the "Operations" box. This should result in only one row with all the counted hour entries.

您知道tflowmeter和tflowmetercatcher的组件吗?

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM