Source:
<code>default ColumnValueSelector<Double> makeColumnValueSelector(ReadableOffset offset, ImmutableBitmap nullValueBitmap) { if (nullValueBitmap.isEmpty()) { class HistoricalDoubleColumnSelector implements DoubleColumnSelector, HistoricalColumnSelector<Double> { @Override public boolean isNull() { return false; } @Override public double getDouble() { return ColumnarDoubles.this.get(offset.getOffset()); } @Override public double getDouble(int offset) { return ColumnarDoubles.this.get(offset); } @Override public void inspectRuntimeShape(RuntimeShapeInspector inspector) { inspector.visit("columnar", ColumnarDoubles.this); inspector.visit("offset", offset); } } return new HistoricalDoubleColumnSelector(); } else { class HistoricalDoubleColumnSelectorWithNulls implements DoubleColumnSelector, HistoricalColumnSelector<Double> { private final PeekableIntIterator nullIterator = nullValueBitmap.peekableIterator(); private int nullMark = -1; @Override public boolean isNull() { final int i = offset.getOffset(); <START> if (nullMark < i) { <END> nullIterator.advanceIfNeeded(i); if (nullIterator.hasNext()) { nullMark = nullIterator.next(); } } return nullMark == i; } @Override public double getDouble() { assert NullHandling.replaceWithDefault() || !isNull(); return ColumnarDoubles.this.get(offset.getOffset()); } @Override public double getDouble(int offset) { assert NullHandling.replaceWithDefault() || !nullValueBitmap.get(offset); return ColumnarDoubles.this.get(offset); } @Override public void inspectRuntimeShape(RuntimeShapeInspector inspector) { inspector.visit("columnar", ColumnarDoubles.this); inspector.visit("offset", offset); inspector.visit("nullValueBitmap", nullValueBitmap); } } return new HistoricalDoubleColumnSelectorWithNulls(); } }</code><technical_language>If calls offset.reset() (topN this sometimes) this wrong. I need some logic detect offset backwards, resetting iterator in case</technical_language>

Target:
default ColumnValueSelector<Double> makeColumnValueSelector(ReadableOffset offset, ImmutableBitmap nullValueBitmap) { if (nullValueBitmap.isEmpty()) { class HistoricalDoubleColumnSelector implements DoubleColumnSelector, HistoricalColumnSelector<Double> { @Override public boolean isNull() { return false; } @Override public double getDouble() { return ColumnarDoubles.this.get(offset.getOffset()); } @Override public double getDouble(int offset) { return ColumnarDoubles.this.get(offset); } @Override public void inspectRuntimeShape(RuntimeShapeInspector inspector) { inspector.visit("columnar", ColumnarDoubles.this); inspector.visit("offset", offset); } } return new HistoricalDoubleColumnSelector(); } else { class HistoricalDoubleColumnSelectorWithNulls implements DoubleColumnSelector, HistoricalColumnSelector<Double> { private PeekableIntIterator nullIterator = nullValueBitmap.peekableIterator(); private int nullMark = -1; private int offsetMark = -1; @Override public boolean isNull() { final int i = offset.getOffset(); if (i < offsetMark) { nullMark = -1; nullIterator = nullValueBitmap.peekableIterator(); } offsetMark = i; if (nullMark < i) { nullIterator.advanceIfNeeded(offsetMark); if (nullIterator.hasNext()) { nullMark = nullIterator.next(); } } return nullMark == offsetMark; } @Override public double getDouble() { assert NullHandling.replaceWithDefault() || !isNull(); return ColumnarDoubles.this.get(offset.getOffset()); } @Override public double getDouble(int offset) { assert NullHandling.replaceWithDefault() || !nullValueBitmap.get(offset); return ColumnarDoubles.this.get(offset); } @Override public void inspectRuntimeShape(RuntimeShapeInspector inspector) { inspector.visit("columnar", ColumnarDoubles.this); inspector.visit("offset", offset); inspector.visit("nullValueBitmap", nullValueBitmap); } } return new HistoricalDoubleColumnSelectorWithNulls(); } }