Google cloud dataflow 从Google云存储读取到本地计算机的数据流

Google cloud dataflow 从Google云存储读取到本地计算机的数据流,google-cloud-dataflow,apache-beam,dataflow,Google Cloud Dataflow,Apache Beam,Dataflow,我尝试了一个数据流作业,从谷歌云存储中读取数据并写入本地机器。我使用了DirectPipelineRunner。作业已成功完成。但是我看不到本地机器上写的文件。我是否应该指定任何ip/主机名以及与输出位置参数对应的本地位置?如何在本地计算机中指定位置 命令如下: gcloud dataflow jobs run sampleJobname1 --gcs-location gs://bucket/templatename1 --parameters inputFilePattern=gs://sa

我尝试了一个数据流作业,从谷歌云存储中读取数据并写入本地机器。我使用了DirectPipelineRunner。作业已成功完成。但是我看不到本地机器上写的文件。我是否应该指定任何ip/主机名以及与输出位置参数对应的本地位置?如何在本地计算机中指定位置

命令如下:

gcloud dataflow jobs run sampleJobname1 --gcs-location gs://bucket/templatename1 --parameters inputFilePattern=gs://samplegcsbucket/abc/*,outputLocation=C:\data\gcp\outer,runner=DirectPipelineRunner
代码:

PCollection textData=pipeline.apply(“读取文本数据”,TextIO.Read().from(options.getInputFilePattern());
textData.apply(“写入文本数据”,TextIO.Write().to(options.getOutputLocation());

这可能作为数据流作业工作的原因是为了输入和输出到云服务

如果您想写入本地计算机,那么可以使用simplefunction,它可以接受字符串输入并返回Void。在这里,您可以编写自定义java代码,将文件保存在本地计算机中。您必须使用directrunner运行此数据流

@SuppressWarnings("serial")
public static class SaveFileToLocal extends SimpleFunction<String>, Void> {

    @Override
    public KV<String, String> apply(KV<String, Iterable<String>> input) {

        String file_contents : input.getValue()

        // CODE TO WRITE THE TEXT TO LOCAL PATH
    }
}
@SuppressWarnings(“串行”)
公共静态类SaveFileToLocal扩展了SimpleFunction,Void>{
@凌驾
公共KV应用(KV输入){
字符串文件内容:input.getValue()
//将文本写入本地路径的代码
}
}

如果使用上述方法仍然无法实现这一点,那么我建议使用云存储API,并使用python或PHP代码执行相同的操作。

是的,我最终使用了云存储API
@SuppressWarnings("serial")
public static class SaveFileToLocal extends SimpleFunction<String>, Void> {

    @Override
    public KV<String, String> apply(KV<String, Iterable<String>> input) {

        String file_contents : input.getValue()

        // CODE TO WRITE THE TEXT TO LOCAL PATH
    }
}