hiveql—选择配置单元表的每个分区中的第一行

lmyy7pcs  于 2021-06-27  发布在  Hive
关注(0)|答案(0)|浏览(207)

我想从配置单元分区表中的每个分区中获取前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 ).

暂无答案!

目前还没有任何答案,快来回答吧!

相关问题