How to check if some column has string value in it

One Star

How to check if some column has string value in it

Hi All,
I'm working on one scenario. I have one column which is string and I need to store that as Integer in Target.
I know I can convert that using Integer.parseInt() function but the problem is source column have both string as well as numeric value in it. So I want to store numeric value as int in target and string value as null.
EX :
Source (varchar()) Target (Int)
123 123
ABC null

Please suggest your views on the above mentioned scenario.
Thanks,
Community Manager

Re: How to check if some column has string value in it

Hi
Write a routine and hard code to check if the input string is a numeric or a string. For example, go to Repository-->Code-->Routines and create a routine, let's call it MyRoutines:
package routines;
public class MyRoutines {

public static Boolean isNumeric(String str) {
if(str.equals("")){
return false;
}
for(int i=str.length();--i>=0;){
int chr=str.charAt(i);
if((chr<48&&chr!=45)|| chr>57)
return false;
}
return true;
}
}

and then call this routine in the job,
tFileInputDelimited--row1--tMap--tMysqlOutput
MyRoutines.isNumeric(row1.columnName)?Integer.parseInt(row1.columnName):null
Let us know if you have any troubles.
Best regards
Shong
----------------------------------------------------------
Talend | Data Agility for Modern Business
Seven Stars

Re: How to check if some column has string value in it

Mathematical.NUM(<var>) will return 1 if the string parameter is all digits.
One Star

Re: How to check if some column has string value in it

Hi,
In the table i have column of data type decimal(12,6) in infobright (mysql) db ,the values in the column have the values
as below:
356.400000
************
-129.840000
how to replace this **** value in the column to zero wherever it occurs
Community Manager

Re: How to check if some column has string value in it

Hi,
In the table i have column of data type decimal(12,6) in infobright (mysql) db ,the values in the column have the values
as below:
356.400000
************
-129.840000
how to replace this **** value in the column to zero wherever it occurs

Read it as a string from db, and then convert it from String to BigDecimal on tMap with the expression as below:
row1.columnName.contains("*")?new java.math.BigDecimal("0"):new java.math.BigDecimal(row1.columnName)

Shong
----------------------------------------------------------
Talend | Data Agility for Modern Business