Normalize multiple columns

Four Stars

Normalize multiple columns

Hi,

 

Need to normalize multiple columns.

Below is my data

 

ID| Col1| Col2

1 |a,b,c |d,e,f

|g,h,i |j,k,l

 

Expected result

ID| Col1| Col2

1 |a | d

1 |b | e

1 |c | f

|g | j

2 |h | k

2 | i | l

 

Below is my try,

String[] value1 = input_row.newColumn.split(",");
String[] value2 = input_row.newColumn1.split(",");
int index = input_row.dummy-1;
for(int i= 0; i<value1.length;i++){
for(int j= i; j<=i;j++){
	System.out.println(" Id="+input_row.dummy+"  Col1="+value1[i]+"  Col2="+value2[j]);	

output_row.dummy = input_row.dummy;
output_row.newColumn = value1[i];
output_row.newColumn1 = value2[j];		
	}
}

While printing the statement,

System.out.println(" Id="+input_row.dummy+"  Col1="+value1[i]+"  Col2="+value2[j]);

array is providing four results as expected.

But while passing to the output_row, only the last array is passed. Only one entry is avaliable in the result.

Could any one help out?

 

Below is the flow,

Inpit - > tjavarow -> output

Twelve Stars

Re: Normalize multiple columns

you have to use tjavaFlex.

Francois Denis

Tag as "solved" for others! Kudos to thanks!

Twelve Stars

Re: Normalize multiple columns

tJava run for each row you need 1row --> 3 row !

Francois Denis

Tag as "solved" for others! Kudos to thanks!

Twelve Stars

Re: Normalize multiple columns

did you want 9 row?
1 |a | d
1 |b | d
1 |c | d
1 |a | e
1 |b | e
1 |c | e
1 |a | f
1 |b | f
1 |c | f
in this case you can use tNormalize.
Regards,

Francois Denis

Tag as "solved" for others! Kudos to thanks!

Seven Stars

Re: Normalize multiple columns

Hello,

Your try is upto mark, Make use of tmap component to generate the sequence and use as index and then assign to col2.

 

Tjavarow logic:

 

String[] values2 = input_row.COL2.split(",");
int index = input_row.seq - 1;

output_row.ID = input_row.ID;
output_row.COL1 = input_row.COL1;
output_row.COL2 = values2[index];

 

 

normalize.PNG

 

Hope this helps your purpose.

 

Regards

Ganshyam

Three Stars

Re: Normalize multiple columns

It works... Great

Four Stars

Re: Normalize multiple columns

Hi Ganshyam,

 

I tried the java code you had provided in tjavarow using the following steps but i am getting 


java.lang.ArrayIndexOutOfBoundsException: -1

i am also attaching the screenshots for the tmap and tjavarow components which i have used.

 

Thanks & Regards

 

2019 GARNER MAGIC QUADRANT FOR DATA INTEGRATION TOOL

Talend named a Leader.

Get your copy

OPEN STUDIO FOR DATA INTEGRATION

Kickstart your first data integration and ETL projects.

Download now

What’s New for Talend Summer ’19

Watch the recorded webinar!

Watch Now

Best Practices for Using Context Variables with Talend – Part 4

Pick up some tips and tricks with Context Variables

Blog

How Media Organizations Achieved Success with Data Integration

Learn how media organizations have achieved success with Data Integration

Read

Tutorial

Introduction to Talend Open Studio for Data Integration.

Watch