Google cloud dataflow 通过Apache Beam使用ParquetIO读取和写入拼花文件的示例

Google cloud dataflow 通过Apache Beam使用ParquetIO读取和写入拼花文件的示例,google-cloud-dataflow,parquet,apache-beam,Google Cloud Dataflow,Parquet,Apache Beam,是否有人尝试过使用Apache Beam读取/写入拼花地板文件。最近在版本2.5.0中添加了支持,因此没有太多文档 我正在尝试读取json输入文件,并希望写入拼花格式 提前感谢。您需要使用。它实现FileIO。在不同的模块中添加以下依赖项作为ParquetIO。 <dependency> <groupId>org.apache.beam</groupId>; <artifactId&gt;beam-sdks-java-io-par

是否有人尝试过使用Apache Beam读取/写入拼花地板文件。最近在版本2.5.0中添加了支持,因此没有太多文档

我正在尝试读取json输入文件,并希望写入拼花格式


提前感谢。

您需要使用。它实现FileIO。

在不同的模块中添加以下依赖项作为ParquetIO。

<dependency>
    <groupId>org.apache.beam</groupId>;
    <artifactId&gt;beam-sdks-java-io-parquet</artifactId>;
    <version>2.6.0</version>;
</dependency>;

org.apache.beam;

我在ParquetIO的源代码中找到了这个用法。不过,在用法上有拼写错误。在写之前还有额外的(点)。
PCollection<JsonObject> input = #Your data
PCollection<GenericRecord> pgr =input.apply("parse json", ParDo.of(new DoFn<JsonObject, GenericRecord> {
        @ProcessElement
        public void processElement(ProcessContext context) {
            JsonObject json= context.getElement();
            GenericRecord record = #convert json to GenericRecord with schema
            context.output(record);
        }
    }));
pgr.apply(FileIO.<GenericRecord>write().via(ParquetIO.sink(schema)).to("path/to/save"));

PCollection<GenericRecord> data = pipeline.apply(
            ParquetIO.read(schema).from("path/to/read"));