I am trying to get Apps Script to make a BQ query, however I get the following error:
Encountered " "FROM" "FROM "" at line 1, column 41. Was expecting: ")" ... (line 14, file "Code")
The query is working fine in BQ so I don't understand what's wrong here...
Here is the script:
var datasets = [
['012345', "Country"]
// other datasets will complete the list
]
datasets.forEach(function(value) {
var datasetId = value[0];
var countryName = value[1];
var queryDataset = BigQuery.Jobs.query(
{'query' : 'SELECT "' + countryName + '" as country,' +
'EXTRACT(HOUR FROM TIMESTAMP_SECONDS(visitStartTime) AT TIME ZONE "Europe/Paris") AS Hour,' +
'(SELECT MAX(sourcePropertyInfo.sourcePropertyDisplayName)' +
'FROM UNNEST(session.hits) AS hits) AS service,' +
'IFNULL(SUM(totals.visits),0) as sessions,' +
'IFNULL(SUM(totals.transactions),0) as transactions,' +
'IFNULL(ROUND((SUM(totals.transactions)/SUM(totals.visits))*100,2),0) AS conversionRate' +
'FROM `xx-135923.' + datasetId + '.ga_realtime_view` AS session' +
'GROUP BY' +
'Hour,' +
'service' +
'ORDER BY' +
'Hour;',
'defaultDataset' : {
'datasetId': datasetId,
'useLegacySql' : false
}
}, 'xx-135923');
Do you guys have any idea ?
Thanks for your help
try + catchto print the query used along with the error it generated. See my code in this answer for what I mean: stackoverflow.com/a/51085317/9337071xx-135923:012345.ga_realtime_view" which I don't understand either, since the table is accurate.