Fix memory allocation for nestedPositions in the map reader
@@ -292,6 +292,7 @@ public class MapDirectSelectiveStreamReader
int streamPosition = 0;
int nestedOffset = 0;
+ int nestedPositionCount = 0;
for (int i = 0; i < positionCount; i++) {
int position = positions[i];
@@ -307,6 +308,7 @@ public class MapDirectSelectiveStreamReader
nestedLengths[i] = length;
nestedOffsets[i] = nestedOffset;
nestedOffset += length;
+ nestedPositionCount += length;
}
outputPositionCount = positionCount;
@@ -314,7 +316,7 @@ public class MapDirectSelectiveStreamReader
if (outputRequired) {
nestedOffsets[positionCount] = nestedOffset;
- int nestedPositionCount = populateNestedPositions(positionCount, nestedOffset);
+ populateNestedPositions(positionCount, nestedPositionCount);
readKeyValueStreams(nestedPositionCount);
}
nestedReadOffset += nestedOffset;
@@ -336,6 +338,7 @@ public class MapDirectSelectiveStreamReader
int streamPosition = 0;
int nonNullPositionCount = 0;
int nestedOffset = 0;
+ int nestedPositionCount = 0;
for (int i = 0; i < positionCount; i++) {
int position = positions[i];
@@ -358,6 +361,7 @@ public class MapDirectSelectiveStreamReader
nestedLengths[nonNullPositionCount] = length;
nestedOffsets[nonNullPositionCount] = nestedOffset;
nonNullPositionCount++;
+ nestedPositionCount += length;
}
outputPositions[outputPositionCount] = position;
@@ -383,7 +387,7 @@ public class MapDirectSelectiveStreamReader
}
else if (outputRequired) {
nestedOffsets[nonNullPositionCount] = nestedOffset;
- int nestedPositionCount = populateNestedPositions(nonNullPositionCount, nestedOffset);
+ populateNestedPositions(nonNullPositionCount, nestedPositionCount);
readKeyValueStreams(nestedPositionCount);
}
@@ -391,16 +395,15 @@ public class MapDirectSelectiveStreamReader
nestedReadOffset += nestedOffset;
}
- private int populateNestedPositions(int positionCount, int nestedOffset)
+ private void populateNestedPositions(int positionCount, int nestedPositionCount)
{
- nestedPositions = ensureCapacity(nestedPositions, nestedOffset);
- int nestedPositionCount = 0;
+ nestedPositions = ensureCapacity(nestedPositions, nestedPositionCount);
+ int index = 0;
for (int i = 0; i < positionCount; i++) {
for (int j = 0; j < nestedLengths[i]; j++) {
- nestedPositions[nestedPositionCount++] = nestedOffsets[i] + j;
+ nestedPositions[index++] = nestedOffsets[i] + j;
}
}
- return nestedPositionCount;
}
private void readKeyValueStreams(int positionCount)
