[resolved] Expression builder complains on compilation problems I cant see

One Star

[resolved] Expression builder complains on compilation problems I cant see

Hi,
Newbie here. I'm using TOS for data integration, latest version. 
I have a tMap after an SQL input operation. Trying to check if a field's value is null and if not get it's length. 

I put some values in the test box and pressed <Test!> and I got the error message: "Exception in thread "main" java.lang.Error: Unresolved compilation problems: "
But where can I see the compilation problems?
When I hover over the red box in the Expression window I get a "Errors:6" message, but I don't know how to see these errors. 
Please help!
Thanks
One Star

Re: [resolved] Expression builder complains on compilation problems I cant see

Hi, tomersagi..
the "Test" button in tMap Expression builder can only process actual data, not the TOS data flow from the tMap input..
for example:
StringHandling.LEN("hello world!")

pressing the test button will produce the result which is 12.
and..
Relational.ISNULL("")

pressing the test button will produce the result which is false..
hmm, i guess you need to ensure you use the correct syntax for null value as Relational.ISNULL(null) will return as true while Relational.ISNULL("") will return as false..
so you can use something like this depending on the data:
Relational.ISNULL(row1.yourField)?(0):(StringHandling.LEN(row1.yourField))

OR..
(StringHandling.TRIM(row1.yourField).equals(""))?(0):(StringHandling.LEN(row1.yourField))

just remember, Java is case sensitive.. there's a difference between null, "null", "", " ", "   ", so on..
hope that'll helps! Smiley Happy
One Star

Re: [resolved] Expression builder complains on compilation problems I cant see

Hi,
Thanks for the tips. It indeed helped with the test, but the component is still failing and for the life of me I can't understand how to debug it. When I run I get this output: 
Exception in component tMap_1
java.lang.NullPointerException
at yv_er.sql_to_blocking_0_1.SQL_To_Blocking.tMSSqlInput_3Process(SQL_To_Blocking.java:3927)
at yv_er.sql_to_blocking_0_1.SQL_To_Blocking.tMSSqlInput_4Process(SQL_To_Blocking.java:5203)
at yv_er.sql_to_blocking_0_1.SQL_To_Blocking.runJobInTOS(SQL_To_Blocking.java:6242)
at yv_er.sql_to_blocking_0_1.SQL_To_Blocking.main(SQL_To_Blocking.java:6099)

I tried to Debug run in java debug mode but it wont stop on those lines eventhough I put a break point on both the component and the lines it the stack trace above. 
BTW, this is the relevant code:
// ###############################
{ // start of Var scope
// ###############################
// # Vars tables
Var__tMap_1__Struct Var = Var__tMap_1;
Var.DOBLen = Relational.ISNULL(row5.DOB) ? (0)
: (StringHandling.LEN(row5.DOB));
Var.tDate = Relational.ISNULL(row5.APPROX_DATEOFBIRTH) ? (null)
: (TalendDate.parseDate("yyyy-MM-dd HH:mm:ss.0",
row5.APPROX_DATEOFBIRTH));
// ###############################
// ###############################
// # Output tables
VRdobDay = null;
// # Output table : 'VRdobDay'
VRdobDay_tmp.Book_id = row5.Book_id;
VRdobDay_tmp.dobDay = Var.DOBLen <= 4 ? null //this is line 3927
: (Var.tDate == null ? (0) :
TalendDate.getPartOfDate("DAY_OF_MONTH",
Var.tDate));
VRdobDay_tmp.dobMonth = Var.DOBLen <= 4 ? null
: TalendDate.getPartOfDate("MONTH",
Var.tDate);
VRdobDay_tmp.dobYear = Var.DOBLen == 0 ? null
: TalendDate.getPartOfDate("YEAR",
Var.tDate);
VRdobDay = VRdobDay_tmp;
// ###############################
} //

line 3927 is marked with a comment. 
I probably did something stupid, but my main question is how do I debug this?
Thanks,
Tomer
Seventeen Stars

Re: [resolved] Expression builder complains on compilation problems I cant see

hi,
Using Var & several ternary operator could become quicly hard to maintain.
Create a routine to do the job :

just to get the idea ...
ex public static String manageNullDate(String DOB, Date APPROX_DATEOFBIRTH) {
if(DOB == null){
// put your default value
}
if(APPROX_DATEOFBIRTH == null){
// your code
}
else {
String partOf date = TalendDate.parseDate("yyyy-MM-dd HH:mm:ss.0",APPROX_DATEOFBIRTH);
etc ....
}
}

Clear to maintain and can reuse it if it's global enought
hope it helps
regards
laurent
One Star

Re: [resolved] Expression builder complains on compilation problems I cant see

Hi, Tomer..
just like what laurent mentioned, i think the issue here is not within tMap but the data itself.. normally the "java.lang.NullPointerException" occurs when the data processed by the routine/function is not in the specified parameters..
meaning, the data cannot be processed due to data quality issue..
can you please run/debug run your job and point the output to tLogRow and see on which row of Book_id it stops?
then please check the DOB and APPROX_DATEOFBIRTH field of that Book_id and see whether it has valid data that can be processed by your variables (Var.DOBLen & Var.tDate)
i'm sure there's some data quality issue.. (like alphabets in DOB / APPROX_DATEOFBIRTH, eg: 0 (zero) and o (lowercase o) or O (upercase O) )..
since you didn't specified what to do when there's alphabet in those fields..
One Star

Re: [resolved] Expression builder complains on compilation problems I cant see

Using routines is a great pointer. 
Thank you all,
Tomer
Seventeen Stars

Re: [resolved] Expression builder complains on compilation problems I cant see

to complete sky_angel answer & data quality, Talend provide very useful tools thanks Data Profiler to discover what is exactly your data ans its quality :
http://www.talend.com/resource/data-profiler.html
regards
laurent