【发布时间】:2018-11-12 22:06:04
【问题描述】:
我仍在学习大查询,我对数据集和表的工作方式有一些疑问。我运行了一个查询并将结果保存到 BigQuery 表中。现在,该表是我提取的数据的快照,还是会在新数据适合原始查询时更新该表?
如果是快照。任何人都可以提供一些帮助,以使用 Nodejs 以编程方式更新/替换 BigQuery 表中的数据。
感谢您的帮助
【问题讨论】:
标签: node.js google-cloud-platform google-bigquery
我仍在学习大查询,我对数据集和表的工作方式有一些疑问。我运行了一个查询并将结果保存到 BigQuery 表中。现在,该表是我提取的数据的快照,还是会在新数据适合原始查询时更新该表?
如果是快照。任何人都可以提供一些帮助,以使用 Nodejs 以编程方式更新/替换 BigQuery 表中的数据。
感谢您的帮助
【问题讨论】:
标签: node.js google-cloud-platform google-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]
}
【讨论】: