我有两个的BigQuery连接:的BigQuery数据迁移上的Java
- 客户BiqQuery连接(使用只读权限)
- 应用BigQuery的连接。
两个连接(BiqQuery服务)都有很多数据集。 因此,我创建了两个拥有不同凭据(客户端和应用程序)的bean(存储库)。
我需要客户BigQuery服务执行查询,得到的查询结果(我在得到它GetQueryResultsResponse),并将其转移到应用BigQuery服务如新表。
我试图从GetQueryResultsResponse使用表方案应用BigQuery服务创建新表,我已经执行的查询后,我加入新行到表中。但在这种情况下,我有问题 - 在BigQuery中插入不会立即完成。数据已添加一段时间,我需要在插入后立即使用数据。
问题: 也许有没有办法将这些数据保存到文件中,并在将来使用它? 有没有办法将查询结果中的数据从一个Google BigQuery服务转移到另一个服务?
我的代码:
//get data from client service
GetQueryResultsResponse resultsResponse = executeQuery(query);
TableSchema schema = resultsResponse.getSchema();
Table table = new Table();
table.setSchema(schema);
TableReference tableRef = new TableReference();
tableRef.setDatasetId(applicationDataSetId);
tableRef.setProjectId(projectId);
tableRef.setTableId(tableId);
//create new table in Application BigQuery environment
try {
Bigquery.Tables.Insert insert = getApplicationBigQueryService().tables().insert(projectId, applicationDataSetId, table);
insert.execute();
} catch (IOException e) {
}
TableDataInsertAllRequest content = new TableDataInsertAllRequest();
List<TableDataInsertAllRequest.Rows> bigQueryRows = new ArrayList<>();
List<Map<String, Object>> rows2 = new ArrayList<>();
Map<String, Object> tableCell = new TableCell();
tableCell.put("customer_master_id", 1);
tableCell.put("formulary_name", "FOR");
tableCell.put("quarter", "2014");
tableCell.put("lives", 1234213);
tableCell.put("source", "BOT");
TableDataInsertAllRequest.Rows row = new TableDataInsertAllRequest.Rows();
row.setJson(tableCell);
bigQueryRows.add(row);
TableDataInsertAllRequest.Rows insertRows = new TableDataInsertAllRequest.Rows();
insertRows.setJson(tableCell);
bigQueryRows.add(insertRows);
content.setRows(bigQueryRows);
// send insert request to BigQuery
Bigquery.Tabledata.InsertAll request = getBentoBigQueryService().tabledata().insertAll(projectId, bentoDataSetId,tableId, content);
//insert data to table
TableDataInsertAllResponse response = request.execute();
log.info(response.toString());
if (response.containsKey(INSERT_ERRORS)) {
throw new JobException(String.format(ERROR_SYNC_MSG, response));
}
} catch (IOException ex) {
log.warn(ERROR_SYNC_MSG, ex);
throw new JobException(String.format(ERROR_SYNC_MSG, ex.getMessage()));
}
感谢。
我知道如何做到这一点,让我们说一个创建连接的BigQuery凭证。主要问题是,这些“凭证”中的任何一个都没有其他服务的许可。我无法使用客户凭证执行查询并将结果插入到应用程序BigQuery中,因为客户服务没有权限执行此操作。它看起来像:Bigquery.Jobs.Query bigQuery = getBigQueryService()。jobs()。query(projectId,queryRequest); getBigQueryService() - 客户端大查询连接对象 getApplicationBigQueryService() - 应用程序大查询连接对象。可以举个例子吗? – yakutcv