parthchandra commented on code in PR #1419:
URL: https://github.com/apache/arrow-java/pull/1419#discussion_r4461661427


##########
vector/src/main/codegen/templates/DenseUnionVector.java:
##########
@@ -669,29 +670,68 @@ public void splitAndTransfer(int startIndex, int length) {
         to.reallocOffsetBuffer();
       }
 
-      int [] typeCounts = new int[nextTypeId];
-      int [] typeStarts = new int[nextTypeId];
-      for (int i = 0; i < typeCounts.length; i++) {
-        typeCounts[i] = 0;
-        typeStarts[i] = -1;
+      int[] childIndexes = new int[typeFields.length];
+      Arrays.fill(childIndexes, -1);
+      for (int i = 0; i < nextTypeId; i++) {
+        childIndexes[typeMapFields[i]] = i;
       }
 
+      // The window selects childCounts[i] values of child i, which are 
renumbered from 0. The
+      // offsets of a child only have to increase, so the selected values may 
have gaps.
+      int[] childCounts = new int[nextTypeId];
+      int[] childStarts = new int[nextTypeId];
+      int[] childEnds = new int[nextTypeId];
+      boolean[] contiguous = new boolean[nextTypeId];
+      Arrays.fill(contiguous, true);
       for (int i = startIndex; i < startIndex + length; i++) {
         byte typeId = typeBuffer.getByte(i);
         if (typeId >= 0) {
-          to.offsetBuffer.setInt((long) (i - startIndex) * OFFSET_WIDTH, 
typeCounts[typeId]);
-          typeCounts[typeId] += 1;
-          if (typeStarts[typeId] == -1) {
-            typeStarts[typeId] = offsetBuffer.getInt((long) i * OFFSET_WIDTH);
+          int child = childIndexes[typeId];

Review Comment:
   A type id that does not belong to the union still crashes with 
ArrayIndexOutOfBoundsException at childCounts[-1]. This only happens when the 
producer sends bad data. It does not return wrong data or leak memory. It 
should still throw a clear error that names the bad type id, and it needs a 
test.



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

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to