• Index
  •  » Talend Open Studio for Data Integration » Usage, Operation
  •  » [resolved] Tmap - String to Int - And return null if null

#1 2011-04-02 04:47:42

talendtester
Member
Registered: 2009-07-15
Posts: 99

[resolved] Tmap - String to Int - And return null if null

Tags: [convert, int, java, string, tmap]

This will convert a string to an integer:
Integer.parseInt(row1.value1)

How can I change this to work for converting a String to Int and return null there is no value?
(row1.value1==null)?null:TalendDate.parseDate("dd/MM/yyyy", row1.value1)

Is this close?
(row1.value1==null)?null:Integer.parseInt(row1.value1)

Last edited by talendtester (2011-04-02 04:48:00)

Offline

#2 2011-04-02 05:08:16

shong
Talend team
Registered: 2007-08-29
Posts: 10310
Website

Re: [resolved] Tmap - String to Int - And return null if null

Hi

Is this close?
(row1.value1==null)?null:Integer.parseInt(row1.value1)

Yes, you are right. let us know if you don't get the expected result.

Best regards
Shong


Email:shong@talend.com
Choose Talend, Enjoy Talend!
New & Event: Talend Help Center
Talend-->the leader of open source data management and application integration solutions!

Offline

#3 2011-04-04 19:51:11

talendtester
Member
Registered: 2009-07-15
Posts: 99

Re: [resolved] Tmap - String to Int - And return null if null

I get this error:

Exception in component tMap_1
java.lang.NumberFormatException: For input string: ""
    at java.lang.NumberFormatException.forInputString(Unknown Source)
    at java.lang.Integer.parseInt(Unknown Source)
    at java.lang.Integer.parseInt(Unknown Source)
    at talenddemosjava.myJob_0_1.myJob.tFileInputDelimited_1Process(myJob.java:1171)
    at talenddemosjava.myJob_0_1.myJob.runJobInTOS(myJob.java:1682)
    at talenddemosjava.myJob_0_1.myJob.main(myJob.java:1556)

Offline

#4 2011-04-05 07:12:36

mailforvijaym
Member
Registered: 2010-12-28
Posts: 28

Re: [resolved] Tmap - String to Int - And return null if null

Hi

do it like this

(row1.value1==null || row1.value1=="" )?null:Integer.parseInt(row1.value1)

or you can use


(row1.value1.length >0 )?null:Integer.parseInt(row1.value1)

Regards
Vijay.M

Offline

#5 2011-04-06 21:03:14

talendtester
Member
Registered: 2009-07-15
Posts: 99

Re: [resolved] Tmap - String to Int - And return null if null

Thanks mailforvijaym & shong,

I found out that my data had several bad records with less than the correct number of delimiters.

Offline

  • Index
  •  » Talend Open Studio for Data Integration » Usage, Operation
  •  » [resolved] Tmap - String to Int - And return null if null

Board footer

Powered by FluxBB