Hive - 如何有效地将 Table 创建为 Select?

Hive - How to efficiently Create Table As Select?

我有一个配置单元 table,htablefoobar 上分区。我想创建这个 table 的一小部分用于实验,所以我认为要做的事情是

create table new_table like htable;

insert into new_table partition (foo, bar) select * from htable
where rand() < 0.01 and foo in (a,b)

然而,这需要很长时间,最终以 java.lang.OutOfMemoryError: Java heap space 失败。有没有更好的方法?

添加distribute by foo, bar:

    insert into new_table partition (foo, bar) select * from htable
     where rand() < 0.01 and foo in (a,b) 
    distribute by foo, bar

这将减少内存消耗。