One Star

String context variables handling of null

Im having an issue with a string context variable and how talend handles it. Im using java TOS 2.3.3.
We are having some context variables assigned during execution of our jobs, however the handling of these variables seem to be off a bit. Is there a way to set a string context var to null rather than "null" or ""?
We are assigning a unique identifier to each batch or job (if its run outside of a batch). So we have setup a template that will run at the beginning of each job which will create a row and pass it through a filter, if there is not unique id specified then it will need to get its own. So we are setting this row to be our context.batchID variable. However if we try to filter on null it doesnt work correctly, but if I change it to filter on "null" the filter works.
So the question is, is there a way to set a string context variable to null rather than "null" or "" by default? Because when they are setup, if you enter in null as the value it gets stored as "null". Am I just missing a way to set these to the actual value null not the string "null"?
3 REPLIES
Community Manager

Re: String context variables handling of null

Hello
The tRowGenerator component can generate a null object,not 'null' or "".
Best regards

shong
----------------------------------------------------------
Talend | Data Agility for Modern Business
One Star

Re: String context variables handling of null

Yeah I understand that, however what im trying to set are context variables which are imported from a parent job. I guess we could use a tRowGenerator out to a tJavaRow and set the context variables to default that way, but it seems like there should be an easier way to default in the value null to a string context variable. However since our ids are 10 characters long all in upper case I have just opted to use filter on the string "null" since it would be invalid anyways. But thanks for the suggestion.
One Star

Re: String context variables handling of null

This is indeed very weird.
Variables are initalized at null but once a value is entered you cannot set it back to null later on.
Its ends up being "" if you delete everything or "null" if you type null.