turcsanyip commented on a change in pull request #3573: NIFI-6419: Fixed 
AvroWriter single record with external schema result…
URL: https://github.com/apache/nifi/pull/3573#discussion_r301607609
 
 

 ##########
 File path: 
nifi-nar-bundles/nifi-standard-services/nifi-record-serialization-services-bundle/nifi-record-serialization-services/src/main/java/org/apache/nifi/avro/WriteAvroResultWithExternalSchema.java
 ##########
 @@ -78,14 +78,19 @@ protected void onBeginRecordSet() throws IOException {
     @Override
     public Map<String, String> writeRecord(final Record record) throws 
IOException {
         // If we are not writing an active record set, then we need to ensure 
that we write the
-        // schema information.
+        // schema information at the beginning and call flush at the end.
         if (!isActiveRecordSet()) {
             flush();
             schemaAccessWriter.writeHeader(recordSchema, getOutputStream());
         }
 
         final GenericRecord rec = AvroTypeUtil.createAvroRecord(record, 
avroSchema);
         datumWriter.write(rec, encoder);
+
+        if (!isActiveRecordSet()) {
+            flush();
 
 Review comment:
   I did not really understand why `flush()` had been added in line 83, but I 
did not want to change the existing logic (though it could be removed with no 
risk I think).
   
   I'd prefer `flush()` here because `write(RecordSet recordSet)` in 
`AbstractRecordSetWriter` handles its own `beginRecordSet()` / 
`finishRecordSet()` calls (and `flush()` is being called there). So I think 
`write(Record record)` should do the same.
   
   Additionally, we can also call `flush()` in the `close()` again (just for 
sure to clean up the resource).
   
   Adding 'flush()' only to 'close()' would not be the best solution in my 
opinion, because in that way this 'flush()' call was necessary for 
write(Record), but redundant for write(RecordSet), which is not consistent / 
straightforward.

----------------------------------------------------------------
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:
[email protected]


With regards,
Apache Git Services

Reply via email to