use of org.apache.druid.segment.data.IndexedInts in project druid by druid-io.
the class BaseFilterTest method selectColumnValuesMatchingFilter.
/**
* Selects elements from "selectColumn" from rows matching a filter. selectColumn must be a single valued dimension.
*/
private List<String> selectColumnValuesMatchingFilter(final DimFilter filter, final String selectColumn) {
final Sequence<Cursor> cursors = makeCursorSequence(makeFilter(filter));
Sequence<List<String>> seq = Sequences.map(cursors, cursor -> {
final DimensionSelector selector = cursor.getColumnSelectorFactory().makeDimensionSelector(new DefaultDimensionSpec(selectColumn, selectColumn));
final List<String> values = new ArrayList<>();
while (!cursor.isDone()) {
IndexedInts row = selector.getRow();
Preconditions.checkState(row.size() == 1);
values.add(selector.lookupName(row.get(0)));
cursor.advance();
}
return values;
});
return seq.toList().get(0);
}
use of org.apache.druid.segment.data.IndexedInts in project druid by druid-io.
the class Historical1SimpleDoubleAggPooledTopNScannerPrototype method scanAndAggregate.
/**
* Any changes to this method should be coordinated with {@link TopNUtils}, {@link
* PooledTopNAlgorithm#computeSpecializedScanAndAggregateImplementations} and downstream methods.
*
* It should be checked with a tool like https://github.com/AdoptOpenJDK/jitwatch that C2 compiler output for this
* method doesn't have any method calls in the while loop, i. e. all method calls are inlined. To be able to see
* assembly of this method in JITWatch and other similar tools, {@link
* PooledTopNAlgorithm#SPECIALIZE_HISTORICAL_ONE_SIMPLE_DOUBLE_AGG_POOLED_TOPN} should be turned off. Note that in this case
* the benchmark should be "naturally monomorphic", i. e. execute this method always with the same runtime shape.
*
* If the while loop contains not inlined method calls, it should be considered as a performance bug.
*/
@Override
public long scanAndAggregate(HistoricalDimensionSelector dimensionSelector, HistoricalColumnSelector metricSelector, SimpleDoubleBufferAggregator aggregator, int aggregatorSize, HistoricalCursor cursor, int[] positions, ByteBuffer resultsBuffer) {
// See TopNUtils.copyOffset() for explanation
Offset offset = (Offset) TopNUtils.copyOffset(cursor);
long processedRows = 0;
int positionToAllocate = 0;
while (offset.withinBounds() && !Thread.currentThread().isInterrupted()) {
int rowNum = offset.getOffset();
double metric = metricSelector.getDouble(rowNum);
final IndexedInts dimValues = dimensionSelector.getRow(rowNum);
final int dimSize = dimValues.size();
for (int i = 0; i < dimSize; i++) {
int dimIndex = dimValues.get(i);
int position = positions[dimIndex];
if (position >= 0) {
aggregator.aggregate(resultsBuffer, position, metric);
} else if (position == TopNAlgorithm.INIT_POSITION_VALUE) {
positions[dimIndex] = positionToAllocate;
aggregator.putFirst(resultsBuffer, positionToAllocate, metric);
positionToAllocate += aggregatorSize;
}
}
processedRows++;
offset.increment();
}
return processedRows;
}
use of org.apache.druid.segment.data.IndexedInts in project druid by druid-io.
the class ConstantDimensionSelectorTest method testGetRow.
@Test
public void testGetRow() {
IndexedInts row = NULL_SELECTOR.getRow();
Assert.assertEquals(1, row.size());
Assert.assertEquals(0, row.get(0));
}
use of org.apache.druid.segment.data.IndexedInts in project druid by druid-io.
the class Generic1AggPooledTopNScannerPrototype method scanAndAggregate.
/**
* Any changes to this method should be coordinated with {@link TopNUtils}, {@link
* PooledTopNAlgorithm#computeSpecializedScanAndAggregateImplementations} and downstream methods.
*
* It should be checked with a tool like https://github.com/AdoptOpenJDK/jitwatch that C2 compiler output for this
* method doesn't have any method calls in the while loop, i. e. all method calls are inlined. To be able to see
* assembly of this method in JITWatch and other similar tools, {@link
* PooledTopNAlgorithm#SPECIALIZE_GENERIC_ONE_AGG_POOLED_TOPN} should be turned off. Note that in this case the benchmark
* should be "naturally monomorphic", i. e. execute this method always with the same runtime shape.
*
* If the while loop contains not inlined method calls, it should be considered as a performance bug.
*/
@Override
public long scanAndAggregate(DimensionSelector dimensionSelector, BufferAggregator aggregator, int aggregatorSize, Cursor cursor, int[] positions, ByteBuffer resultsBuffer) {
long processedRows = 0;
int positionToAllocate = 0;
while (!cursor.isDoneOrInterrupted()) {
final IndexedInts dimValues = dimensionSelector.getRow();
final int dimSize = dimValues.size();
for (int i = 0; i < dimSize; i++) {
int dimIndex = dimValues.get(i);
int position = positions[dimIndex];
if (position >= 0) {
aggregator.aggregate(resultsBuffer, position);
} else if (position == TopNAlgorithm.INIT_POSITION_VALUE) {
positions[dimIndex] = positionToAllocate;
position = positionToAllocate;
aggregator.init(resultsBuffer, position);
aggregator.aggregate(resultsBuffer, position);
positionToAllocate += aggregatorSize;
}
}
processedRows++;
cursor.advanceUninterruptibly();
}
return processedRows;
}
use of org.apache.druid.segment.data.IndexedInts in project druid by druid-io.
the class SettableDimensionValueSelector method setValueFrom.
@Override
public void setValueFrom(ColumnValueSelector<?> selector) {
DimensionSelector dimensionSelector = (DimensionSelector) selector;
keptSelector = dimensionSelector;
IndexedInts row = dimensionSelector.getRow();
int rowSize = row.size();
keptRow.ensureSize(rowSize);
for (int i = 0; i < rowSize; i++) {
keptRow.setValue(i, row.get(i));
}
keptRow.setSize(rowSize);
}
Aggregations