【发布时间】: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