I have a problem launching following query as a job:
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
Running this query in the console succeeds, but running it with the following java code fails
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);
The error I get is
{
"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"
}
Does anyone have an idea why?