hive - 在 hive 中实现 SCD1 的最佳方法
问题描述
我有一个主表(约 100 毫米记录),需要使用每天处理的每日增量更新/插入。
delta 的典型每日交易量为几十万条记录。这可以使用allfull join
或窗口函数来实现row_number+union
。
但我的问题是,这两种方法中哪一种是使用 Hive 的更好方法(它在 Tez 上运行,版本是 2.1)。我们希望更新 master 中的所有字段以获取 delta 发生变化的记录,因此希望row_number+union
全部使用并寻找一些优化策略。
解决方案
我认为一般的经验法则是 - 避免完全连接 - 总是。
我不知道您如何使用带有联合的窗口功能,但根据我的经验,以下工作非常好(假设连接匹配 1:1):
完全加入
select
coalesce(x.a, y.a) as a,
coalesce(x.b, y.b) as b,
coalesce(x.c, y.c) as c,
coalesce(x.d, y.d) as d,
x.xe,
y.ye
from
x
full outer join y
on x.a=y.a and x.b=y.b
联盟
select
a,
b,
coalesce(max(x_c), max(y_c)) as c,
coalesce(max(x_d), max(y_d)) as d,
max(xe) as xe,
max(ye) as ye
from
(select a,b,c as x_c,d as x_d, null as y_c, null as y_d, xe, null as ye from x
union all
select a,b,null as x_c, null as x_d, c as y_c, d as y_d, null as xe, ye from y) main
group by
a,b
推荐阅读
- javascript - 合并数组数组而不重复来自同一数组的值
- javascript - 通过覆盖修改后如何再次设置javascript警报的默认行为
- python-3.x - 在python中提取文件的两行之间的一行
- linux - 如果命令指定要输出的文件,如何使用管道
- tibco-rv - tibco-rv 入站出站消息
- python - 通过 Django 从托管在不同服务器中的数据库中获取 Postgres 转储
- jmeter - Jmeter 的 HeaderManager 在 Linux 上使用 \r\n
- javascript - 在 symfony 3 中与表单数据一起在 twig 中发布数组数据
- mysql - 使用多个 OR 语句更新
- java - 从数据库中搜索后如何在 JSP 页面中显示数据?