1

我想從使用node.js API的谷歌雲功能創建外部表。該功能將從GCS存儲桶更改中觸發。我可以創建一個本地表,但不能創建一個外部表。在導入here的node.js api中,configuration.load元數據沒有設置將其指定爲外部表。這是我迄今爲止創建本地表的代碼。我的問題是「我如何使用Node.js的API來創建外部表的GCS桶」BigQuery Node.js API創建外部表

const projectId = "N" 
    const bigquery = BigQuery({ 
     projectId: projectId 
    }); 
    const storage = Storage({ 
     projectId: projectId 
    }); 

    const dataset = bigquery.dataset("dataset"); 

    const table = dataset.table("test_data"); 

    const bucket = storage.bucket("my-bucket"); 

    const file = bucket.file("2017/03/02/*"); 

    let job; 

    // Imports data from a GCS file into a table 
    return table.import(file,{"sourceFormat":"AVRO"}) 
     .then((results) => { 
      job = results[0]; 
      console.log(`Job ${job.id} started.`); 
      return job.promise(); 
     }) 
     .then((results) => { 
      console.log(`Job ${job.id} completed.`); 
      return results; 
     }); 

回答

1

我找到了解決辦法閱讀文檔後位。通過加載/導入它們,聯合表格不起作用。他們只是用externalConfig集合提出。所以這段代碼對我有用

const dataset = bigquery.dataset("dataset"); 
var options = { 
    "externalDataConfiguration": { 
     "sourceUris": ["gs://my-bucket/2017/03/20/*"], 
     "sourceFormat": "AVRO", 
     "maxBadRecords": 0, 
     "autodetect": true 
    } 
} 
dataset.createTable("test_data_20170320",options, function(err, table, apiResponse){ 
    console.log(err) 
    console.log(table) 
    console.log(apiResponse) 
})