如何在配置单元中进行条件连接

时间:2017-01-05 01:52:20

标签: hive hiveql

我有两个配置单元表,只有当两个表都包含数据时我才想进行连接。如果其中一个表为空,我不希望连接发生。 我尝试探索案例陈述,意图我会做类似

的事情
select count(*) as val 
case
 when val > 0 then <do join of table1 and table2 here>
 else
   <do nothing>
end
from table2

然而,看起来hive不允许在case语句中执行评估,因此这种方法不起作用。任何人都有关于如何在配置单元中执行此操作的任何输入。

1 个答案:

答案 0 :(得分:0)

select *
from TableA as a
left join TableB as b
on b.A_Id = a.A_Id
where
    b.A_Id is not null or
    not exists (select top 1 A_Id from TableB)

以下是我遇到的Source