BigQuery Java 客户端 - 如何查询外部(联合)table?

BigQuery Java client - how to query external ( federated ) table?

我正在使用新的 google-cloud-bigquery 和 google-cloud-storage api。我想查询一个外部 table,我是这样创建的:

ExternalTableDefinition etd = ExternalTableDefinition.newBuilder(bucketPath, schema, FormatOptions.csv()).build();
TableId tableID = TableId.of(dataset, targetTableName);
TableInfo tableInfo = TableInfo.newBuilder(tableID, etd).build();

现在我想查询此 table,但要将其作为临时查询,请使用 QueryRequest:

QueryRequest queryRequest = QueryRequest.newBuilder("select * from table limit 10 ").setUseLegacySql(true).setDefaultDataset(dataset).build();
QueryResponse response = client.query(queryRequest);

但由于 table 不存在而失败,这是有道理的。我正在尝试执行类似于此命令行的操作:

bq query --project_id=<project ID> --external_table_definition=wikipedia::/tmp/wikipedia 'select name from wikipedia where name contains "Alex";'

但在 Java.

总结一下:如何通过 Java 客户端创建和查询 external temporary table大查询?

参考文档: https://cloud.google.com/bigquery/external-data-sources#temporary-tables

供参考,方法如下:

public static void main(String[] args) 
{

BigQuery bigquery = 
BigQueryOptions.getDefaultInstance().getService();


ExternalTableDefinition etd = 
ExternalTableDefinition.newBuilder("gs://", createSchema(), 
FormatOptions.csv()).build();

TableId tableId = TableId.of("testdataset", "mytablename");


bigquery.create(TableInfo.newBuilder(tableId, etd).build());


//Now query the table project.testdataset.mytablename

}