Data from 1 Column to be separated in Multiple Columns

Input file
col1
1
2
3
4
5
6
7
8
output file
col1 col2 col3 col4
1 2 3 4
5 6 7 8
How to achieve this?

Showing Answers 1 - 18 of 18 Answers

Nitin Patil

  • Apr 5th, 2018
 

created for 3 columns.
temp :: rollup(temp, in) =
begin
temp.rec :: if(temp.ind != 0)string_concat(temp.rec,"|",in.data) else temp.rec;
temp.ind :: temp.ind + 1;
end;
type temporary_type=record
decimal("") ind;
string("") rec;
end; /*Temporary variable*/
temp :: initialize(in) =
begin
temp.ind :: 0;
temp.rec :: in.data;

end;
out :: finalize(temp, in) =
begin
out.col1 :: (string_split(temp.rec,"|"))[0];
out.col2 ::(string_split(temp.rec,"|"))[1];
out.col3 :: (string_split(temp.rec,"|"))[2];
end;
out :: key_change(in1, in2) =
begin
out :: (next_in_sequence() % 3) ==0;
end;

  Was this answer useful?  Yes

Sai

  • May 24th, 2018
 

In this scenario, we need to take redefine component and provide the delimiter as "
",then will get this answer.
example:
record
decimal("|") number;
end;
then we have to change it into delimiter as
record
decimal("
") number;
end;

  Was this answer useful?  Yes

Avisek

  • May 28th, 2018
 

input file dml:
record
string("
") col1;
end
output file dml
record
string(",")col1;
string(",")col2;
string(",")col3;
string("
")col4;
end
use a rollup with key_change fn
let int count = 0;
let string("x01") val_a=;
let string("x01") val_b=;
let string("x01") val_c=;
out :: key_change(in1,in2) =
begin
count = count +1 ;
if ( count ==1 ) val_a=in1.col1;
if( count ==2 ) val_b=in1.col1;
if( count ==3) val_c=in1.col1;
if ( count >=4 ) count = 0 ;
out :: count == 0;
end;
out :: rollup(in) =
begin
out.col1=val_a;
out.col2=val_b;
out.col3=val_c;
out.col4=in.col1;
end;

  Was this answer useful?  Yes

Shrinidhi

  • May 6th, 2019
 

Use Rollup with key change function and specify the expression in transform as:
type temporary_type=record
decimal("x01") a=0;
decimal("x01") b=0;
decimal("x01") c=0;
decimal("x01") d=0;
end;
/*Do computation*/
temp::rollup(temp,in)=
begin
temp.a :: if(in.col1%4 == 1 ) in.col1 else temp.a;
temp.b :: if(in.col1%4 == 2 ) in.col1 else temp.b;
temp.c :: if(in.col1%4 == 3 ) in.col1 else temp.c;
temp.d :: in.col1;
end;
/* This function is optional. */
/*Determine if key changed*/
out::key_change(in1,in2)=
begin
out :: if(in1.col1%4==0) 1 else 0;
end;
out::finalize(temp,in)=
begin
out.col1 :: temp.a;
out.col2 :: temp.b;
out.col3 :: temp.c;
out.col4 :: temp.d;
end;

  Was this answer useful?  Yes

Mahesh

  • May 26th, 2021
 

Redefine component with output dml as
record
decimal("x00") col1 = 0;
decimal("x00") col2= 0;
decimal("x00") col3 = 0;
decimal("x00") col4 = 0;
end;

  Was this answer useful?  Yes

Anand Kishore

  • Oct 7th, 2022
 

Use round robin with sequence 3

  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