Skip to main content
Announcements
Introducing Qlik Answers: A plug-and-play, Generative AI powered RAG solution. READ ALL ABOUT IT!
cancel
Showing results for 
Search instead for 
Did you mean: 
jerownimow
Contributor III
Contributor III

How to Map Dynamic Columns from an Input CSV file

I have exactly the same scenario as this article https://www.talend.com/resources/talend-dynamic-schema/.

The field positions on my input are varying so I have to come up of a way to have it fix every time I will receive the source file.

I followed the same procedure but I can't get the correct output. Looks like the issue is on the java code that was provided on the article.

Badly needed a help on this one.

Java Code:

String strArray[] = ((String)globalMap.get("row1.col_list")). split(";");

System.out.println("Target col list: "+((String)globalMap.get("row1.col_list")). split(";"));

String tarArray[] = ((String)globalMap.get("row1.col_list")). split(";");

Dynamic columns = row6.data;

String out="";

for (int i = 0; i < columns.getColumnCount(); i++)

{

DynamicMetadata columnMetadata = columns.getColumnMetadata(i);

String inp_col=columnMetadata.getName().toString();

String col_val=(String)row6.data.getColumnValue(inp_col);

for (int j = 0; j < columns.getColumnCount(); j++)

{

if (inp_col.equals(strArray[j].toString()))

{

tarArray[j]=col_val;

}

}

}

for (int t=0; t < columns.getColumnCount(); t++)

{

if (t ==0)

out=tarArray[0];

else

out=out+";"+tarArray[t];

}

row5.data=out;

Set-up on Database:

0695b00000Wtb8oAAB.png

Output:

*Strange part is that when the col_list was split, it has a weird output:

0695b00000Wtb8yAAB.png

0695b00000Wtb9cAAB.png

1 Solution

Accepted Solutions
jerownimow
Contributor III
Contributor III
Author

Thank you, @Shicong Hong​. Looks good now.

It looks like I changed the Field separator to hyphen so it would appear on the log that the separator is semi-colon which should not be.

 

I will try this on the actual data.

0695b00000Wth0vAAB.png

View solution in original post

3 Replies
Anonymous
Not applicable

Hi​

I just tested the Java code with studio 8 and it works, one thing you need to pay attention to is that the input file should contain the column name in the first line if you are using Dynamic schema to read it, eg:

name;id

AL;1

Mike;2

 

Regards

Shong

jerownimow
Contributor III
Contributor III
Author

Thank you, @Shicong Hong​. Looks good now.

It looks like I changed the Field separator to hyphen so it would appear on the log that the separator is semi-colon which should not be.

 

I will try this on the actual data.

0695b00000Wth0vAAB.png

Anonymous
Not applicable

@Jerome Sabareza​ , glad to hear that you get it working now. Feel free to post questions if you have any issues.

 

Regards

Shong