You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@nifi.apache.org by GitBox <gi...@apache.org> on 2019/09/02 12:56:33 UTC

[GitHub] [nifi] tpalfy commented on a change in pull request #3679: NIFI-6089 Add Parquet record reader and writer

tpalfy 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_r319923524
 
 

 ##########
 File path: nifi-nar-bundles/nifi-parquet-bundle/nifi-parquet-processors/src/test/java/org/apache/nifi/parquet/TestParquetRecordSetWriter.java
 ##########
 @@ -0,0 +1,161 @@
+/*
+ * 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;
+
+import org.apache.avro.generic.GenericRecord;
+import org.apache.commons.io.IOUtils;
+import org.apache.hadoop.conf.Configuration;
+import org.apache.hadoop.fs.Path;
+import org.apache.nifi.components.PropertyDescriptor;
+import org.apache.nifi.controller.ConfigurationContext;
+import org.apache.nifi.logging.ComponentLog;
+import org.apache.nifi.schema.access.SchemaAccessUtils;
+import org.apache.nifi.schema.access.SchemaNotFoundException;
+import org.apache.nifi.serialization.RecordSetWriter;
+import org.apache.nifi.serialization.SimpleRecordSchema;
+import org.apache.nifi.serialization.record.MapRecord;
+import org.apache.nifi.serialization.record.Record;
+import org.apache.nifi.serialization.record.RecordSchema;
+import org.apache.nifi.serialization.record.SchemaIdentifier;
+import org.apache.nifi.util.MockComponentLog;
+import org.apache.nifi.util.MockConfigurationContext;
+import org.apache.parquet.avro.AvroParquetReader;
+import org.apache.parquet.hadoop.ParquetReader;
+import org.apache.parquet.hadoop.util.HadoopInputFile;
+import org.apache.parquet.io.InputFile;
+import org.junit.Before;
+import org.junit.Test;
+
+import java.io.File;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.io.OutputStream;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.Map;
+
+import static org.junit.Assert.assertEquals;
+
+public class TestParquetRecordSetWriter {
+
+    private ComponentLog componentLog;
+    private ParquetRecordSetWriter recordSetWriterFactory;
+
+    @Before
+    public void setup() {
+        recordSetWriterFactory = new ParquetRecordSetWriter();
+        componentLog = new MockComponentLog("1234", recordSetWriterFactory);
+    }
+
+    @Test
+    public void testWriteUsers() throws IOException, SchemaNotFoundException {
+        final ConfigurationContext configurationContext = getConfigurationContextWithSchema("src/test/resources/avro/user.avsc");
 
 Review comment:
   Could refactor this, something like:
   
   ```java
       @Test
       public void testWriteUsers() throws IOException, SchemaNotFoundException {
           initRecordSetWriterFactory();
   
           // get the schema from the writer factory
           final RecordSchema writeSchema = recordSetWriterFactory.getSchema(Collections.emptyMap(), null);
   
           // write some records
           final int numUsers = 10;
           final File parquetFile = new File("target/testWriterUsers-" + System.currentTimeMillis());
   
           // write some records...
           writeUsers(writeSchema, parquetFile, numUsers);
   
           // read the records back in to verify
           verifyParquetRecords(parquetFile, numUsers);
       }
   
       @Test
       public void testWriteUsersWhenSchemaFormatNotAvro() throws IOException, SchemaNotFoundException {
           initRecordSetWriterFactory();
   
           // get the schema from the writer factory
           final RecordSchema writeSchema =                                                      recordSetWriterFactory.getSchema(Collections.emptyMap(), null);
           final RecordSchema writeSchemaWithOtherFormat = new SimpleRecordSchema(writeSchema.getFields(), null, "OTHER-FORMAT", SchemaIdentifier.EMPTY);
   
           // write some records
           final int numUsers = 10;
           final File parquetFile = new File("target/testWriterUsers-" + System.currentTimeMillis());
   
           // write some records...
           writeUsers(writeSchemaWithOtherFormat, parquetFile, numUsers);
   
           // read the records back in to verify
           verifyParquetRecords(parquetFile, numUsers);
       }
   
       private void initRecordSetWriterFactory() throws IOException {
           final ConfigurationContext configurationContext = getConfigurationContextWithSchema("src/test/resources/avro/user.avsc");
   
           // simulate enabling the service
           recordSetWriterFactory.onEnabled(configurationContext);
           recordSetWriterFactory.storeSchemaWriteStrategy(configurationContext);
           recordSetWriterFactory.storeSchemaAccessStrategy(configurationContext);
       }
   ```

----------------------------------------------------------------
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:
users@infra.apache.org


With regards,
Apache Git Services