用于创建外部表的 BigQuery Node.js api

2024-03-20

我正在尝试使用 node.js API 从 google 云函数创建外部表。该函数将从 GCS 存储桶变化触发。我可以创建本机表,但不能创建外部表。在node.js api中进行导入here https://googlecloudplatform.github.io/google-cloud-node/#/docs/google-cloud/0.49.0/bigquery/table?method=import,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;
        });

我在阅读了一些文档后找到了解决方案。联合表不能通过加载/导入来工作。它们只是与 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)
})
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

用于创建外部表的 BigQuery Node.js api 的相关文章

随机推荐