dataflow读取DoFn中的文件,输出为行流

时间:2017-02-17 17:04:23

标签: google-cloud-dataflow dataflow

Dataflow Streaming Pipeline:

GCS中的某些源上载压缩文件 - >上传事件(gs:///folder/file.gz)发送到PubSub - > DataFlow Streaming从PubSub I / O读取文件事件 - > DoFn Un-Gzip

static class CustomDoFn extends DoFn<String, String>{

@Override
public void processElement(ProcessContext c) throws Exception {
    String gcsPath = c.element();
    Open ReadChannel with GCS
    Get Stream from Channel
    while((line = stream.ReadLine()) != null){
        c.output(line) // Is this good way to read and send line down the pipeline?
    }
}

//成为管道

 pipeline.apply(PubSubIO.Read()).
           apply(ParDO.of(new CustomDoFn())).
           apply(new CustomTX()).
           apply(BigQueryIO.Write());
怀疑是:
1.在DoFn中循环生成输出是否正确?
2.我如何在Dofn中使用FileBasedSource.FileBasedReader

1 个答案:

答案 0 :(得分:0)

目前无法使用带有动态文件名的FileBasedSource(即在管道构造时未指定文件名)。 Apache Beam 2.0(https://issues.apache.org/jira/browse/BEAM-65)的未来改进将启用此功能,但尚未准备好使用。正如Alex Amato所指出的那样,你概述的方法将对大文件进行内存约束,否则应该产生一个正常运行的管道。

相关问题