代码之家  ›  专栏  ›  技术社区  ›  DataTx

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

  •  0
  • DataTx  · 技术社区  · 6 年前

    我正试着在因帕拉取样20%的一张桌子。我在某个地方听说内置的impala采样函数有问题。

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

    我有这样的东西:

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

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

    1 回复  |  直到 6 年前
        1
  •  1
  •   Gordon Linoff    6 年前

    我不确定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;