In many cases, when using a dynamic schema, it's necessary to change the properties of a column to map the target data structure. The column properties include column name, value, type, etc.
Example Job
The following image shows an example of how to get the column properties on a tJavaRow component and update them.
The example Java code below changes the column name of column 'name' to a new name, changes the data type of column 'age' to Integer. Copy this code and modify it according to specific needs, it supports changing column name, data type, length, precision, etc.
Dynamic columns = input_row.data;
for (int i = 0; i < columns.getColumnCount(); i++)
{
DynamicMetadata columnMetadata = columns.getColumnMetadata(i);
String col_name=columnMetadata.getName();
String col_type=columnMetadata.getType();
if(col_name.equals("name")){
columnMetadata.setName("new_name");
}
if(col_name.equals("age")){
columnMetadata.setType("id_Integer");
}
}
output_row.data=columns;
Talend Support does not support custom code development or debugging.
Hi, thanks for the post. is there a way to dynamically update a table? I know how to do it for inserts. Looking for a solution as how to update it as it requires a key to be set in the talend job.