简体   繁体   中英

BigQuery - Export CSV certain columns

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

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM