Hive:SQL请求将表拆分为大约相同大小的N个表?
Q:我有一个巨大的Hive表,由于单个本地节点安装上的Java堆大小不足,MapReduce作业无法处理。由于此节点上缺少物理内存,因此无法增加YARN堆大小。作为一个解决方法,我正在考虑将这个巨大的表分成几个大小相同且结构相同的小型表(模式)。假设有2 000 000条记录分为5个表,每个表有4 000 000条记录。
以这种方式拆分Hive表的SQL请求是什么?
A:首先,我会深入研究为什么你会出现堆大小错误。这通常表示配置错误的群集。理论上,Hive / Hadoop应该能够通过流式传输到磁盘或从磁盘流式传输几乎所有内容。它主要将数据加载到内存中作为优化。 Hive旨在处理具有数十亿条记录和数TB数据的表。
但是,如果您确实希望均匀地对多个表进行采样,则可以使用多表插入;像这样的东西:
from (
select a, b, c, floor(rand() * 5) as part from my_table
) t
insert into my_table_0 select a, b, c where part = 0
insert into my_table_1 select a, b, c where part = 1
insert into my_table_2 select a, b, c where part = 2
insert into my_table_3 select a, b, c where part = 3
insert into my_table_4 select a, b, c where part = 4