【问题标题】:Bigquery - Resources exceeded during query execution while creating bins from 10M table using ROW_NUMBER()Bigquery - 使用 ROW_NUMBER() 从 10M 表创建 bin 时,查询执行期间资源超出
【发布时间】:2019-04-24 16:08:30
【问题描述】:

我有一个大约有 1000 万条记录的表,其中每条记录是一个 ID 和一些概率(范围在 0 和 1 之间)。 所有的 ID 都是唯一的。我正在尝试将这个 10M 数据集分解为 1,000 个箱 - 这意味着每个箱中将有 10k 条记录。 但我想根据概率计算这些箱,因此我首先按概率的降序排列表格 然后我尝试创建垃圾箱。

--10M dataset
with predictions as
(
select id ,probability
from table
)

-- give a rom_number to each record and then create 1000 groups
, bin_groups as (
select
id,
ceiling(1000.0*ROW_NUMBER() over(order by probability desc) / (select count(distinct id) from predictions)) as bins
from predictions
)

select *
from bin_groups 
where bins = 1 
limit 100

但是,执行此查询时出现以下错误 -

Resources exceeded during query execution: The query could not be executed in the allotted memory. Peak usage: 102% of limit. Top memory consumer(s): JOIN operations: 96% other/unattributed: 4%

我在这里读到 - https://cloud.google.com/bigquery/docs/best-practices-performance-output#use_a_limit_clause_with_large_sorts 我们需要在查询时限制结果,但似乎 LIMIT 也不起作用。

【问题讨论】:

  • 尝试将where bins = 1 或limit 放在内部选择中,而不是放在最后一步,以减少计算over 函数所需的资源。

标签: google-bigquery


【解决方案1】:

您在实现上面的 2 个选择语句之后发生的限制,因此在外部添加限制将不起作用。您可能必须将限制放在 bin_groups 中,尽管我不确定它是否仍然适合您的用例。

--10M dataset
with predictions as
(
select id ,probability
from table
)

-- give a rom_number to each record and then create 1000 groups
, bin_groups as (
select
id,
ceiling(1000.0*ROW_NUMBER() over(order by probability desc) / (select count(distinct 
id) from predictions)) as bins
from predictions
limit 100
)

select *
from bin_groups 
where bins = 1 

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2021-03-11
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-04-23
    • 2013-05-10
    • 1970-01-01
    相关资源
    最近更新 更多