• Index
  •  » Talend Open Studio for Data Integration » Usage, Operation
  •  » [resolved] How to separate rows in groups of x although other group have same id

#1 2012-07-11 09:45:48

quim.montal
New member
Registered: 2012-07-11
Posts: 4

[resolved] How to separate rows in groups of x although other group have same id

Hi, im new in talend and i got to this problem

I have a table like this one:

id_truck action time

0005    EP       01/02/2003 13:10:00
0005    ET       01/02/2003 14:10:00
0005    ST       01/02/2003 15:10:00
0005    SP       01/02/2003 16:10:00
0005    EP       01/02/2003 17:10:00
0005    ET       01/02/2003 17:50:00
0005    ST       01/02/2003 18:10:00
0005    SP       01/02/2003 19:10:00

and i need a table like this

id_op id_truck EP                                 ET                                   ST   SP
1       0005       01/02/2003 13:10:00     01/02/2003 14:10:00        ...   ....
2       0005       01/02/2003 17:10:00     01/02/2003 17:50:00        ...   ....

so that i have to do it with tpivot to change rows per columns but if i do that, it does a group by of truck number 0005 so that one of the registers got erased. Doesn't work making a new column with diferent id by sequence number on tmap before using tpivot because then it separates all the rows and thats not what i want. I just can think of making a loop so that every 4 rows it makes a new table and then do tpivot to all the tables and put them together by another tmap but i cant find no way of doing that...

Thanks a lot in advance ^^

Offline

#2 2012-07-11 09:57:33

pedro
Member
Registered: 2011-11-17
Posts: 3682

Re: [resolved] How to separate rows in groups of x although other group have same id

Hi

Code:

I just can think of making a loop so that every 4 rows it makes a new table and then do tpivot to all the tables and put them together by another tmap but i cant find no way of doing that...

You can add a context variable into this job(e.g. sequence).
Part of your job should be like this.
tPivotToColumnsDelimited--OnComponentOk-->tJava
tPivotToColumnsDelimited: modify the file name "E:/TOS_DI-r75139-V5.0.1NB/workspace/out"+context.sequence+".csv"
tJava: context.sequence++

Then create a subjob to extract all data from each csv file into tHashOutput or tFileOutputDelimited.
tFileList--Iterate-->tFileInputDelmited--main-->tHashOutput(append)

Regards,
Pedro


Only Paranoid Survive.

Offline

#3 2012-07-11 10:29:57

quim.montal
New member
Registered: 2012-07-11
Posts: 4

Re: [resolved] How to separate rows in groups of x although other group have same id

Hi pedro

Thanks for your reply, i'll try it.

Regards,

Quim

Offline

#4 2012-07-11 12:37:51

quim.montal
New member
Registered: 2012-07-11
Posts: 4

Re: [resolved] How to separate rows in groups of x although other group have same id

Hi again Pedro,

Finally I didn't do as you told, I didn't understand pretty much of all that components, I have just worked by the time with oracle objects and tagregate :S To solve my problem I created to context variables and on tmap i wrote this code

context.cont++;
if (context.cont==5){
    context.separator++;
    context.cont=0;
};     
     
Now it works great for first 2 rows but it gots crazy from the third, it erases some data and puts other in thw wrong row, do you know what the problem could be? Thanks in advance.

Regards,

Quim

Offline

#5 2012-07-11 12:45:53

quim.montal
New member
Registered: 2012-07-11
Posts: 4

Re: [resolved] How to separate rows in groups of x although other group have same id

Sorry it was an error of variable

Regards,

Quim

Offline

  • Index
  •  » Talend Open Studio for Data Integration » Usage, Operation
  •  » [resolved] How to separate rows in groups of x although other group have same id

Board footer

Powered by FluxBB