我在Hive数据库中有五个表(A,B,C,D,E),我必须根据列“id”上的逻辑来合并这些表中的数据。从Hive中的多个表中选择增量数据
的条件是:
Select * from A
UNION
select * from B (except ids not in A)
UNION
select * from C (except ids not in A and B)
UNION
select * from D(except ids not in A,B and C)
UNION
select * from E(except ids not in A,B,C and D)
有这个数据插入到决赛桌。
一种方法是创建一个目标表(目标)并为其添加每个UNION阶段的数据,然后使用此表与另一个UNION阶段进行连接。
这将是我.hql文件的一部分:
insert into target
(select * from A
UNION
select B.* from
A
RIGHT OUTER JOIN B
on A.id=B.id
where ISNULL(A.id));
INSERT INTO target
select C.* from
target
RIGHT outer JOIN C
ON target.id=C.id
where ISNULL(target.id);
INSERT INTO target
select D.* from
target
RIGHT OUTER JOIN D
ON target.id=D.id
where ISNULL(target.id);
INSERT INTO target
select E.* from
target
RIGHT OUTER JOIN E
ON target.id=E.id
where ISNULL(target.id);
是否有更好的做到这一点?我认为无论如何,我们必须做 多个加入/查找。我很期待的最好的方法来实现这一 在
1)蜂巢与TEZ
2)火花-SQL
许多在此先感谢
太复杂了。 –