如何将BigQuery查询结果保存到另一个表中? [英] How to save BigQuery query results to another table?
本文介绍了如何将BigQuery查询结果保存到另一个表中?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想将查询结果保存到新表中。
使用BigQuery在线编辑器,如 bigquery.cloud.google ,我可以轻松地使用微解决方案。
结果插入〜150.000.000行几秒钟。
但我如何通过BigQuery API使用目标表参数运行查询 / strong>?
解决方案
通过使用 Jobs.insert
API调用。
例如,在Java中:
[...]
TableReference tableRef = new TableReference();
tableRef.setProjectId(< project>);
tableRef.setDatasetId(< dataset>);
tableRef.setTableId(< name>);
JobConfigurationQuery queryConfig = new JobConfigurationQuery();
queryConfig.setDestinationTable(tableRef);
queryConfig.setAllowLargeResults(true);
queryConfig.setQuery(some sql);
queryConfig.setCreateDisposition(CREATE_IF_NEEDED);
queryConfig.setWriteDisposition(WRITE_APPEND);
JobConfiguration config = new JobConfiguration()。setQuery(queryConfig);
Job job = new Job();
job.setConfiguration(config);
Bigquery.Jobs.Insert insert = bigquery.jobs()。insert(< projectid>,job);
JobReference jobId = insert.execute()。getJobReference();
[...]
I want save query results into new table. With BigQuery online editor like bigquery.cloud.google i easily do it with micro-solution from Felipe Hoffa. Results with ~150.000.000 rows inserted with several seconds.
But how do i run query with "Destination Table" parameters via BigQuery API?
解决方案
By using the Jobs.insert
API call.
For example, in Java:
[...]
TableReference tableRef = new TableReference();
tableRef.setProjectId("<project>");
tableRef.setDatasetId("<dataset>");
tableRef.setTableId("<name>");
JobConfigurationQuery queryConfig = new JobConfigurationQuery();
queryConfig.setDestinationTable(tableRef);
queryConfig.setAllowLargeResults(true);
queryConfig.setQuery("some sql");
queryConfig.setCreateDisposition(CREATE_IF_NEEDED);
queryConfig.setWriteDisposition(WRITE_APPEND);
JobConfiguration config = new JobConfiguration().setQuery(queryConfig);
Job job = new Job();
job.setConfiguration(config);
Bigquery.Jobs.Insert insert = bigquery.jobs().insert("<projectid>", job);
JobReference jobId = insert.execute().getJobReference();
[...]
这篇关于如何将BigQuery查询结果保存到另一个表中?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文