[英]Bigquery parallel processing based on column value
我有一个包含两列的表student_record
我需要对每个主题分别进行分析,并且有 100 多个主题。 现在我只是循环遍历所有 subject 并将以下查询s
output 保存到 dataframe 并进行分析
SELECT studentId, res.subject, res.score
FROM student_record, UNNEST(result) res
WHERE res.subject = s
此查询可能需要很长时间才能完成(100 多个科目,1 亿学生)并且需要为每个科目运行。
我想知道是否有更好的方法在 BQ 中通过并行处理执行此类任务(例如,运行单个查询并将结果保存到按主题索引的本地文件中?)。
这个查询非常简单,应该很快。 如果您要将数百万行写入 dataframe,那可能是您的瓶颈。 我会考虑以下方法之一:
with data as (
select studentId, res.subject, res.score
from student_record, unnest(result) res
)
select
subject,
count(distinct studentID) as student_count,
avg(score) as avg_score,
max(score) as max_score,
min(score) as min_score,
variance(score) as var_score,
stddev(score) as std_dev_score,
--- etc etc
from data
group by subject
create table dataset.student_record_clustered_by_subject
(
studentId string, -- or int depending on makeup of your column
subject string,
score int -- or decimal if you have decimal places
)
cluster by subject
as (
select studentId, res.subject, res.score
from student_record, unnest(result) res
);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.