代码之家  ›  专栏  ›  技术社区  ›  Pieter Coucke

如何使用Nodejs将插入流传输到BigQuery?

  •  2
  • Pieter Coucke  · 技术社区  · 11 年前

    我想使用 google-api-nodejs-client stream rows Google BigQuery .

    挖掘 source code 我发现我需要一个“资源”参数。我尝试了几种组合 apirequest 但我总是会出错 No rows present in the request.

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

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

    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);
    });
    
    2 回复  |  直到 11 年前
        1
  •  3
  •   Danny Kitt    11 年前

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

      'resource ': {
    
        2
  •  2
  •   Jordan Tigani    11 年前

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

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

    (请注意,与上述内容的不同之处在于 {'id': 123,'name':'test1'} 行未被引用。

    推荐文章