我在将查询作为作业启动时遇到问题:
SELECT COUNT(*) FROM
(
SELECT field_name FROM [dataset.table]
WHERE
time BETWEEN DATE_ADD(CURRENT_TIMESTAMP(), -30, "DAY") AND
CURRENT_TIMESTAMP() AND
GROUP EACH BY field_name
) AS cur_month
JOIN EACH
(
SELECT field_name FROM [dataset.table]
WHERE
time BETWEEN DATE_ADD(CURRENT_TIMESTAMP(), -60, "DAY") AND
DATE_ADD(CURRENT_TIMESTAMP(), -30, "DAY") AND
GROUP EACH BY field_name
) AS prev_month
ON cur_month.field_name = prev_month.field_name
在控制台中运行此查询成功,但使用以下java代码运行它失败
JobConfigurationQuery queryConfig = new JobConfigurationQuery()
.setQuery(query)
.setDestinationTable(new TableReference()
.setProjectId(projectId)
.setDatasetId(toDataset)
.setTableId(toTableId))
.setAllowLargeResults(true)
.setCreateDisposition("CREATE_IF_NEEDED")
.setWriteDisposition("WRITE_TRUNCATE")
.setPriority("BATCH")
.setFlattenResults(false);
我得到的错误是
{
"errorResult": {
"location": "query",
"message": "Ambiguous field name 'field_name' in JOIN. Please use the table qualifier before field name.",
"reason": "invalidQuery"
},
"errors": [
{
"location": "query",
"message": "Ambiguous field name 'field_name' in JOIN. Please use the table qualifier before field name.",
"reason": "invalidQuery"
}
],
"state": "DONE"
}
有谁知道为什么?
答案 0 :(得分:2)
问题与:BigQuery - same query works when submitted from UI and reports SQL syntax error from batch
重复将展平结果设置为true可以解决我的问题。
答案 1 :(得分:0)
您需要详细检查确实执行了您发布的查询,因为我在查询中看不到任何device_id
,但错误消息很明确:
Ambiguous field name 'device_id' in JOIN. Please use the table qualifier before field name.
您需要确保device_id列在字段名称之前具有表限定符。