Reputation: 1326
I wonder whether someone could help me please.
I've been working through help I received here: Dynamic Table and Dataset in Scheduled BigQuery Job
I've tried running the code, and I think there is an inherent problem, because when I run the code (below) I receive an error on this line:
"query": "SELECT
The error is "Unterminated string literal"
function runQuery() {
var yesterday = Utilities.formatDate(new Date(), "GMT", "dd-MM-yyyy'T'HH:mm:ss'Z'");
var configuration = {
"query": {
"useQueryCache": false,
"destinationTable": {
"projectId": "project_name_obfuscated",
"datasetId": "project_114151_shared",
"tableId": "test123"
},
"writeDisposition": "WRITE_TRUNCATE",
"createDisposition": "CREATE_IF_NEEDED",
"allowLargeResults": true,
"query": "SELECT *
FROM (SELECT hits.page.pagePath
FROM
[project:dataset.ga_sessions_20181015]
WHERE
REGEXP_MATCH( hits.page.pagePath, r'\?email=.*@.*\.*')),
(SELECT
hits.eventInfo.eventLabel
FROM
[project:dataset.ga_sessions_20181015]
WHERE
hits.eventInfo.eventAction = 'end-client,role,decision')"
}
};
var job = {
"configuration": configuration
};
var jobResult = BigQuery.Jobs.insert(job, "project_name_obfuscated");
var jobId = jobResult.jobReference.jobId;
// The job might not actually be done; wait until it is marked
// complete.
var sleepTimeMs = 500;
while (true) {
Utilities.sleep(sleepTimeMs);
sleepTimeMs *= 2;
queryResults = BigQuery.Jobs.getQueryResults(projectId, jobId, {
"maxResults": 10000);
if (!queryResults.jobComplete) {
break;
}
}
I've been through various tutorials and tried adding the ' + solution so the line becomes "query": ' SELECT +
But I still can't get the script to run.
Could someone possible point out where I've gone wrong?
Many thanks and kind regards!!
Upvotes: 1
Views: 893
Reputation: 2232
As the user TheMaster pointed out in his comment, the error comes from a badly formatted multiline string:
Well Then it's multiline.
"
is not terminated on line 1. Join them using\
or+
developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/… Apps script isn't ES2015. So you can't use ``
So the code should look close to this:
"query": "SELECT * " +
"FROM (SELECT hits.page.pagePath " +
"FROM " +
"[project:dataset.ga_sessions_20181015] " +
"WHERE " +
"REGEXP_MATCH( hits.page.pagePath, r'\?email=.*@.*\.*')), " +
"(SELECT " +
"hits.eventInfo.eventLabel "+
"FROM " +
"[project:dataset.ga_sessions_20181015] " +
"WHERE " +
" hits.eventInfo.eventAction = 'end-client,role,decision')"
Upvotes: 1