Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Example to read and write parquet file using ParquetIO through Apache Beam

Has anybody tried reading/writing Parquet file using Apache Beam. Support is added recently in version 2.5.0, hence not much documentation.

I am trying to read json input file and would like to write to parquet format.

Thanks in advance.

like image 405
Pari Avatar asked Oct 29 '25 13:10

Pari


2 Answers

Add the following dependency as ParquetIO in different module.

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

//Here is code to read and write....

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"));
like image 98
Md Shihab Uddin Avatar answered Nov 01 '25 14:11

Md Shihab Uddin


You will need to use ParquetIO.Sink. It implements FileIO.

like image 20
Nathan Nasser Avatar answered Nov 01 '25 14:11

Nathan Nasser



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!