Separate filter and no-filter code paths
@@ -116,9 +116,59 @@ public class LongDictionarySelectiveStreamReader
skip(offset - readOffset);
}
+ // TODO In case of all nulls, the stream type will be LongDirect
+ int streamPosition;
+ if (filter == null) {
+ streamPosition = readNoFilter(positions, positionCount);
+ }
+ else {
+ streamPosition = readWithFilter(positions, positionCount);
+ }
+
+ readOffset = offset + streamPosition;
+
+ return outputPositionCount;
+ }
+
+ private int readNoFilter(int[] positions, int positionCount)
+ throws IOException
+ {
+ // no filter implies output is required
+ int streamPosition = 0;
+ for (int i = 0; i < positionCount; i++) {
+ int position = positions[i];
+ if (position > streamPosition) {
+ skip(position - streamPosition);
+ streamPosition = position;
+ }
+
+ if (presentStream != null && !presentStream.nextBit()) {
+ nulls[i] = true;
+ values[i] = 0;
+ }
+ else {
+ long value = dataStream.next();
+ if (inDictionaryStream == null || inDictionaryStream.nextBit()) {
+ value = dictionary[(int) value];
+ }
+ values[i] = value;
+ if (presentStream != null) {
+ nulls[i] = false;
+ }
+ }
+
+ streamPosition++;
+ }
+
+ outputPositionCount = positionCount;
+ return streamPosition;
+ }
+
+ private int readWithFilter(int[] positions, int positionCount)
+ throws IOException
+ {
outputPositionCount = 0;
int streamPosition = 0;
- // TODO In case of all nulls, the stream type will be LongDirect
for (int i = 0; i < positionCount; i++) {
int position = positions[i];
if (position > streamPosition) {
@@ -132,9 +182,7 @@ public class LongDictionarySelectiveStreamReader
nulls[outputPositionCount] = true;
values[outputPositionCount] = 0;
}
- if (filter != null) {
outputPositions[outputPositionCount] = position;
- }
outputPositionCount++;
}
}
@@ -150,16 +198,13 @@ public class LongDictionarySelectiveStreamReader
nulls[outputPositionCount] = false;
}
}
- if (filter != null) {
outputPositions[outputPositionCount] = position;
- }
outputPositionCount++;
}
}
streamPosition++;
- if (filter != null) {
outputPositionCount -= filter.getPrecedingPositionsToFail();
int succeedingPositionsToFail = filter.getSucceedingPositionsToFail();
@@ -174,11 +219,8 @@ public class LongDictionarySelectiveStreamReader
skip(positionsToSkip);
}
}
- }
- readOffset = offset + streamPosition;
-
- return outputPositionCount;
+ return streamPosition;
}
private void skip(int items)
