gpt4 book ai didi

hadoop - hive中的多表连接

转载 作者:可可西里 更新时间:2023-11-01 14:42:22 32 4
gpt4 key购买 nike

我已将 Teradata 表的数据迁移到 hive 中。

现在我必须在导入数据的基础上构建汇总表。需要从五个源表构建汇总表

如果我使用连接,我需要连接五个表,在 hive 中是否可行?还是应该将查询分为五个部分?对于这个问题应该采取什么可取的方法?

请推荐

最佳答案

hive 中的五种方式连接当然是可能的,而且(自然地)可能很慢到非常慢。

您应该考虑对表进行联合分区

  • 相同的分区列
  • 相同数量的分区

其他选项包括提示。例如,考虑是否其中一张 table 很大而其他 table 很小。然后您可以使用 streamtble 提示

假设 a 很大:

SELECT /*+ STREAMTABLE(a) */ a.val, b.val, c.val, d.val, e.val 
FROM a JOIN b ON (a.key = b.key1) JOIN c ON (c.key = b.key1) join d on (d.key = c.key) join e on (e.key = d.key)

改编自:https://cwiki.apache.org/confluence/display/Hive/LanguageManual+Joins:

All five tables are joined in a single map/reduce job and the values for a particular value of the key for tables b, c,d, and e are buffered in the memory in the reducers. Then for each row retrieved from a, the join is computed with the buffered rows. If the STREAMTABLE hint is omitted, Hive streams the rightmost table in the join.

另一个提示是 mapjoin,它有助于在内存中缓存小表。

假设 a 很大并且 b、c、d、e 足够小以适合每个映射器的内存:

 SELECT /*+ MAPJOIN(b,c,d,e) */  a.val, b.val, c.val, d.val, e.val 
FROM a JOIN b ON (a.key = b.key1) JOIN c ON (c.key = b.key1)
join d on (d.key = c.key) join e on (e.key = d.key)

关于hadoop - hive中的多表连接,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29028616/

32 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com