One Star

[resolved] Need help with "Invalid character constant" error, etc.

Hi, here is my tMap expression:
table_a.column_x == 0000 ? 'UNK' : String.valueOf(table_a.column_x)

Getting an "invalid character constant" error on this
column_x is of data type short and I'm wanting to change it to string
Occasionally my source system gives a value of '0000'
Note: The source table column is actually of MySQL data type year by the way, but I'm just calling it a short in Talend; if this is a part of my problem then I welcome solutions
The reason for all the dancing around is that Java doesn't accept a year of '0000' as a valid Java date, which is why I thought to try a short, but it seems the '0000' was still causing problems
Thanks for any advice Smiley Happy
1 ACCEPTED SOLUTION

Accepted Solutions
Seventeen Stars

Re: [resolved] Need help with "Invalid character constant" error, etc.

hi,
table_a.column_x.equals("0000") ? "UNK" : table_a.column_x

"0000" should also to be a String to keep 'precision' (4 digits) .
Convert it with tconvert before expression.
regards
laurent
8 REPLIES
Community Manager

Re: [resolved] Need help with "Invalid character constant" error, etc.

Hi
I would like to read it as a string, and then check the string if it contains "0000", if so, set it to null or other value, if not, parse the string to Date if needed.
Shong
----------------------------------------------------------
Talend | Data Agility for Modern Business
Four Stars

Re: [resolved] Need help with "Invalid character constant" error, etc.

I am not sure, but the error is referring to 'UNK' as invalid char constant !!!
What is datatype of your output column?
Vaibhav
Six Stars

Re: [resolved] Need help with "Invalid character constant" error, etc.

In Java single quotes indicate a Char, double quotes for String. 'UNK' is not a valid Char. 'U' is a valid Char. "UNK" is a valid String.
Seventeen Stars

Re: [resolved] Need help with "Invalid character constant" error, etc.

hi,
table_a.column_x.equals("0000") ? "UNK" : table_a.column_x

"0000" should also to be a String to keep 'precision' (4 digits) .
Convert it with tconvert before expression.
regards
laurent
One Star

Re: [resolved] Need help with "Invalid character constant" error, etc.

Ok thanks very much for all of these ideas, I'll mark the thread resolved Smiley Happy
Four Stars

Re: [resolved] Need help with "Invalid character constant" error, etc.

Hi,
What was the problem and how you solved it, could you pl explain it here?
Thanks
Vaibhav
One Star

Re: [resolved] Need help with "Invalid character constant" error, etc.

Hi, I ended up changing it back to a short/smallint, saved some bytes that way in my DB
However, kzone's answer looks reasonable, though I didn't try it ... did it not work for you?
Seventeen Stars

Re: [resolved] Need help with "Invalid character constant" error, etc.

However, kzone's answer looks reasonable, though I didn't try it

arhhgghhh ... Damned Smiley Wink