BigQuery-导出CSV某些列 [英] BigQuery - Export CSV certain columns

查看:138
本文介绍了BigQuery-导出CSV某些列的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想从bigQuery导出表或视图,但是我不需要导出所有内容:我只需要导出某些列。我该如何配置要导出的文件?

I want to export a table or a view from bigQuery, but I do not need to export everything: I need to export only certain columns. How can I configure which ones to export?

我当前的代码如下:

BigQuery bigQuery = BigQueryOptions.getDefaultInstance().getService();
Field fieldToExport = Field.of("column to export", LegacySQLTypeName.STRING);
Table table = bigQuery.getTable("mybigqueryid", "mytable", /* here it only accepts tableOptions, not fields*/);
String format = "csv";
String bucketPath = "mybucketpath.csv";
Job job = table.extract(format, bucketPath);

我最初尝试使用TableField,但显然这些不是bigquery表中的字段。

I tried using TableField at first, but apparently those are not fields from a bigquery table.

预先感谢

推荐答案

BigQuery Export仅支持整个表导出!

BigQuery Export supports whole Table Export ONLY!

如果只需要导出其中一部分,则应执行SELECT语句,然后将结果导出到CSV。

为此,您可以使用SELECT语句的目标表,然后删除此表(显式地或通过在其上设置过期),或者可以使用所谓的匿名表-将select语句的结果临时存储在其中的表-您可以从jobs.get中获取它。 API- https://cloud.google.com /bigquery/docs/reference/rest/v2/jobs#configuration.query.destinationTable

If you need to export just part of it - you should execute SELECT statement and then export result to CSV.
For this you can either use destination table for SELECT statement and than delete this table (either explicitly or by setting expiration on it) or you can use so called anonymous table - which is where result of your select statement is temporary stored - you can get it from the jobs.get API - https://cloud.google.com/bigquery/docs/reference/rest/v2/jobs#configuration.query.destinationTable

这篇关于BigQuery-导出CSV某些列的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆