2
votes

Hive supports conditional statements - https://cwiki.apache.org/Hive/languagemanual-udf.html#LanguageManualUDF-ConditionalFunctions

However, I wish to use a block conditional statements. For example, I have two tables A and B that have similar columns (although column names aren't identical). I wish to create a new table from A and B such that B has higher priority. So, if a row is present in B, I wish to select it from B, else select the row from A. i.e.

SELECT 
IF (B.id<>NULL,
      (B.id as id,
       B.value1 as value),
      (A.id as id,
       a.value2 as value))
FROM A FULL OUTER JOIN B ON (A.id = B.id)

The above query doesn't work. Is it because Hive doesn't support block conditional statements? How can I implement the above functionality?

1

1 Answers

4
votes

I wouldn't know about block conditional statements, but wouldn't this achieve the same thing:

select case when b.id is null then a.id else b.id end as id,
       case when b.id is null then a.value else b.value end as value
from a
full outer join b on ( a.id = b.id )