Four Stars

Get String Length of the output_row fields from a Java component.

Hi.

I am trying to build data verification in a Talend Java component (currently using a tJavaRow), where the fields being processed are checked against the String Size in the output row field.

This validation would be used to identify if columns contain Strings which are larger than intended and alert about these but still process others in the same row.

I have found information on getting the sizes for dynamic schemas but there does not seem to be any information for normal String Length.

 

In a nutshell, from a Java component I would like to get the Length from the output row schema for each field.

Is this possible?

 

Thanks

  • Data Integration
4 REPLIES
Community Manager

Re: Get String Length of the output_row fields from a Java component.

Hello
Maybe tSchemaCompilanceCheck component can fit your need for data validation? Can you please show us some data to explain your requirement?

Regards
Shong

----------------------------------------------------------
Talend | Data Agility for Modern Business
Four Stars

Re: Get String Length of the output_row fields from a Java component.

Hi Shong, thanks for your reply.

 

Currently I have implemented the tSchemaComplianceCheck for validation, but this will only validate per complete row and per column.

I want to be able to check per column and only lose a column's data rather than a complete row.

 

Attached is my implementation where in the tJavaRow I am doing the mappings and would like to do the validations.

 

Thanks,

Rene

Community Manager

Re: Get String Length of the output_row fields from a Java component.

I don't know what are your expected output? To check if the column contains string and get the length of column, you can use this expression, eg:
if(StringHandling.IS_ALPHA(input_row.columnName)==true){
if(input_row.columnName.length()>5){
output_row.columnName="this column is invalid";
}else{
output_row.columnName=input_row.columnName;
}

Regards
Shong
----------------------------------------------------------
Talend | Data Agility for Modern Business
Four Stars

Re: Get String Length of the output_row fields from a Java component.

As stated I want a validation on the Output column so that if the input data size is larger than the output column size, only the column's data is lost.

I am already able to get the output column instance through java.lang.reflect and identify it's datatype, but haven't managed to get a column's length/size.

 

As you explained I can make a check by hardcoding the values for validation but whenever there is a change in the output column I would need to change the code as well.

Ideally I have this done programmatically through Java as it would save time in implementing changes.

 

Regards,

Rene