我正试着在因帕拉取样20%的一张桌子。我在某个地方听说内置的impala采样函数有问题。
是否有方法将子查询传递给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;