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 2021/07/08 21:10:45 UTC

[GitHub] [nifi] markap14 commented on a change in pull request #4948: NIFI-8273 Adding Scripted Record processors

markap14 commented on a change in pull request #4948:
URL: https://github.com/apache/nifi/pull/4948#discussion_r666520891



##########
File path: nifi-nar-bundles/nifi-scripting-bundle/nifi-scripting-processors/src/main/java/org/apache/nifi/processors/script/RecordBatchingProcessorFlowFileBuilder.java
##########
@@ -0,0 +1,101 @@
+/*
+ * 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.processors.script;
+
+import org.apache.nifi.flowfile.FlowFile;
+import org.apache.nifi.processor.ProcessSession;
+import org.apache.nifi.processor.exception.ProcessException;
+import org.apache.nifi.serialization.RecordSetWriter;
+import org.apache.nifi.serialization.WriteResult;
+import org.apache.nifi.serialization.record.Record;
+
+import java.io.IOException;
+import java.io.OutputStream;
+import java.util.HashMap;
+import java.util.LinkedList;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+import java.util.function.BiFunction;
+import java.util.stream.Collectors;
+
+/**
+ * Helper class contains all the information necessary to prepare an outgoing flow file.
+ */
+final class RecordBatchingProcessorFlowFileBuilder {
+    private final ProcessSession session;
+    private final FlowFile incomingFlowFile;
+    private final FlowFile outgoingFlowFile;
+    private final OutputStream out;
+    private final RecordSetWriter writer;
+    private final List<Map<String, String>> attributes = new LinkedList<>();

Review comment:
       This is a complex and potentially very expensive data structure. It's holding a lot of attributes that we then going to ignore.
   I don't think we actually need to keep track of any of these attributes at all, to be honest. When the final Record has been written to the Record Writer, we should be calling
   ```
   WriteResult result = writer.finishRecordSet();
   ```
   It looks like this happens here in the `build()` method. We do not need to keep any of the intermediate values. We also shouldn't need to keep count of the number of records written, as that's also returned in the WriteResult.
   
   I'll need to continue the review to understand exactly how this is being used, but I'm not sure that this class is even needed at all. Typically, we will just create a RecordSetWriter, write the records, and then call finishRecordSet(). That call to finishRecordSet() should give us all that we need that is being tracked here.




-- 
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: issues-unsubscribe@nifi.apache.org

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