我创建了一个BQ表,其中的时间进行了划分(日期/时间戳),并且还使用区域和位置字段对数据进行了聚类。
我已使用为创建初始记录而运行的查询创建了每日计划查询。计划的查询设置为将数据追加到先前创建的分区和群集表中。但是,计划的查询无法运行并显示以下消息:
不兼容的表分区规范。目标表 存在分区规范 interval(type:DAY,field:timestamp)聚类(location,region),但是 传输目标分区规范为 时间间隔(类型:DAY,字段:时间戳)。请更新后重试 目标表或传输分区规范。
查询的简化版本如下:
CREATE TEMP FUNCTION
isYesterday(recordTimestamp TIMESTAMP) AS ( DATE(recordTimestamp) = DATE_SUB(CURRENT_DATE(), INTERVAL 1 DAY) );
WITH
daily AS (
SELECT
TIMESTAMP_TRUNC(timestamp,day) day,
location,
direction,
region,
MAX(metric1) metric1,
MAX(metric2) metric2
FROM (
SELECT
location,
timestamp,
direction,
CASE
WHEN area>0 AND area<20 THEN "region1"
WHEN area>10
AND area<20 THEN "region2"
WHEN area>30 AND area<40 THEN "Region3"
WHEN area=61 THEN "Region4"
WHEN area=65 THEN "Region5"
WHEN area=76 THEN "Region6"
WHEN area>89 AND area<100 THEN "Region7"
END
AS region,
SUM(terminalcount0) metric1,
SUM(terminalcount1) metric2
FROM
`statistic`
WHERE
isYesterday(timestamp)
-- DATE(timestamp) BETWEEN '2020-07-01'
-- AND DATE_SUB(CURRENT_DATE(),INTERVAL 1 day)
GROUP BY
location,
timestamp,
direction,
region )
GROUP BY
day,
location,
direction,
region)
SELECT
day as timestamp,
location,
direction,
SUM(metric1) metric1,
SUM(metric2) metric2
FROM
daily
GROUP BY
day,
location,
direction,
region
如何解决此问题,以便计划的查询可以运行并定期将结果保存到目标表?还是GCP不支持对现有群集表的计划查询?
答案 0 :(得分:1)
这里有一个针对此问题的答案:61896744
您可以通过添加带有选择查询的视图来解决此问题:
SELECT field_a, field_b, datetime, date
FROM large_table
WHERE date >= DATE_SUB(CURRENT_DATE(), INTERVAL 1 WEEK)
并创建一个预定查询,如下所示:
INSERT INTO `my_clustered_table` (field_a, field_b, ...)
SELECT *
FROM `my_view`