如何为每一行使用带有 bigquery 流插入的插入 ID?

Posted

技术标签:

【中文标题】如何为每一行使用带有 bigquery 流插入的插入 ID?【英文标题】:How to use insertId with big query streaming insert for each rows? 【发布时间】:2019-05-26 19:20:01 【问题描述】:

如何使用 insertId 和 Bigquery 流式插入 node.js 的每一行

const bigquery = new BigQuery(
  projectId: projectId,
);

// Inserts data into a table
await big query
  .dataset(datasetId)
  .table(tableId)
  .insert(rows);
console.log(`Inserted $rows.length rows`);

【问题讨论】:

您好!欢迎来到 SO。你读过这个吗? cloud.google.com/bigquery/… 【参考方案1】:

insertId 包含在 InsertionRow structure 中,即:


  "insertId": string,
  "json": 
    object
  

有一个nodejs例子here,但基本上:

const rows = [

  insertId: '1',
  json: 
    INSTNM: 'Motion Picture Institute of Michigan',
    CITY: 'Troy',
    STABBR: 'MI'
  
,
//...
];

正如document Graham 分享的那样:

为帮助确保数据一致性,您可以为每个 插入的行。 BigQuery 使用 insertId 属性对您的 尽力而为的数据。

【讨论】:

以上是关于如何为每一行使用带有 bigquery 流插入的插入 ID?的主要内容,如果未能解决你的问题,请参考以下文章