如何使用nodejs gcloud上传到bigquery时启用错误

时间:2016-07-17 13:57:26

标签: node.js google-bigquery gcloud

使用bigquery UI我可以选择通过检查

来启用错误
Number of errors allowed

现在当我在nodejs中使用Gcloud时,如何启用错误?

fs.writeFile("/tmp/bq_json_file_new.json", myJSON, function(err){});
fs.createReadStream("/tmp/bq_json_file_new.json")
  .pipe(table.createWriteStream(metadata))
  .on('complete', function(job) {
    job
      .on('error', console.log)
      .on('complete', function(metadata) {
        console.log('job completed', metadata);
      });
  });

2 个答案:

答案 0 :(得分:1)

这是作业配置中的maxBadRecords字段。您可以在BigQuery API中插入作业时指定此项。我不确定nodejs客户端的外观,但如果你传入一个工作形状的对象,你应该能够在其加载作业配置中指定maxBadRecords

答案 1 :(得分:0)

这是使用Danny Kitt's回答的答案:

var gcloud = require('gcloud')({
  keyFilename: '../config/keyfile.json',
  projectId: 'my-project'
});

var request = require('request');

var bigquery = gcloud.bigquery();


var dataset = bigquery.dataset('my_dataset');
var table = dataset.table('my_table');

var metadata = {
    sourceFormat: 'NEWLINE_DELIMITED_JSON',
    maxBadRecords: 2
};

fs = require('fs');

fs.createReadStream('./myFile.json')
  .pipe(table.createWriteStream(metadata))
  .on('complete', function(job) {
   job
      .on('error', console.log)
      .on('complete', function(metadata) {
        console.log('job completed', metadata);
      });
  });