Setting "Dynamic Column Value" using tJavaRow

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
Eleven 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!


All Replies
Eleven 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!

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?

Tutorial

Introduction to Talend Open Studio for Data Integration.

Definitive Guide to Data Integration

Practical steps to developing your data integration strategy.

Definitive Guide to Data Quality

Create systems and workflow to manage clean data ingestion and data transformation.