• Index
  •  » Talend Open Studio for Data Integration » Usage, Operation
  •  » [resolved] tmap update current row with previosu row info

#1 2010-10-19 19:18:43

jdchaves
New member
Company: Indiciumm
Registered: 2010-10-19
Posts: 3

[resolved] tmap update current row with previosu row info

I have been unsuccessfully trying to use tmap as the last part of a process, which I will summarize as follows:

The process extracts information from a Cobol proprietary system, w/o table maps.

As a result the only information available is in the form of a print formatted report.

The Java process have different sub jobs that do: a) clean headings b) create a row counter c) separate info (positional rows) according to 4 criteria (agent info, customer info, invoice info, transactions info). d) create 4 tab delimited files e) reassemble the files as tab delimited using the row counter as guide.

All successful. I end with a file looking like this(summary):

Record    Record_type   Agent       Customer   Invoice    Transactions
1                 1              aaaa     
2                 2                             xxxxxx
3                 3                                             FV-001
4                 99                                                            00111
5                 99                                                            00228
6                  1             bbbb
7                  2                           yyyyyy   
8                  3                                            FV-002
9                  99                                                           00879

fields Record and Record_type are integer. Agent, Customer, Invoice and Transactions are String. Table is sorted by Agent, Customer and Invoice.

I have been unable to create a way in tmap to update the table rows in a way that keeps the first agent name while the agent name is null or empty string in the input flow and updates to the new agent name as input row agent is not null or not empty string:

tFileInputdelimited ---> tmap --> tFileOutputDelimited

Record    Record_type   Agent       Customer   Invoice    Transactions
1                 1              aaaa     
2                 2              aaaa          xxxxxx
3                 3              aaaa                         FV-001
4                 99            aaaa                                         00111
5                 99            aaaa                                         00228
6                 1              bbbb
7                 2              bbbb          yyyyyy   
8                 3              bbbb                        FV-002
9                 99            bbbb                                         00879

I have already searched throughout the forum and checked several related threads w/o success. Any help would be really appreciated smile.

Offline

#2 2010-10-19 19:29:24

JohnGarrettMartin
Member
Registered: 2009-01-07
Posts: 762

Re: [resolved] tmap update current row with previosu row info

You can use a tJavaRow to save the previous value of the column, and then apply that in a tMap:

tFileInputdelimited ---> tJavaRow --> tmap --> tFileOutputDelimited

in the tJavaRow, save the value to the globalMap:

if(input_row.Agent != null && !"".equals(input_row.Agent) ) {
    globalMap.put("Agent_prev_value",input_row.Agent);
}

Then in the tMap:
row2.Agent == null || "".equals(row2.Agent) ? (String)globalMap.get("Agent_prev_value") : row2.Agent

Offline

#3 2010-10-19 19:49:54

jdchaves
New member
Company: Indiciumm
Registered: 2010-10-19
Posts: 3

Re: [resolved] tmap update current row with previosu row info

John,
Thank you for your quick reply. In the tmap you would put the expression in the variables area or in the output row area?

Offline

#4 2010-10-19 20:05:05

jdchaves
New member
Company: Indiciumm
Registered: 2010-10-19
Posts: 3

Re: [resolved] tmap update current row with previosu row info

I found out. It is in the output row area. I am posting a complete update with pictures in order to explain in detail what John instructed. Once again thanks to John. smile smile.

All in all it works flawlesly.


Uploaded Images

Last edited by jdchaves (2010-10-19 23:02:18)

Offline

  • Index
  •  » Talend Open Studio for Data Integration » Usage, Operation
  •  » [resolved] tmap update current row with previosu row info

Board footer

Powered by FluxBB