ImmutableList.Builder<PageAndPositions> builder = ImmutableList.builder();
long nextDistinctId = 0;
GroupByHash groupByHash = new GroupByHash(types, allChannels, 10_000);
for (UpdateRequest request : requests) {
IntList positions = new IntArrayList();
BlockCursor[] cursors = request.duplicateCursors();
// Move through the positions while advancing the cursors in lockstep
int positionCount = cursors[0].getRemainingPositions() + 1;
for (int index = 0; index < positionCount; index++) {
// cursors are start at valid position, so we don't need to advance the first time
if (index > 0) {
for (BlockCursor cursor : cursors) {
checkState(cursor.advanceNextPosition());
}
}
// We are reading ahead in the cursors, so we need to filter any nulls since they can not join
if (!containsNullValue(cursors) && groupByHash.putIfAbsent(cursors) == nextDistinctId) {
nextDistinctId++;
// Only include the key if it is not already in the index
if (existingSnapshot.getJoinPosition(cursors) == UNLOADED_INDEX_KEY) {
positions.add(cursors[0].getPosition());
}
}
}
if (!positions.isEmpty()) {
builder.add(new PageAndPositions(request, positions));
}
}
pageAndPositions = builder.build();