Search in sources :

Example 26 with IndexedInts

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

the class FilterPartitionBenchmark method readCursors.

private void readCursors(Sequence<Cursor> cursors, Blackhole blackhole) {
    final Sequence<Void> voids = Sequences.map(cursors, input -> {
        List<DimensionSelector> selectors = new ArrayList<>();
        selectors.add(input.getColumnSelectorFactory().makeDimensionSelector(new DefaultDimensionSpec("dimSequential", null)));
        while (!input.isDone()) {
            for (DimensionSelector selector : selectors) {
                IndexedInts row = selector.getRow();
                blackhole.consume(selector.lookupName(row.get(0)));
            }
            input.advance();
        }
        return null;
    });
    blackhole.consume(voids.toList());
}
Also used : DimensionSelector(org.apache.druid.segment.DimensionSelector) IndexedInts(org.apache.druid.segment.data.IndexedInts) ArrayList(java.util.ArrayList) DefaultDimensionSpec(org.apache.druid.query.dimension.DefaultDimensionSpec)

Example 27 with IndexedInts

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

the class ArrayOfDoublesSketchBuildAggregator method aggregate.

/**
 * This method uses synchronization because it can be used during indexing,
 * and Druid can call aggregate() and get() concurrently
 * https://github.com/apache/druid/pull/3956
 */
@Override
public void aggregate() {
    final IndexedInts keys = keySelector.getRow();
    for (int i = 0; i < valueSelectors.length; i++) {
        if (valueSelectors[i].isNull()) {
            return;
        } else {
            values[i] = valueSelectors[i].getDouble();
        }
    }
    synchronized (this) {
        if (canLookupUtf8) {
            for (int i = 0, keysSize = keys.size(); i < keysSize; i++) {
                final ByteBuffer key;
                if (canCacheById) {
                    key = (ByteBuffer) stringCache.computeIfAbsent(keys.get(i), keySelector::lookupNameUtf8);
                } else {
                    key = keySelector.lookupNameUtf8(keys.get(i));
                }
                if (key != null) {
                    byte[] bytes = new byte[key.remaining()];
                    key.mark();
                    key.get(bytes);
                    key.reset();
                    sketch.update(bytes, values);
                }
            }
        } else {
            for (int i = 0, keysSize = keys.size(); i < keysSize; i++) {
                final String key;
                if (canCacheById) {
                    key = (String) stringCache.computeIfAbsent(keys.get(i), keySelector::lookupName);
                } else {
                    key = keySelector.lookupName(keys.get(i));
                }
                sketch.update(key, values);
            }
        }
    }
}
Also used : IndexedInts(org.apache.druid.segment.data.IndexedInts) ByteBuffer(java.nio.ByteBuffer)

Example 28 with IndexedInts

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

the class MapVirtualColumn method makeColumnValueSelector.

@Override
public ColumnValueSelector<?> makeColumnValueSelector(String columnName, ColumnSelectorFactory factory) {
    final DimensionSelector keySelector = factory.makeDimensionSelector(DefaultDimensionSpec.of(keyDimension));
    final DimensionSelector valueSelector = factory.makeDimensionSelector(DefaultDimensionSpec.of(valueDimension));
    final String subColumnName = VirtualColumns.splitColumnName(columnName).rhs;
    if (subColumnName == null) {
        return new MapVirtualColumnValueSelector<Map>(keySelector, valueSelector) {

            @Override
            public Class<Map> classOfObject() {
                return Map.class;
            }

            @Override
            public Map getObject() {
                final IndexedInts keyIndices = keySelector.getRow();
                final IndexedInts valueIndices = valueSelector.getRow();
                final int limit = Math.min(keyIndices.size(), valueIndices.size());
                final Map<String, String> map = Maps.newHashMapWithExpectedSize(limit);
                for (int i = 0; i < limit; i++) {
                    map.put(keySelector.lookupName(keyIndices.get(i)), valueSelector.lookupName(valueIndices.get(i)));
                }
                return map;
            }
        };
    }
    IdLookup keyIdLookup = keySelector.idLookup();
    if (keyIdLookup != null) {
        final int keyId = keyIdLookup.lookupId(subColumnName);
        if (keyId < 0) {
            return NilColumnValueSelector.instance();
        }
        return new MapVirtualColumnValueSelector<String>(keySelector, valueSelector) {

            @Override
            public Class<String> classOfObject() {
                return String.class;
            }

            @Nullable
            @Override
            public String getObject() {
                final IndexedInts keyIndices = keySelector.getRow();
                final IndexedInts valueIndices = valueSelector.getRow();
                final int limit = Math.min(keyIndices.size(), valueIndices.size());
                for (int i = 0; i < limit; i++) {
                    if (keyIndices.get(i) == keyId) {
                        return valueSelector.lookupName(valueIndices.get(i));
                    }
                }
                return null;
            }
        };
    } else {
        return new MapVirtualColumnValueSelector<String>(keySelector, valueSelector) {

            @Override
            public Class<String> classOfObject() {
                return String.class;
            }

            @Nullable
            @Override
            public String getObject() {
                final IndexedInts keyIndices = keySelector.getRow();
                final IndexedInts valueIndices = valueSelector.getRow();
                final int limit = Math.min(keyIndices.size(), valueIndices.size());
                for (int i = 0; i < limit; i++) {
                    if (Objects.equals(keySelector.lookupName(keyIndices.get(i)), subColumnName)) {
                        return valueSelector.lookupName(valueIndices.get(i));
                    }
                }
                return null;
            }
        };
    }
}
Also used : IndexedInts(org.apache.druid.segment.data.IndexedInts) Map(java.util.Map)

Example 29 with IndexedInts

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

the class StringTypeMapVirtualColumnDimensionSelector method findValueIndicesIndexForSubColumn.

/**
 * Find the index of valueIndices which is {@link IndexedInts} returned from {@link #getValueSelector()#getRow()}
 * corresponding to the {@link #subColumnName}.
 *
 * @return index for valueIndices if found. -1 otherwise.
 */
private int findValueIndicesIndexForSubColumn() {
    final DimensionSelector keySelector = getKeySelector();
    final DimensionSelector valueSelector = getValueSelector();
    final IndexedInts keyIndices = keySelector.getRow();
    final IndexedInts valueIndices = valueSelector.getRow();
    final int limit = Math.min(keyIndices.size(), valueIndices.size());
    return IntStream.range(0, limit).filter(// subColumnName is never null
    i -> subColumnName.equals(keySelector.lookupName(keyIndices.get(i)))).findAny().orElse(-1);
}
Also used : ZeroIndexedInts(org.apache.druid.segment.data.ZeroIndexedInts) IndexedInts(org.apache.druid.segment.data.IndexedInts)

Example 30 with IndexedInts

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

the class StringTypeMapVirtualColumnDimensionSelector method getObject.

@Nullable
@Override
public Object getObject() {
    final int valueIndex = findValueIndicesIndexForSubColumn();
    if (valueIndex < 0) {
        return null;
    } else {
        final DimensionSelector valueSelector = getValueSelector();
        final IndexedInts valueIndices = valueSelector.getRow();
        return valueSelector.lookupName(valueIndices.get(valueIndex));
    }
}
Also used : ZeroIndexedInts(org.apache.druid.segment.data.ZeroIndexedInts) IndexedInts(org.apache.druid.segment.data.IndexedInts) Nullable(javax.annotation.Nullable)

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