Do not input private or sensitive data. View Qlik Privacy & Cookie Policy.
Skip to main content

Announcements
Qlik Open Lakehouse is Now Generally Available! Discover the key highlights and partner resources here.
cancel
Showing results for 
Search instead for 
Did you mean: 
Anonymous
Not applicable

How to extract and map dynamic fields in tmap?

Hi All,

 

I have taken multiple files with different schema using tFileList and passed it through tFiledelimitedInput  using dynamic schema. As i can see that by using the dynamic schema i get all the columns in a single column as a string separated by some delimiter. I want to extract the columns from the dynamic field and use it in tmap for joining or filtering the data further. How can i get those dynamic values in the form of schema. I also tried tExtractDynamicFields but for that we need the target schema but in my case the target schema will be same as the input schema which is dynamic and keeps changing. I need to compare those fields with another file.

 

Regards

Pragyawan

Labels (3)
1 Solution

Accepted Solutions
ravi999
Contributor III
Contributor III

 

Use the following code in tjavarow . Replace field with ur column name.Then connect to tmap and tfileoutputdelimited.Check the include headers option . u will get the field name and field name in the target file

----------------------------------------------------------
Dynamic columns = row1.dynamic;

for (int i = 0; i < columns.getColumnCount(); i++) {
if(columns.getColumnMetadata(i).getName().equalsIgnoreCase("field")){
DynamicMetadata columnMetadata = columns.getColumnMetadata(i);
String field = Relational.ISNULL(columns.getColumnValue(i))?"Ravi":columns.getColumnValue(i).toString();
output_row.newColumn = field;
System.out.println(columnMetadata.getName() + ": " + field);
}
}

output_row.dynamic = input_row.dynamic;

 -----------------------------------------------------------------------

 

View solution in original post

6 Replies
Anonymous
Not applicable
Author

Hello,

Could you please let us know if this related topic helps?

https://community.talend.com/t5/Design-and-Development/tMap-with-Dynamic-schema/m-p/43409

Best regards

Sabrina

ravi999
Contributor III
Contributor III

This worked for one of my usecase. Thanks!

Anonymous
Not applicable
Author

Hello @pragyawan

Does it work for your use case?

Best regards

Sabrina

Anonymous
Not applicable
Author

I can now extract the field name and value in tjavarow with the help of that code but now i need to write those field name and values in a file which i am facing trouble with.

Anonymous
Not applicable
Author

I have a destination file having only 2 columns i.e. field_name and Field_value and i want to store the extracted value in this file but i am not getting this. i am only able to get the last value of the iteration in the context variable

ravi999
Contributor III
Contributor III

 

Use the following code in tjavarow . Replace field with ur column name.Then connect to tmap and tfileoutputdelimited.Check the include headers option . u will get the field name and field name in the target file

----------------------------------------------------------
Dynamic columns = row1.dynamic;

for (int i = 0; i < columns.getColumnCount(); i++) {
if(columns.getColumnMetadata(i).getName().equalsIgnoreCase("field")){
DynamicMetadata columnMetadata = columns.getColumnMetadata(i);
String field = Relational.ISNULL(columns.getColumnValue(i))?"Ravi":columns.getColumnValue(i).toString();
output_row.newColumn = field;
System.out.println(columnMetadata.getName() + ": " + field);
}
}

output_row.dynamic = input_row.dynamic;

 -----------------------------------------------------------------------