bbende commented on a change in pull request #3679: NIFI-6089 Add Parquet 
record reader and writer
URL: https://github.com/apache/nifi/pull/3679#discussion_r319207154
 
 

 ##########
 File path: 
nifi-nar-bundles/nifi-parquet-bundle/nifi-parquet-processors/src/main/java/org/apache/nifi/parquet/record/ParquetRecordReader.java
 ##########
 @@ -0,0 +1,94 @@
+/*
+ * 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.nifi.parquet.record;
+
+import org.apache.avro.generic.GenericRecord;
+import org.apache.hadoop.conf.Configuration;
+import org.apache.nifi.avro.AvroTypeUtil;
+import org.apache.nifi.parquet.stream.NifiParquetInputFile;
+import org.apache.nifi.serialization.RecordReader;
+import org.apache.nifi.serialization.record.MapRecord;
+import org.apache.nifi.serialization.record.Record;
+import org.apache.nifi.serialization.record.RecordSchema;
+import org.apache.parquet.avro.AvroParquetReader;
+import org.apache.parquet.hadoop.ParquetReader;
+import org.apache.parquet.io.InputFile;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.util.Map;
+
+public class ParquetRecordReader implements RecordReader {
+
+    private GenericRecord lastParquetRecord;
+    private RecordSchema recordSchema;
+
+    private final InputStream inputStream;
+    private final InputFile inputFile;
+    private final ParquetReader<GenericRecord> parquetReader;
+
+    public ParquetRecordReader(final InputStream inputStream, final long 
inputLength, final Configuration configuration) throws IOException {
+        if (inputLength < 0) {
+            throw new IllegalArgumentException("Invalid input length of '" + 
inputLength + "'. This record reader requires knowing " +
+                    "the length of the InputStream and cannot be used in some 
cases where the length may not be known.");
+        }
+
+        this.inputStream = inputStream;
+
+        inputFile = new NifiParquetInputFile(inputStream, inputLength);
+        parquetReader = 
AvroParquetReader.<GenericRecord>builder(inputFile).withConf(configuration).build();
+
+        // Read the first record so that we can extract the schema
+        lastParquetRecord = parquetReader.read();
+
+        // TODO what if lastParquetRecord is null ?
 
 Review comment:
   Will update

----------------------------------------------------------------
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.
 
For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


With regards,
Apache Git Services

Reply via email to