cancel
Showing results for 
Search instead for 
Did you mean: 

Null values as input for standard functions or UDF

Former Member
0 Kudos

Hello,

we have a strange behavior if an input is null for standard functions and UDFs.

Requirement is to set a target field to "false" if an element does not exist. So what I do is to create an UDF and check whether the input is null :

if (input!= null)

{

return "true";

}

else

{

return "false";

}

So return should be either "false" or "true" in any case. However if the input is null i also get a null value as return. This is very similar to the behavior of standard functions such as "concat" because if one input value is null, then also the output string is null.

Is this expected behavior? It is not possible to use "mapWithDefault" as an empty string should return true, only if the element does not exist at all there should be a false returned.

Thank you for your advice.

Accepted Solutions (0)

Answers (1)

Answers (1)

Former Member
0 Kudos

Hi Florian,

Can you try like this:

if source field exists then true --> mapwithdefault(false) -->output.

Regards,

---Satish

Former Member
0 Kudos

So you mean the following function chain:

sourceFields --> Exists --> mapWithDefault(false) --> targetField ?

I will try it!

Anyway it is strange that I cannot handle nullValues in an UDF?

Former Member
0 Kudos

Hi Florian,

Like this:

sourceFields --> Exists --> then constant (true) -- > mapWithDefault(false) --> targetField.

Regards,

---Satish

Former Member
0 Kudos

Hello,

now it even worked when I just use the "exists" function. However I had to change the context as the parent node is not mandatory.