I would like to know what is the replacement of NULLIF
in Hive? I am using COALESCE but its not serving my requirement. My query statement is something like :
COALESCE(A,B,C) AS D
COALESCE
will return first NOT NULL value. But my A/B/C contain blank values so COALESCE is not assigning that value to D as it is considering blank as NOT NULL. But I want the correct value to be get assign to D.
In SQL I could have use COALESCE(NULLIF(A,'')......)
so it will check for blank as well. I tried CASE but it's not working.
Just use case syntax like following below :
Hope can solved your problem. Thank you..
Just use
case
:This is standard SQL, so it will work in Hive and elsewhere.
For your particular problem:
You can actually shorten this to:
because
NULL
values fail comparisons. I would use this version but often people learning SQL prefer the more explicit version with thenot null
comparison.Another HiveQL specific option is here: