How to convert rows into columns and column into rows in abinitio

I have a scenario:
Input file
Col1 col2
1 A
2 B
3 C
4 D
and desired output should be like below:
col1 1 2 3 4
col2 A B C D
Could you please help

Showing Answers 1 - 21 of 21 Answers

reddy

  • May 19th, 2015
 

use normalize component

  Was this answer useful?  Yes

phani

  • Jul 9th, 2015
 

By using pivot option

  Was this answer useful?  Yes

Arpit Jain

  • Apr 19th, 2016
 

Using normalize is best way but you can use string functions also to solve this sought of issues.

  Was this answer useful?  Yes

Roshan D

  • Jun 21st, 2016
 

Use Rollup with function Concatenation(in.col1) and concatenation(in.col2) with key as {}

  Was this answer useful?  Yes

gangadhar c

  • Aug 1st, 2016
 

Meta pivote is the best component to use rows into columns, columns into rows.

  Was this answer useful?  Yes

sonalika

  • Sep 21st, 2017
 

step 1. use normalize - lenght=2 and set indicator c1 for 1st records and c2 for 2nd records. op would be -
c1 1
colum1 column2
c2 A
c1 2
c2 B
c1 3
c2 C
step 2 - use rollup where key {colum1}. In rlp function use vector_append(column2). op would be -
col1 1 2 3
col2 A B C

  Was this answer useful?  Yes

Sudharshan

  • Nov 13th, 2017
 

1. Use normalize or meta pivot to convert the rows into columns or columns into rows.
2. If you use normalize, set index =2 and then write the below code in normalize function
out :: length(in) =
begin
out :: 2;
end;
out :: normalize(in, index) =
begin
out.field_name :1: if(index==0) "col1";
out.field_value :1: if(index==0) in.col1;
out.field_name :2: if(index==1) "col2";
out.field_value :2: if(index==1) in.col2;
end;
Normalize output will be as shown below.
field_name field_value
col1 1
col1 2
col1 3
col1 4
col2 A
col2 B
col2 C
col2 D
3. Use rollup component to create vector for field value by taking field_name as key.
out :: rollup(in) =
begin
out.field_name :: in.field_name;
out.field_value :: accumulation(in.field_value);
end;
Rollup output will be as shown below.
field_name field_value.field_value
col2 A
B
C
D
col1 1
2
3
4
4. Use reformat to convert the field value vector values into single row using string_join function
out :: reformat(in) =
begin
out.field_name :: in.field_name;
out.field_value:: string_join(in.field_value," ");
end;
final output will be as shown below
field_name field_value
col2 A B C D
col1 1 2 3 4

  Was this answer useful?  Yes

Give your answer:

If you think the above answer is not correct, Please select a reason and add your answer below.

 

Related Answered Questions

 

Related Open Questions