0

我想从配置单元分区表中的每个分区获取前 N 条记录,而不必反序列化表中的每条记录。我已经看到了许多其他数据库的解决方案,但没有一个可以在 Hive 中运行而不运行每条记录的解决方案。

一个最小的例子:

create table demo ( val int ) 
    partitioned by (partid int);
insert into demo partition (partid=1) 
    select stack(5, 1, 2, 3, 4, 5);
insert into demo partition (partid=2) 
    select stack(5, 100, 200, 300, 400, 500)
insert into demo partition (partid=3) 
    select stack(5, -1, -2, -3, -4, -5)
insert into demo ...
    ...

我想得到结果

select * from partition_demo where partid = 1 limit 1
union all
select * from partition_demo where partid = 2 limit 1
union all
select * from partition_demo where partid = 3 limit 1
union all
...

无需编写每个子句,无需反序列化每个分区中的所有数据(这似乎使用RANK OVER)。

4

0 回答 0