如何将查询答案传递给极限函数Impala



我正试图在黑斑羚中对表格的20%进行采样。我在某个地方听说,内置的黑斑羚采样功能有问题。

有没有一种方法可以将子查询传递给impala limit函数,以对整个表的n%进行采样。

我有这样的东西:

select 
* from
table_a
order by rand()
limit
(
select 
round( (count(distinct ids)) *.2,0)
from table_a) 
)

子查询为我提供了所有记录的20%

我不确定Impala是否有特定的采样逻辑(有些数据库有(。但是你可以使用窗口功能:

select a.*
from (select a.*,
row_number() over (order by rand()) as seqnum,
count(*) over () as cnt
from table_a
) a
where seqnum <= cnt * 0.2;

最新更新