1

我正在尝试使用 node.js API 从谷歌云函数创建一个外部表。该函数将从 GCS 存储桶更改触发。我可以创建本机表,但不能创建外部表。在用于在此处导入的 node.js api 中,configuration.load 元数据没有将其指定为外部表的设置。这是我到目前为止创建本机表的代码。我的问题是“如何使用 Node.js Api 为 GCS 存储桶创建外部表”

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

1 回答 1

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)
})
于 2017-03-21T00:13:42.483 回答