Search in sources :

Example 46 with IndexedInts

use of org.apache.druid.segment.data.IndexedInts in project druid by druid-io.

the class DictionaryEncodedColumnMerger method processMergedRow.

@Override
public void processMergedRow(ColumnValueSelector selector) throws IOException {
    IndexedInts row = getRow(selector);
    int rowSize = row.size();
    if (rowSize == 0) {
        nullRowsBitmap.add(rowCount);
    } else if (hasNull && isNullRow(row, rowSize)) {
        // If this dimension has the null/empty str in its dictionary, a row with nulls at all positions should also be
        // added to nullRowBitmap.
        nullRowsBitmap.add(rowCount);
    }
    if (encodedValueSerializer instanceof ColumnarMultiIntsSerializer) {
        ((ColumnarMultiIntsSerializer) encodedValueSerializer).addValues(row);
    } else {
        int value = row.size() == 0 ? 0 : row.get(0);
        ((SingleValueColumnarIntsSerializer) encodedValueSerializer).addValue(value);
    }
    rowCount++;
}
Also used : SingleValueColumnarIntsSerializer(org.apache.druid.segment.data.SingleValueColumnarIntsSerializer) IndexedInts(org.apache.druid.segment.data.IndexedInts) ColumnarMultiIntsSerializer(org.apache.druid.segment.data.ColumnarMultiIntsSerializer) VSizeColumnarMultiIntsSerializer(org.apache.druid.segment.data.VSizeColumnarMultiIntsSerializer) V3CompressedVSizeColumnarMultiIntsSerializer(org.apache.druid.segment.data.V3CompressedVSizeColumnarMultiIntsSerializer)

Example 47 with IndexedInts

use of org.apache.druid.segment.data.IndexedInts in project druid by druid-io.

the class StringTopNColumnAggregatesProcessor method scanAndAggregateWithCardinalityKnown.

private long scanAndAggregateWithCardinalityKnown(TopNQuery query, Cursor cursor, DimensionSelector selector, Aggregator[][] rowSelector) {
    long processedRows = 0;
    while (!cursor.isDone()) {
        final IndexedInts dimValues = selector.getRow();
        for (int i = 0, size = dimValues.size(); i < size; ++i) {
            final int dimIndex = dimValues.get(i);
            Aggregator[] aggs = rowSelector[dimIndex];
            if (aggs == null) {
                final Comparable<?> key = dimensionValueConverter.apply(selector.lookupName(dimIndex));
                aggs = aggregatesStore.computeIfAbsent(key, k -> BaseTopNAlgorithm.makeAggregators(cursor, query.getAggregatorSpecs()));
                rowSelector[dimIndex] = aggs;
            }
            for (Aggregator aggregator : aggs) {
                aggregator.aggregate();
            }
        }
        cursor.advance();
        processedRows++;
    }
    return processedRows;
}
Also used : DimensionHandlerUtils(org.apache.druid.segment.DimensionHandlerUtils) HashMap(java.util.HashMap) Aggregator(org.apache.druid.query.aggregation.Aggregator) IndexedInts(org.apache.druid.segment.data.IndexedInts) StorageAdapter(org.apache.druid.segment.StorageAdapter) Function(java.util.function.Function) TopNQuery(org.apache.druid.query.topn.TopNQuery) DimensionDictionarySelector(org.apache.druid.segment.DimensionDictionarySelector) Cursor(org.apache.druid.segment.Cursor) BaseTopNAlgorithm(org.apache.druid.query.topn.BaseTopNAlgorithm) Map(java.util.Map) ColumnCapabilities(org.apache.druid.segment.column.ColumnCapabilities) ColumnType(org.apache.druid.segment.column.ColumnType) DimensionSelector(org.apache.druid.segment.DimensionSelector) TopNResultBuilder(org.apache.druid.query.topn.TopNResultBuilder) TopNParams(org.apache.druid.query.topn.TopNParams) IndexedInts(org.apache.druid.segment.data.IndexedInts) Aggregator(org.apache.druid.query.aggregation.Aggregator)

Example 48 with IndexedInts

use of org.apache.druid.segment.data.IndexedInts in project druid by druid-io.

the class DimensionSelectorUtils method makeNonDictionaryEncodedValueMatcherGeneric.

private static ValueMatcher makeNonDictionaryEncodedValueMatcherGeneric(final DimensionSelector selector, @Nullable final String value) {
    return new ValueMatcher() {

        @Override
        public boolean matches() {
            final IndexedInts row = selector.getRow();
            final int size = row.size();
            if (size == 0) {
                // null should match empty rows in multi-value columns
                return value == null;
            } else {
                for (int i = 0; i < size; ++i) {
                    if (Objects.equals(selector.lookupName(row.get(i)), value)) {
                        return true;
                    }
                }
                return false;
            }
        }

        @Override
        public void inspectRuntimeShape(RuntimeShapeInspector inspector) {
            inspector.visit("selector", selector);
        }
    };
}
Also used : ValueMatcher(org.apache.druid.query.filter.ValueMatcher) BooleanValueMatcher(org.apache.druid.segment.filter.BooleanValueMatcher) IndexedInts(org.apache.druid.segment.data.IndexedInts) RuntimeShapeInspector(org.apache.druid.query.monomorphicprocessing.RuntimeShapeInspector)

Example 49 with IndexedInts

use of org.apache.druid.segment.data.IndexedInts in project druid by druid-io.

the class DimensionSelectorUtils method makeDictionaryEncodedValueMatcherGeneric.

private static ValueMatcher makeDictionaryEncodedValueMatcherGeneric(final DimensionSelector selector, Predicate<String> predicate) {
    final BitSet checkedIds = new BitSet(selector.getValueCardinality());
    final BitSet matchingIds = new BitSet(selector.getValueCardinality());
    final boolean matchNull = predicate.apply(null);
    // Lazy matcher; only check an id if matches() is called.
    return new ValueMatcher() {

        @Override
        public boolean matches() {
            final IndexedInts row = selector.getRow();
            final int size = row.size();
            if (size == 0) {
                // null should match empty rows in multi-value columns
                return matchNull;
            } else {
                for (int i = 0; i < size; ++i) {
                    final int id = row.get(i);
                    final boolean matches;
                    if (checkedIds.get(id)) {
                        matches = matchingIds.get(id);
                    } else {
                        matches = predicate.apply(selector.lookupName(id));
                        checkedIds.set(id);
                        if (matches) {
                            matchingIds.set(id);
                        }
                    }
                    if (matches) {
                        return true;
                    }
                }
                return false;
            }
        }

        @Override
        public void inspectRuntimeShape(RuntimeShapeInspector inspector) {
            inspector.visit("selector", selector);
        }
    };
}
Also used : ValueMatcher(org.apache.druid.query.filter.ValueMatcher) BooleanValueMatcher(org.apache.druid.segment.filter.BooleanValueMatcher) IndexedInts(org.apache.druid.segment.data.IndexedInts) BitSet(java.util.BitSet) RuntimeShapeInspector(org.apache.druid.query.monomorphicprocessing.RuntimeShapeInspector)

Example 50 with IndexedInts

use of org.apache.druid.segment.data.IndexedInts in project druid by druid-io.

the class DimensionSelectorUtils method makeNonDictionaryEncodedValueMatcherGeneric.

private static ValueMatcher makeNonDictionaryEncodedValueMatcherGeneric(final DimensionSelector selector, final Predicate<String> predicate) {
    final boolean matchNull = predicate.apply(null);
    return new ValueMatcher() {

        @Override
        public boolean matches() {
            final IndexedInts row = selector.getRow();
            final int size = row.size();
            if (size == 0) {
                // null should match empty rows in multi-value columns
                return matchNull;
            } else {
                for (int i = 0; i < size; ++i) {
                    if (predicate.apply(selector.lookupName(row.get(i)))) {
                        return true;
                    }
                }
                return false;
            }
        }

        @Override
        public void inspectRuntimeShape(RuntimeShapeInspector inspector) {
            inspector.visit("selector", selector);
            inspector.visit("predicate", predicate);
        }
    };
}
Also used : ValueMatcher(org.apache.druid.query.filter.ValueMatcher) BooleanValueMatcher(org.apache.druid.segment.filter.BooleanValueMatcher) IndexedInts(org.apache.druid.segment.data.IndexedInts) RuntimeShapeInspector(org.apache.druid.query.monomorphicprocessing.RuntimeShapeInspector)

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