我想在GAE上了解数据流作业何时完成。
我尝试同时制作以下两个管道
1。
| 'write to bigquery' >> beam.io.WriteToBigQuery(...)
| WriteStringsToPubSub('projects/fakeprj/topics/a_topic')
2。
| 'write to bigquery' >> beam.io.WriteToBigQuery(...)
| 'DoPubSub' >> beam.ParDo(DoPubSub()) # do Publish using google.cloud.pubsub
但是上面的两个代码都会产生以下错误:
AttributeError:“ PDone”对象没有“ windowing”属性
WriteToBigquery之后如何做程序?
注意:
我通过REST使用模板执行数据流。
因此,不能使用pipeline_result.wait_until_finish()
。
编辑。
完整堆栈在这里。
File "<myPC_DIRPATH>/webapi-dataflow/pubsubtemplate.py", line 327, in <module>
vital_data_export()
File "<myPC_DIRPATH>/webapi-dataflow/pubsubtemplate.py", line 323, in vital_data_export
result = p.run()
File "<myPC_DIRPATH>\webapi-dataflow\venv\dstobq_test\lib\site-packages\apache_beam\pipeline.py", line 382, in run
return self.runner.run_pipeline(self)
File "<myPC_DIRPATH>\webapi-dataflow\venv\dstobq_test\lib\site-packages\apache_beam\runners\dataflow\dataflow_runner.py", line 285, in run_pipeline
return_context=True)
File "<myPC_DIRPATH>\webapi-dataflow\venv\dstobq_test\lib\site-packages\apache_beam\pipeline.py", line 580, in to_runner_api
root_transform_id = context.transforms.get_id(self._root_transform())
File "<myPC_DIRPATH>\webapi-dataflow\venv\dstobq_test\lib\site-packages\apache_beam\runners\pipeline_context.py", line 60, in get_id
self._id_to_proto[id] = obj.to_runner_api(self._pipeline_context)
File "<myPC_DIRPATH>\webapi-dataflow\venv\dstobq_test\lib\site-packages\apache_beam\pipeline.py", line 810, in to_runner_api
for part in self.parts],
File "<myPC_DIRPATH>\webapi-dataflow\venv\dstobq_test\lib\site-packages\apache_beam\runners\pipeline_context.py", line 60, in get_id
self._id_to_proto[id] = obj.to_runner_api(self._pipeline_context)
File "<myPC_DIRPATH>\webapi-dataflow\venv\dstobq_test\lib\site-packages\apache_beam\pipeline.py", line 814, in to_runner_api
for tag, out in self.named_outputs().items()},
File "<myPC_DIRPATH>\webapi-dataflow\venv\dstobq_test\lib\site-packages\apache_beam\pipeline.py", line 814, in <dictcomp>
for tag, out in self.named_outputs().items()},
File "<myPC_DIRPATH>\webapi-dataflow\venv\dstobq_test\lib\site-packages\apache_beam\runners\pipeline_context.py", line 60, in get_id
self._id_to_proto[id] = obj.to_runner_api(self._pipeline_context)
File "<myPC_DIRPATH>\webapi-dataflow\venv\dstobq_test\lib\site-packages\apache_beam\pvalue.py", line 144, in to_runner_api
self.windowing))
File "<myPC_DIRPATH>\webapi-dataflow\venv\dstobq_test\lib\site-packages\apache_beam\pvalue.py", line 128, in windowing
self.producer.inputs)
File "<myPC_DIRPATH>\webapi-dataflow\venv\dstobq_test\lib\site-packages\apache_beam\transforms\ptransform.py", line 443, in get_windowing
return inputs[0].windowing
AttributeError: 'PDone' object has no attribute 'windowing'
答案 0 :(得分:2)
在Java中,这是我在数据流管道的末尾将“完成”事件发布到PubSub时所做的工作,该管道的输出将写入BigQuery。希望在Python中也有类似的东西。
PCollection<TableRow> rows = data.apply("ConvertToTableRow", ParDo.of(new ConvertToRow()));
// Normally this would be the end of the pipeline..
WriteResult writeResult = rows.apply("WriteToBQ", BigQueryIO.writeTableRows().to(...);
// Transformations after this will be done AFTER all rows have been written to BQ
rows.apply(Wait.on(writeResult.getFailedInserts()))
// Transforms each row inserted to an Integer of value 1
.apply("OnePerInsertedRow", ParDo.of(new DoFn<TableRow, Integer>() {
@ProcessElement
public void processElement(ProcessContext c) {
c.output(Integer.valueOf(1));
}
}))
// https://github.com/apache/beam/blob/master/sdks/java/core/src/main/java/org/apache/beam/sdk/transforms/Sum.java#L51
// Combines a PCollection of Integers (all 1's) by summing them.
// Outputs a PCollection of one integer element with the sum
.apply("SumInsertedCounts", Sum.integersGlobally())
.apply("CountsMessage", ParDo.of(new DoFn<Integer, PubsubMessage>() {
@ProcessElement
public void processElement(ProcessContext c) {
String messagePayload = "pipeline_completed";
Map<String, String> attributes = new HashMap<>();
attributes.put("rows_written", c.element().toString());
PubsubMessage message = new PubsubMessage(messagePayload.getBytes(), attributes);
c.output(message);
}
}))
.apply("PublishCompletionMessage", PubsubIO.writeMessages().to(/* output topic */));
答案 1 :(得分:0)
您不能
很明显,PDone是管道的最后阶段,因此不必等待完成。
PInput和PDone是Apache Beam支持的类,分别指示源和接收器。如果您尝试在BigQuery写入之后执行某些操作,则除非您连续运行两个不同的数据流作业,否则是不可能的。
如果要连续运行它们,请查看Apache Airflow。