BigQuery - Export CSV certain columns

旧街凉风 提交于 2020-06-17 06:13:12

问题


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?

My current code is something like this:

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);

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

Thanks in advance


回答1:


BigQuery Export supports whole Table Export ONLY!

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



来源:https://stackoverflow.com/questions/49738175/bigquery-export-csv-certain-columns

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!