Unlock a world of possibilities! Login now and discover the exclusive benefits awaiting you.
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
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;
-----------------------------------------------------------------------
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
This worked for one of my usecase. Thanks!
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.
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
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;
-----------------------------------------------------------------------