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

How to Pass Query Answer into Limit Function Impala

我正在尝试在 impala 中抽取 table 的 20%。我在某处听说内置 impala 采样函数有问题。

有没有一种方法可以将子查询传递给 impala 限制函数,以对整个 table.

的 n% 进行采样

我有这样的东西:

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

子查询给了我所有记录的 20%

我不确定 Impala 是否有特定的采样逻辑(某些数据库有)。但是你可以使用 window 函数:

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;