【问题标题】:Google Apps Script and Big Query - tabledate.insertAllGoogle Apps 脚本和 Bigquery - tabledata.insertAll
【发布时间】:2014-06-30 00:05:55
【问题描述】:

一直在为此苦苦挣扎...... Google Apps 脚本和 Big Query API 运行良好,但是当我尝试使用 BigQuery.Tabledata.insertAll 时,我不断收到一条错误消息,提示“没有此类字段”。

当我尝试通过 Google API 资源管理器运行相同的东西时,它运行良好。文档说命令是:

BigQuery.TableData.insertAll(TableDataInsertAllRequest resource, String projectId, String datasetId, String tableId)

我已经按照文档https://developers.google.com/bigquery/docs/reference/v2/tabledata/insertAll 构建了 TableDataInsertAllRequest 资源,它看起来像这样:

{
  "kind": "bigquery#tableDataInsertAllRequest",
  "rows": 
  [
    {
      "json": 
      {
        "domain": "test",
        "kind": "another test"
      }
    }
  ]
}

这与我的表架构匹配。

当我运行命令时返回的错误是:

{
    "insertErrors": [
        {
            "index": 0,
            "errors": [
                {
                    "message": "no such field",
                    "reason": "invalid"
                }
            ]
        }
    ],
    "kind": "bigquery#tableDataInsertAllResponse"
} 

正如我所说,相同的 TableDataInsertAllRequest 资源在 API 资源管理器中可以正常工作(单击上面文档页面上的 Try It),但它不能通过 Apps 脚本工作。

感谢您的帮助。

【问题讨论】:

  • 请发布您的架构和失败的作业 ID。
  • 你让这件事工作了吗?愿意发布您的答案吗?谢谢!

标签: google-apps-script google-api google-bigquery


【解决方案1】:

我也遇到过这种情况,而且这种变体的运气更好。

var rowObjects = [];
// Generally you'd do this next bit in a loop
var rowData = {};
rowData.domain = 'test';
rowData.kind = 'another test';
rowObjects.push(rowData);
// And at this point you'd have an array rowObjects with a bunch of objects
var response = BigQuery.Tabledata.insertAll({'rows': rowObjects}, projectId, datasetId, tableId);

注意事项:

  • 我没有指出kind——这是对insertAll()的调用暗示的
  • 我使用点表示法(这是正确的术语吗?)而不是字符串来将属性填充到我的“行对象”中

我不确定其中哪一个是秘制酱汁。无论如何,最后,调用的结构大概是这样的:

BigQuery.Tabledata.insertAll({'rows' : [
                                         {
                                           'domain' : 'test',
                                           'kind' : 'another test'
                                         }
                                       ]
                              },
                              projectId,
                              datasetId,
                              tableId);

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-12-02
    • 1970-01-01
    • 1970-01-01
    • 2014-03-27
    • 1970-01-01
    相关资源
    最近更新 更多