You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by "davsclaus (via GitHub)" <gi...@apache.org> on 2023/05/28 10:40:27 UTC

[GitHub] [camel] davsclaus commented on a diff in pull request #10218: CAMEL-13573 : create parquet-avro dataformat

davsclaus commented on code in PR #10218:
URL: https://github.com/apache/camel/pull/10218#discussion_r1208501459


##########
components/camel-parquet-avro/src/main/java/org/apache/camel/dataformat/parquet/avro/ParquetAvroDataFormat.java:
##########
@@ -0,0 +1,125 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.camel.dataformat.parquet.avro;
+
+import java.io.BufferedOutputStream;
+import java.io.InputStream;
+import java.io.OutputStream;
+import java.util.ArrayList;
+import java.util.List;
+
+import org.apache.avro.reflect.ReflectData;
+import org.apache.camel.Exchange;
+import org.apache.camel.spi.DataFormat;
+import org.apache.camel.spi.DataFormatName;
+import org.apache.camel.spi.annotations.Dataformat;
+import org.apache.camel.support.DefaultUuidGenerator;
+import org.apache.camel.support.service.ServiceSupport;
+import org.apache.hadoop.conf.Configuration;
+import org.apache.hadoop.fs.FileSystem;
+import org.apache.parquet.avro.AvroParquetReader;
+import org.apache.parquet.avro.AvroParquetWriter;
+import org.apache.parquet.hadoop.ParquetReader;
+import org.apache.parquet.hadoop.ParquetWriter;
+
+import static org.apache.parquet.hadoop.ParquetFileWriter.Mode.OVERWRITE;
+import static org.apache.parquet.hadoop.metadata.CompressionCodecName.GZIP;
+
+@Dataformat("parquetAvro")
+public class ParquetAvroDataFormat extends ServiceSupport implements DataFormat, DataFormatName {
+
+    private static final DefaultUuidGenerator DEFAULT_UUID_GENERATOR = new DefaultUuidGenerator();
+
+    private Class<?> unmarshalType;
+
+    public String getDataFormatName() {
+        return "parquet-avro";
+    }
+
+    public void marshal(Exchange exchange, Object graph, OutputStream stream) throws Exception {
+        // marshal from the Java object (graph) to the parquet-avro type
+        Configuration conf = new Configuration();
+
+        FileSystem.get(conf).setWriteChecksum(false);
+
+        BufferedOutputStream parquetOutput = new BufferedOutputStream(stream);
+        ParquetOutputStream parquetOutputStream = new ParquetOutputStream(
+                DEFAULT_UUID_GENERATOR.generateUuid(),
+                parquetOutput);
+
+        List<?> list = (List<?>) graph;
+
+        try (ParquetWriter writer = AvroParquetWriter.builder(parquetOutputStream)
+                .withSchema(ReflectData.AllowNull.get().getSchema(unmarshalType)) // generate nullable fields
+                .withDataModel(ReflectData.get())
+                .withConf(conf)
+                .withCompressionCodec(GZIP)

Review Comment:
   Yes please create a JIRA



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@camel.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org