How to extract and map dynamic fields in tmap?

Five Stars

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


Accepted Solutions
Six Stars

Re: How to extract and map dynamic fields in tmap?

 

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


All Replies
Moderator

Re: How to extract and map dynamic fields in tmap?

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

--
Don't forget to give kudos when a reply is helpful and click Accept the solution when you think you're good with it.
Six Stars

Re: How to extract and map dynamic fields in tmap?

This worked for one of my usecase. Thanks!

Moderator

Re: How to extract and map dynamic fields in tmap?

Hello @pragyawan

Does it work for your use case?

Best regards

Sabrina

--
Don't forget to give kudos when a reply is helpful and click Accept the solution when you think you're good with it.
Five Stars

Re: How to extract and map dynamic fields in tmap?

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.

Five Stars

Re: How to extract and map dynamic fields in tmap?

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

Six Stars

Re: How to extract and map dynamic fields in tmap?

 

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

2019 GARTNER 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

Best Practices for Using Context Variables with Talend – Part 4

Pick up some tips and tricks with Context Variables

Blog

Talend Integration with Databricks

Take a look at this video about Talend Integration with Databricks

Watch Now

How to Modernize Your Cloud Platform for Big Data Analytics With Talend and Micr...

Learn how<SPAN>to modernize your Cloud Platform for Big Data Analytics with Talend and Microsoft Azure</SPAN>

Read