我将这种解决方案视为物化视图的替代方案:
但是它使用的调度查询最多每3小时运行一次。我的用户希望获得实时数据,我该怎么办?
答案 0 :(得分:2)
2018-10:BigQuery不支持materialized views,但是您可以使用这种方法:
代码如下:
CREATE OR REPLACE VIEW `wikipedia_vt.just_latest_rows_live` AS
SELECT latest_row.*
FROM (
SELECT ARRAY_AGG(a ORDER BY datehour DESC LIMIT 1)[OFFSET(0)] latest_row
FROM (
SELECT * FROM `fh-bigquery.wikipedia_vt.just_latest_rows`
# previously "materialized" results
UNION ALL
SELECT * FROM `fh-bigquery.wikipedia_v3.pageviews_2018`
# append-only table, source of truth
WHERE datehour > TIMESTAMP_SUB(CURRENT_TIMESTAMP(), INTERVAL 2 DAY )
) a
GROUP BY title
)
请注意,BigQuery能够使用TIMESTAMP_SUB(CURRENT_TIMESTAMP(), INTERVAL 2 DAY )
有效地修剪分区。