Search in sources :

Example 1 with IndexedInts

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);
}
Also used : DimensionSelector(org.apache.druid.segment.DimensionSelector) IndexedInts(org.apache.druid.segment.data.IndexedInts) ArrayList(java.util.ArrayList) List(java.util.List) ArrayList(java.util.ArrayList) ImmutableList(com.google.common.collect.ImmutableList) VectorCursor(org.apache.druid.segment.vector.VectorCursor) Cursor(org.apache.druid.segment.Cursor) DefaultDimensionSpec(org.apache.druid.query.dimension.DefaultDimensionSpec)

Example 2 with IndexedInts

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;
}
Also used : IndexedInts(org.apache.druid.segment.data.IndexedInts) Offset(org.apache.druid.segment.data.Offset)

Example 3 with IndexedInts

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));
}
Also used : IndexedInts(org.apache.druid.segment.data.IndexedInts) Test(org.junit.Test)

Example 4 with IndexedInts

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;
}
Also used : IndexedInts(org.apache.druid.segment.data.IndexedInts)

Example 5 with IndexedInts

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);
}
Also used : DimensionSelector(org.apache.druid.segment.DimensionSelector) ArrayBasedIndexedInts(org.apache.druid.segment.data.ArrayBasedIndexedInts) IndexedInts(org.apache.druid.segment.data.IndexedInts)

Aggregations

IndexedInts (org.apache.druid.segment.data.IndexedInts)63 DimensionSelector (org.apache.druid.segment.DimensionSelector)22 ValueMatcher (org.apache.druid.query.filter.ValueMatcher)14 Test (org.junit.Test)13 RuntimeShapeInspector (org.apache.druid.query.monomorphicprocessing.RuntimeShapeInspector)12 ArrayBasedIndexedInts (org.apache.druid.segment.data.ArrayBasedIndexedInts)12 Cursor (org.apache.druid.segment.Cursor)10 DefaultDimensionSpec (org.apache.druid.query.dimension.DefaultDimensionSpec)8 InitializedNullHandlingTest (org.apache.druid.testing.InitializedNullHandlingTest)7 Predicate (com.google.common.base.Predicate)6 ByteBuffer (java.nio.ByteBuffer)6 Nullable (javax.annotation.Nullable)6 ColumnSelectorFactory (org.apache.druid.segment.ColumnSelectorFactory)6 BooleanValueMatcher (org.apache.druid.segment.filter.BooleanValueMatcher)6 List (java.util.List)5 Predicates (com.google.common.base.Predicates)4 ImmutableMap (com.google.common.collect.ImmutableMap)4 Arrays (java.util.Arrays)4 NullHandling (org.apache.druid.common.config.NullHandling)4 MapBasedInputRow (org.apache.druid.data.input.MapBasedInputRow)4