简体   繁体   English

Javascript未终止的字符串文字错误

[英]Javascript Unterminated string literal error

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 我一直在通过这里得到的帮助进行工作: 预定BigQuery作业中的动态表和数据集

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 + 我遍历了各种教程,并尝试添加'+解决方案,使该行变为“查询”:'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!! 非常感谢和问候!

As the user TheMaster pointed out in his comment, the error comes from a badly formatted multiline string: 正如用户TheMaster在其注释中指出的那样,该错误来自格式错误的多行字符串:

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 `` "不会在第1行终止。请使用\\+ developer.mozilla.org/ en-US/docs/Web/JavaScript/Reference/…将它们加入。应用程序脚本不是ES2015。因此,您不能使用``

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')"

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM