One Star

Adding row1 and row2 then row2 and and row3

Hi Guys,
I am new to talend:
I have single column table with the following data:
1
2
3
4
I want to output it as two column
First Column, Second Column
1,2
2,3
3,4
Thanks
3 REPLIES
Moderator

Re: Adding row1 and row2 then row2 and and row3

Hi,
You can use tMap to achieve your goal.
Pleasee see my screenshots
Best regards
Sabrina
--
Don't forget to give kudos when a reply is helpful and click Accept the solution when you think you're good with it.
Employee

Re: Adding row1 and row2 then row2 and and row3

I think xdshi has misunderstood here. What you need to do is use the functionality in the variables of the tMap. The variables are processed from the top down in order. This allows you to "store" values from the last row to be used in the next row. I have put together an example and have included a screenshot of the tMap below....

Essentially you create 4 variables. The first two to store the column values that you want to output, the other two to keep a row count and to calculate a modulus of the count. You assign the top variable to be the first column value. This variable is supplied the value of the second variable value (which on the first row will be null as the second variable will not have received any values by that point). The second variable (*secondCol") is given the value of the column data you want to use. For every row that comes in, the "SecondCol" variable is assigned a new value and the "FirstCol" variable is assigned the last value held by the "SecondCol" variable. 
On the output we use the modulus operator. We only want to output every other row. So if 100 rows of data come in, we only want to output 50 rows. We use the "modulus" variable to filter this. 
When the job is run, if you have the following values going in.....
a
b
c
d
e
f
..... you will get the following out.....
a,b
c,d
e,f
You will need to add some extra logic to prevent an odd number of rows having the last row thrown away. But I am sure you can figure that out :-)
Employee

Re: Adding row1 and row2 then row2 and and row3

I just noticed that you want to have the following output from a,b,c,d,e...
a,b
b,c
c,d
d,e
e,f
To do this, just leave out the modulus filter that I used in my example.