2

我想使用google-api-nodejs-client行流式传输到Google BigQuery

深入研究源代码,我发现我需要一个“资源”参数。我尝试了几种组合并找到了apirequest的来源,但我总是得到错误No rows present in the request.

我终于设法用另一个npm 模块一次上传一行,但这个模块不支持 tabledata.insertAll()。

你能举一个例子来说明如何使用“资源”参数来流式插入吗?

bigquery.tabledata.insertAll({
  auth: oauth2Client,
  'projectId': config.google.projectId,
  'datasetId': config.google.datasetId,
  'tableId': config.google.tableId,
  'resource ': {
    "kind": "bigquery#tableDataInsertAllRequest",
    "rows": [
      {
        "insertId": 123456,
        "json": '{"id": 123,"name":"test1"}'
      }
    ]
  }
}, function(err, result) {
  if (err) {
    return console.error(err);
  }
  console.log(result);
});
4

2 回答 2

3

资源后您有额外的空间,您是否尝试过删除它?

  'resource ': {
于 2014-09-04T20:31:48.597 回答
2

看起来您正在对插入的行进行额外的编码。它们应该作为原始 json 发送,而不是将整行编码为字符串。也就是说,像这样:

'rows': [
  {
    'insertId': 123456,
    'json': {'id': 123,'name':'test1'}
  }
]

(请注意,与您上面的区别只是{'id': 123,'name':'test1'}没有引用该行。

于 2014-09-02T16:37:42.647 回答