要更新的 BigQuery 视图 Table
BigQuery View to Update Table
我有一个日志记录 table,其中包含需要处理的原始数据,有时需要设置目标 table 以避免资源错误。
目前我正在使用 BigQuery 视图处理结果并将结果保存在另一个 BigQuery table 中,计划查询设置为覆盖 table。
随着数据量的增长,我发现成本越来越高,如何在更[=22=]的实践中构造它以节省成本?
我目前的BigQuery View脚本逻辑是这样的:
with latest_timestamp as(
select max(timestamp) latest from persist_table
),
select col1, col2, col3 from logging_table where timestamp >= (select latest from latest_timestamp)
union all
select * from persist_table where timestamp < (select latest from latest_timestamp)
我必须使用时间戳,因为时间戳是分区列,并且要避免结果中出现 duplicate/missing 数据。
不确定是否有任何其他更好的方法来做到这一点,所以我会接受任何建议。
以下步骤应该让您只插入新行,避免您每次都阅读并插入整个 table。请记住,Bigquery 根据读取的字节数向您收费。因此,每次使用分区时都不必读取整个 table 来重新插入它,从而节省成本。
确保所有 table 都按时间戳分区(如果尚未完成)(logging_table 和 persist_table):它减少了大量需要读取的数据;
将您的日程查询更改为以下内容:
with latest_timestamp as(
select max(timestamp) latest from persist_table
)
select col1, col2, col3 from logging_table where timestamp > (select latest from latest_timestamp)
union all
(select t1.col1, t1.col2, t1.col3 from
(select col1, col2, col3 from logging_table where timestamp = (select latest from latest_timestamp)) t1
left join
(select * from persist_table where timestamp = (select latest from latest_timestamp)) t2
on
(t1.col1=t2.col1 and t1.col2=t2.col2 and t1.col3=t2.col3)
where
t2.col1 is null)
AND
- 将
Overwrite
更改为 Append to table
:
我有一个日志记录 table,其中包含需要处理的原始数据,有时需要设置目标 table 以避免资源错误。
目前我正在使用 BigQuery 视图处理结果并将结果保存在另一个 BigQuery table 中,计划查询设置为覆盖 table。
随着数据量的增长,我发现成本越来越高,如何在更[=22=]的实践中构造它以节省成本?
我目前的BigQuery View脚本逻辑是这样的:
with latest_timestamp as(
select max(timestamp) latest from persist_table
),
select col1, col2, col3 from logging_table where timestamp >= (select latest from latest_timestamp)
union all
select * from persist_table where timestamp < (select latest from latest_timestamp)
我必须使用时间戳,因为时间戳是分区列,并且要避免结果中出现 duplicate/missing 数据。 不确定是否有任何其他更好的方法来做到这一点,所以我会接受任何建议。
以下步骤应该让您只插入新行,避免您每次都阅读并插入整个 table。请记住,Bigquery 根据读取的字节数向您收费。因此,每次使用分区时都不必读取整个 table 来重新插入它,从而节省成本。
确保所有 table 都按时间戳分区(如果尚未完成)(logging_table 和 persist_table):它减少了大量需要读取的数据;
将您的日程查询更改为以下内容:
with latest_timestamp as(
select max(timestamp) latest from persist_table
)
select col1, col2, col3 from logging_table where timestamp > (select latest from latest_timestamp)
union all
(select t1.col1, t1.col2, t1.col3 from
(select col1, col2, col3 from logging_table where timestamp = (select latest from latest_timestamp)) t1
left join
(select * from persist_table where timestamp = (select latest from latest_timestamp)) t2
on
(t1.col1=t2.col1 and t1.col2=t2.col2 and t1.col3=t2.col3)
where
t2.col1 is null)
AND
- 将
Overwrite
更改为Append to table
: