gideonkorir commented on a change in pull request #3509: NIFI-6295 fix 
deserialization issues with NiFiRecordSerDe for hive3streaming
URL: https://github.com/apache/nifi/pull/3509#discussion_r313976755
 
 

 ##########
 File path: 
nifi-nar-bundles/nifi-hive-bundle/nifi-hive3-processors/src/main/java/org/apache/hive/streaming/NiFiRecordSerDe.java
 ##########
 @@ -142,7 +138,27 @@ public SerDeStats getSerDeStats() {
     public Object deserialize(Writable writable) throws SerDeException {
         ObjectWritable t = (ObjectWritable) writable;
         Record record = (Record) t.get();
-        List<Object> r = new 
ArrayList<>(Collections.nCopies(columnNames.size(), null));
+        return  deserialize(record, schema, true);
+    }
+
+    /**
+     * Deserialize a record object into a Hive struct.
+     * @param  record The record to deserialize, can be null
+     * @param structTypeInfo The hive table column info that corresponds to 
the Hive struct
+     * @param isParentStruct Whether or not this struct is the one contained 
by the Writable
+     */
+    Object deserialize(Record record, StructTypeInfo structTypeInfo, boolean 
isParentStruct) throws SerDeException{
+        if(record == null){
+            return  null;
+        }
+        Map<String, Integer> fieldPositionMap = null;
+        try {
+            fieldPositionMap = populateFieldPositionMap(record.getSchema(), 
structTypeInfo, log);
 
 Review comment:
   The problem was that `deserialize` could call itself if the field value was 
a nested record, array/list of records or a map of key->Record. This bothered 
me quite a bit but I didn't know how exactly to handle it.  My initial thoughts 
was to have a cache (a map basically) that I populate as I encounter new 
schema/struct type info; something to consider, we can have 2 exact schemas but 
different positions (imaging an account containing a list of accounts where the 
column names were re-ordered in the child collection) so the cache will need to 
handle that.

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