Setting "Dynamic Column Value" using tJavaRow

Highlighted
Five Stars

Setting "Dynamic Column Value" using tJavaRow

Hi,

 

I used the following code suggested in Talend documentation to retrieve a dynamic field value using tJavaRow.

 

Dynamic columns = row3.other;

for (int i = 0; i < columns.getColumnCount(); i++) {  
      DynamicMetadata columnMetadata = columns.getColumnMetadata(i);  
      System.out.println("Column Name = " + columnMetadata.getName());

      System.out.println("Column Value = " + columns.getColumnValue(i));
}

 

In my case the column value is of type String. I want to replace the newline in the column value with a space.

I can use replace function in java. But to put the replaced string back to the Dynamic field is where I get lost.

is there any method that I can use put the string back to dynamic field? something like "setColumnValue"?

 

Also I couldn't find documentation for Dynamic and DynamicMetadata (routines.system.Dynamic and routines.system.DynamicMetadata). Can someone share the documentation link if they have please?

 

Thanks!


Accepted Solutions
Twelve Stars

Re: Setting "Dynamic Column Value" using tJavaRow

first: are you using dynamic column type.
if you know your column you do not need it.

If you are using it:
Dynamic columns = row3.other;

for (int i = 0; i < columns.getColumnCount(); i++) { 
      DynamicMetadata columnMetadata = columns.getColumnMetadata(i); 
      if (columnMetadata.getName().equals("yourColName"))
           {columns.setColumnValue(i,columns.getColumnValue(i).replace("newline"," "))};
}

 

Francois Denis

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

View solution in original post


All Replies
Twelve Stars

Re: Setting "Dynamic Column Value" using tJavaRow

first: are you using dynamic column type.
if you know your column you do not need it.

If you are using it:
Dynamic columns = row3.other;

for (int i = 0; i < columns.getColumnCount(); i++) { 
      DynamicMetadata columnMetadata = columns.getColumnMetadata(i); 
      if (columnMetadata.getName().equals("yourColName"))
           {columns.setColumnValue(i,columns.getColumnValue(i).replace("newline"," "))};
}

 

Francois Denis

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

View solution in original post

Five Stars

Re: Setting "Dynamic Column Value" using tJavaRow

Hi,

 

Thanks for your reply. This works fine. I can now set the column value using setColumnValue(int, str).

 

Regards,

Ramya

Five Stars

Re: Setting "Dynamic Column Value" using tJavaRow

In my use case i need to write the extracted field name and field value in a output file where we have 2 columns as schema i.e. fieldname and fieldvalue. How can i write all the column names and corresponding values in a file?

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 1

Learn how to do cool things with Context Variables

Blog

Migrate Data from one Database to another with one Job using the Dynamic Schema

Find out how to migrate from one database to another using the Dynamic schema

Blog

Best Practices for Using Context Variables with Talend – Part 4

Pick up some tips and tricks with Context Variables

Blog