Unlock a world of possibilities! Login now and discover the exclusive benefits awaiting you.
Hi Everyone.
This is my first post here so sorry if advance if I missed something and I go straight to the question.
Here is my issue.
I would like to populate integer data type field (output) from string data type (input).
But it looks like nested "if statement" doesn't work correctly.
This one expression doesn't work:
"
Relational.ISNULL(row3.DOB) || row3.DOB.trim().isEmpty() ? null :
(
(StringHandling.DOWNCASE(StringHandling.LEFT(StringHandling.TRIM(row3.DOB),StringHandling.INDEX(StringHandling.TRIM(row3.DOB),", "))).equals("jan") || StringHandling.DOWNCASE(StringHandling.LEFT(StringHandling.TRIM(row3.DOB),StringHandling.INDEX(StringHandling.TRIM(row3.DOB),", "))).equals("january")) ? 1 :
(StringHandling.DOWNCASE(StringHandling.LEFT(StringHandling.TRIM(row3.DOB),StringHandling.INDEX(StringHandling.TRIM(row3.DOB),", "))).equals("dec") || StringHandling.DOWNCASE(StringHandling.LEFT(StringHandling.TRIM(row3.DOB),StringHandling.INDEX(StringHandling.TRIM(row3.DOB),", "))).equals("december")) ? 12 : null
)
"
Every time I receive error message:
java.NullPointerException: null
But when I change my expression a little the job run with success (please look at the last else value (1 instead of null) 😞
"
Relational.ISNULL(row3.DOB) || row3.DOB.trim().isEmpty() ? null :
(
(StringHandling.DOWNCASE(StringHandling.LEFT(StringHandling.TRIM(row3.DOB),StringHandling.INDEX(StringHandling.TRIM(row3.DOB),", "))).equals("jan") || StringHandling.DOWNCASE(StringHandling.LEFT(StringHandling.TRIM(row3.DOB),StringHandling.INDEX(StringHandling.TRIM(row3.DOB),", "))).equals("january")) ? 1 :
(StringHandling.DOWNCASE(StringHandling.LEFT(StringHandling.TRIM(row3.DOB),StringHandling.INDEX(StringHandling.TRIM(row3.DOB),", "))).equals("dec") || StringHandling.DOWNCASE(StringHandling.LEFT(StringHandling.TRIM(row3.DOB),StringHandling.INDEX(StringHandling.TRIM(row3.DOB),", "))).equals("december")) ? 12 : 1
)
"
My target column data type is nullable Integer.
This is a little strange because for example there is no issue regarding the first null value in my expression:
"
Relational.ISNULL(row3.DOB) || row3.DOB.trim().isEmpty() ? null :
...
"
So to be honest I don't know what I'm doing wrong.
Can anyone help me?
Kind regards,
MSW
Java can be tricky when you ask it to box and unbox values. I'm not sure of the specific operations in play, but it may be trying to unbox the last null in your code before boxing up the result into the Integer that becomes the expression output.
I was able to avoid this by casting your two literal outputs to Integer like so:
Relational.ISNULL(row3.DOB) || row3.DOB.trim().isEmpty() ? null : ( (StringHandling.DOWNCASE(StringHandling.LEFT(StringHandling.TRIM(row3.DOB),StringHandling.INDEX(StringHandling.TRIM(row3.DOB),", "))).equals("jan") || StringHandling.DOWNCASE(StringHandling.LEFT(StringHandling.TRIM(row3.DOB),StringHandling.INDEX(StringHandling.TRIM(row3.DOB),", "))).equals("january")) ? (Integer)1 : (StringHandling.DOWNCASE(StringHandling.LEFT(StringHandling.TRIM(row3.DOB),StringHandling.INDEX(StringHandling.TRIM(row3.DOB),", "))).equals("dec") || StringHandling.DOWNCASE(StringHandling.LEFT(StringHandling.TRIM(row3.DOB),StringHandling.INDEX(StringHandling.TRIM(row3.DOB),", "))).equals("december")) ? (Integer)12 : null )
Can you take a screenshot of your tMap please? Also, this error *may* be misleading. Can you copy the complete error? Another thing that might help is to switch to the code tab and go to the line in the error stack where it says the error occurs. It will be to do the null you are producing at the end of this IF condition. I think somewhere downstream of this it is being used in an unsafe way or by a column that is not nullable.
Hi rhall_2_0.
Here is the screenshot and complete error message:
Starting job IVRS_J010_4471_MK_7264_027_All at 15:27 04/11/2019.
[statistics] connecting to socket on port 3978
[statistics] connected
[FATAL]: talendetl.ivrs_j010_4471_mk_7264_027_all_0_1.IVRS_J010_4471_MK_7264_027_All - tMap_7 null
java.lang.NullPointerException
at talendetl.ivrs_j010_4471_mk_7264_027_all_0_1.IVRS_J010_4471_MK_7264_027_All.tDBInput_3Process(IVRS_J010_4471_MK_7264_027_All.java:9391)
at talendetl.ivrs_j010_4471_mk_7264_027_all_0_1.IVRS_J010_4471_MK_7264_027_All.tFileInputExcel_1Process(IVRS_J010_4471_MK_7264_027_All.java:3841)
at talendetl.ivrs_j010_4471_mk_7264_027_all_0_1.IVRS_J010_4471_MK_7264_027_All.runJobInTOS(IVRS_J010_4471_MK_7264_027_All.java:14202)
at talendetl.ivrs_j010_4471_mk_7264_027_all_0_1.IVRS_J010_4471_MK_7264_027_All.main(IVRS_J010_4471_MK_7264_027_All.java:13794)
Exception in component tMap_7 (IVRS_J010_4471_MK_7264_027_All)
java.lang.NullPointerException
at talendetl.ivrs_j010_4471_mk_7264_027_all_0_1.IVRS_J010_4471_MK_7264_027_All.tDBInput_3Process(IVRS_J010_4471_MK_7264_027_All.java:9391)
at talendetl.ivrs_j010_4471_mk_7264_027_all_0_1.IVRS_J010_4471_MK_7264_027_All.tFileInputExcel_1Process(IVRS_J010_4471_MK_7264_027_All.java:3841)
at talendetl.ivrs_j010_4471_mk_7264_027_all_0_1.IVRS_J010_4471_MK_7264_027_All.runJobInTOS(IVRS_J010_4471_MK_7264_027_All.java:14202)
at talendetl.ivrs_j010_4471_mk_7264_027_all_0_1.IVRS_J010_4471_MK_7264_027_All.main(IVRS_J010_4471_MK_7264_027_All.java:13794)
[statistics] disconnected
Job IVRS_J010_4471_MK_7264_027_All ended at 15:27 04/11/2019. [exit code=1]
I checked the code tab and from my perspective there is nothing what can cause the error but I'm not the Java guru.
Java can be tricky when you ask it to box and unbox values. I'm not sure of the specific operations in play, but it may be trying to unbox the last null in your code before boxing up the result into the Integer that becomes the expression output.
I was able to avoid this by casting your two literal outputs to Integer like so:
Relational.ISNULL(row3.DOB) || row3.DOB.trim().isEmpty() ? null : ( (StringHandling.DOWNCASE(StringHandling.LEFT(StringHandling.TRIM(row3.DOB),StringHandling.INDEX(StringHandling.TRIM(row3.DOB),", "))).equals("jan") || StringHandling.DOWNCASE(StringHandling.LEFT(StringHandling.TRIM(row3.DOB),StringHandling.INDEX(StringHandling.TRIM(row3.DOB),", "))).equals("january")) ? (Integer)1 : (StringHandling.DOWNCASE(StringHandling.LEFT(StringHandling.TRIM(row3.DOB),StringHandling.INDEX(StringHandling.TRIM(row3.DOB),", "))).equals("dec") || StringHandling.DOWNCASE(StringHandling.LEFT(StringHandling.TRIM(row3.DOB),StringHandling.INDEX(StringHandling.TRIM(row3.DOB),", "))).equals("december")) ? (Integer)12 : null )
If @cterenzi's suggestion does not work, can you show us the code where the error stack says the error occurred. It *could* be nothing to do with the code you have shown us. Trapping errors like this from a tMap generally require a quick flick through the code to see exactly where the error is occurring
Hi cterenzi.
Your tip is fine in my case.
Now Talend doesn't trow any error.
Thanks for that !
Regards.