Skip to main content
Announcements
July 15, NEW Customer Portal: Initial launch will improve how you submit Support Cases. IMPORTANT DETAILS
cancel
Showing results for 
Search instead for 
Did you mean: 
SMahadevan1608028474
Contributor
Contributor

Empty String (Soruce data have the null value) error message when converting String to Decimal format

Source

-------

Product price

This is column is not mandatory and it have null values also in source data and it's reading the data as String.

Var

----

I have created with var Int datatype.

(int)(Double.parseDouble(row4.Product_price)*10000)

Output table - Set datatype as Double

-------------

Double.parseDouble(String.valueOf(Var.var2))/10000

So in Schemacompilance I have selected Nullable checkbox for this column.

 

After run the job since the source file as Null value am getting the below error,

java.lang.NumberFormatException: empty String

Labels (2)
10 Replies
Peter_Mitchell
Contributor II
Contributor II

You're trying to parse a null or empty string to a double. Do something like this:

(row4.Product_price!=""||row4.Product_price!=null)?(int)(Double.parseDouble(row4.Product_price)*10000):null;

 

Even better, if you've got apache string utils installed I would do this:

Apache_string_utils.isBlank(row4.Product_price)?(int)(Double.parseDouble(row4.Product_price)*10000):null;

 

https://www.tutorialspoint.com/java/lang/double_parsedouble.htm

SMahadevan1608028474
Contributor
Contributor
Author

I have tried with this logics, but still facing the same issue "Empty String".

 

(row4.Product_price!=""||row4.Product_price!=null)?(int)(Double.parseDouble(row4.Product_price)*10000):null

 

 

Additionally this column(Product_price) has the negative value as well (Eg: -608).. I hope this will not make an issue.

SMahadevan1608028474
Contributor
Contributor
Author

Can anyone assist this ticket , I hope the logics seems to be correct . But still am facing the issue.

 

Attached the screenshot for more reference.

tnewbie
Creator II
Creator II

Did you try .equals(null) or !xxxx.equals(null), I have experienced this to be much better way of comparing nulls

SMahadevan1608028474
Contributor
Contributor
Author

I have tried the below ways, but still am facing the Empty String issue.

Can you please let me know is nay mistake here.

 

(row4.Unit_Selling_Price.equals(null)?null:(int)(Double.parseDouble(row4.Unit_Selling_Price)*10000))

 

(row4.Unit_Selling_Price!=(null)?(int)(Double.parseDouble(row4.Unit_Selling_Price)*10000):null)

 

(row4.Unit_Selling_Price.equals(null)||row4.Unit_Selling_Price!=(null)?(int)(Double.parseDouble(row4.Unit_Selling_Price)*10000):null)

Peter_Mitchell
Contributor II
Contributor II

A null string is not the same as an empty string. If you're going down the route of using .equals() method then you need to include an OR statement.

 

((row4.Unit_Selling_Price.equals(null) || row4.Unit_Selling_Price.equals("")) ? null : (int)(Double.parseDouble(row4.Unit_Selling_Price)*10000)).

 

As I said above, I would recommend using apache_string_utils.isBlank() method. Consistently works for me.

SMahadevan1608028474
Contributor
Contributor
Author

After trying this below statement,

((row4.Unit_Selling_Price.equals(null)||row4.Unit_Selling_Price.equals(""))?null:(int)(Double.parseDouble(row4.Unit_Selling_Price)*10000))

 

The below error is occurs,

 

Exception in component tMap_1 (Datavalidation_Filter_V1_3_tconvertype)

java.lang.NullPointerException

 at datavalidation_jan11.datavalidation_filter_v1_3_tconvertype_0_1.Datavalidation_Filter_V1_3_tconvertype.tFileInputDelimited_1Process(Datavalidation_Filter_V1_3_tconvertype.java:52769)

 at datavalidation_jan11.datavalidation_filter_v1_3_tconvertype_0_1.Datavalidation_Filter_V1_3_tconvertype.runJobInTOS(Datavalidation_Filter_V1_3_tconvertype.java:53952)

 at datavalidation_jan11.datavalidation_filter_v1_3_tconvertype_0_1.Datavalidation_Filter_V1_3_tconvertype.main(Datavalidation_Filter_V1_3_tconvertype.java:53800)

[statistics] disconnected

 

I don't have apache string utils installed in my system and if I want to do that is the path is right on, please let me where can I download

https://commons.apache.org/proper/commons-lang/apidocs/org/apache/commons/lang3/StringUtils.html

tnewbie
Creator II
Creator II

Please try (row4.Unit_Selling_Price.equals("null")

SMahadevan1608028474
Contributor
Contributor
Author

I have tried this but still empty string error is occur,

(row4.Unit_Selling_Price.equals("null")?null:(int)(Double.parseDouble(row4.Unit_Selling_Price)*10000))