gpt4 book ai didi

node.js - 了解大查询表

转载 作者:太空宇宙 更新时间:2023-11-04 03:18:30 25 4
gpt4 key购买 nike

我仍在学习大查询,并且对数据集和表的工作方式有一些疑问。我运行了一个查询并将结果保存到 BigQuery 表中。现在,该表是我提取的数据的快照,还是该表会在新数据适合原始查询时更新?

如果是快照的话。任何人都可以提供一些帮助,帮助您使用 Nodejs 以编程方式更新/替换 BigQuery 表中的数据。

感谢您的帮助

最佳答案

该表是一个“快照”,不会自动更新。关于使用 Node 以编程方式更新/替换表,我建议为此创建一个单独的问题,并尝试提供尽可能多的详细信息。 Node GitHub repo上的样本不过,可能足以让您开始。 For example :

function loadCSVFromGCS(datasetId, tableId, projectId) {
// [START bigquery_load_table_gcs_csv]
// Imports the Google Cloud client libraries
const {BigQuery} = require('@google-cloud/bigquery');
const {Storage} = require('@google-cloud/storage');

/**
* TODO(developer): Uncomment the following lines before running the sample.
*/
// const projectId = "your-project-id";
// const datasetId = "my_dataset";
// const tableId = "my_table";

/**
* This sample loads the CSV file at
* https://storage.googleapis.com/cloud-samples-data/bigquery/us-states/us-states.csv
*
* TODO(developer): Replace the following lines with the path to your file.
*/
const bucketName = 'cloud-samples-data';
const filename = 'bigquery/us-states/us-states.csv';

// Instantiates clients
const bigquery = new BigQuery({
projectId: projectId,
});

const storage = new Storage({
projectId: projectId,
});

// Configure the load job. For full list of options, see:
// https://cloud.google.com/bigquery/docs/reference/rest/v2/jobs#configuration.load
const metadata = {
sourceFormat: 'CSV',
skipLeadingRows: 1,
schema: {
fields: [
{name: 'name', type: 'STRING'},
{name: 'post_abbr', type: 'STRING'},
],
},
};

// Loads data from a Google Cloud Storage file into the table
bigquery
.dataset(datasetId)
.table(tableId)
.load(storage.bucket(bucketName).file(filename), metadata)
.then(results => {
const job = results[0];

// load() waits for the job to finish
console.log(`Job ${job.id} completed.`);

// Check the job's status for errors
const errors = job.status.errors;
if (errors && errors.length > 0) {
throw errors;
}
})
.catch(err => {
console.error('ERROR:', err);
});
// [END bigquery_load_table_gcs_csv]
}

关于node.js - 了解大查询表,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53262822/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com