[英]Cloud Dataflow, PubSub & Bigquery (TableRowJsonCoder) Issues
[英]Cloud Dataflow, PubSub & Bigquery Issues
我想使用Cloud Dataflow,PubSub和Bigquery將tableRow寫入Pubsub消息,然后將其寫入Bigquery。 我希望表名,項目ID和數據集ID是動態的。
我在互聯網上看到了以下代碼,但我不明白如何傳遞數據行參數。
public void PubSub(String projectId , String datasetId,String tableId,String topicId)
PipelineOptions options = PipelineOptionsFactory.create();
DataflowPipelineOptions dataflowOptions = options.as(DataflowPipelineOptions.class);
dataflowOptions.setStreaming(true);
Pipeline pipeline = Pipeline.create(dataflowOptions);
PCollection<TableRow> input = pipeline.apply(PubsubIO.Read.topic(createTopic(projectId,topicId).getName()).withCoder(TableRowJsonCoder.of()))
.apply(Window.<TableRow>into(FixedWindows.of(Duration.standardMinutes(1))));
input.apply(BigQueryIO.Write.to(getTableReference(projectId,datasetId, tableId)).withSchema(getSchema()));
pipeline.run();
}
private static TableReference getTableReference(String projectId , String datasetId,String tableId) {
TableReference tableRef = new TableReference();
tableRef.setProjectId(projectId);
tableRef.setDatasetId(datasetId);
tableRef.setTableId(tableId);
return tableRef;
}
預先感謝,加爾
BigQueryIO.Write轉換不支持動態輸出。 但是您可以直接從DoFn進行BigQuery API調用。
這樣,您可以將表名設置為所需的任何值,這由代碼計算得出。 可以從側面輸入中查找,也可以直接從DoFn當前正在處理的元素中計算得出。
為了避免對BigQuery進行過多的小調用,您可以使用finishBundle()批量處理請求。
我不完全了解您是否要先將數據流寫入Pub / Sub,然后再將Pub / Sub寫入BigQuery? 您可以直接使用BigQuery而不使用Pub / Sub。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.