我正在使用新的google-cloud-bigquery和google-cloud-storage api。我想查询一个像这样创建的外部表:
ExternalTableDefinition etd = ExternalTableDefinition.newBuilder(bucketPath, schema, FormatOptions.csv()).build();
TableId tableID = TableId.of(dataset, targetTableName);
TableInfo tableInfo = TableInfo.newBuilder(tableID, etd).build();
现在,我想查询此表,但要使用QueryRequest将它作为临时表:
QueryRequest queryRequest = QueryRequest.newBuilder("select * from table limit 10 ").setUseLegacySql(true).setDefaultDataset(dataset).build();
QueryResponse response = client.query(queryRequest);
但是由于表不存在而失败,这很有意义。我正在尝试执行类似于以下命令行的操作:
bq query --project_id=<project ID> --external_table_definition=wikipedia::/tmp/wikipedia 'select name from wikipedia where name contains "Alex";'
但是在Java中。
总结一下:如何通过Java客户端创建和查询外部临时表以进行大查询?
来自文档的参考:
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
}
关于java - BigQuery Java客户端-如何查询外部(联合)表?,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/42447578/