dinaWork dinaWork - 4 months ago 47
Node.js Question

how to enable errors when uploading to bigquery using nodejs gcloud

using the bigquery UI I have an option to enable mistakes by checking the

Number of errors allowed


now when I am using the Gcloud in nodejs how can I enable errors?

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);
});
});

Answer

here's the answer using Danny Kitt's answer:

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);
      });
  });