Search in sources :

Example 1 with IndexedInts

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

the class IncrementalIndexAdapterTest method testGetBitmapIndex.

@Test
public void testGetBitmapIndex() throws Exception {
    final long timestamp = System.currentTimeMillis();
    IncrementalIndex incrementalIndex = IncrementalIndexTest.createIndex(null);
    IncrementalIndexTest.populateIndex(timestamp, incrementalIndex);
    IndexableAdapter adapter = new IncrementalIndexAdapter(incrementalIndex.getInterval(), incrementalIndex, INDEX_SPEC.getBitmapSerdeFactory().getBitmapFactory());
    String dimension = "dim1";
    for (int i = 0; i < adapter.getDimValueLookup(dimension).size(); i++) {
        IndexedInts indexedInts = adapter.getBitmapIndex(dimension, i);
        Assert.assertEquals(1, indexedInts.size());
    }
}
Also used : IndexedInts(io.druid.segment.data.IndexedInts) IndexableAdapter(io.druid.segment.IndexableAdapter) IncrementalIndexTest(io.druid.segment.data.IncrementalIndexTest) Test(org.junit.Test)

Example 2 with IndexedInts

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

the class IncrementalIndexStorageAdapterTest method testCursoringAndIndexUpdationInterleaving.

@Test
public void testCursoringAndIndexUpdationInterleaving() throws Exception {
    final IncrementalIndex index = indexCreator.createIndex();
    final long timestamp = System.currentTimeMillis();
    for (int i = 0; i < 2; i++) {
        index.add(new MapBasedInputRow(timestamp, Lists.newArrayList("billy"), ImmutableMap.<String, Object>of("billy", "v1" + i)));
    }
    final StorageAdapter sa = new IncrementalIndexStorageAdapter(index);
    Sequence<Cursor> cursors = sa.makeCursors(null, new Interval(timestamp - 60_000, timestamp + 60_000), VirtualColumns.EMPTY, Granularities.ALL, false);
    Sequences.toList(Sequences.map(cursors, new Function<Cursor, Object>() {

        @Nullable
        @Override
        public Object apply(Cursor cursor) {
            DimensionSelector dimSelector = cursor.makeDimensionSelector(new DefaultDimensionSpec("billy", "billy"));
            int cardinality = dimSelector.getValueCardinality();
            //index gets more rows at this point, while other thread is iterating over the cursor
            try {
                for (int i = 0; i < 1; i++) {
                    index.add(new MapBasedInputRow(timestamp, Lists.newArrayList("billy"), ImmutableMap.<String, Object>of("billy", "v2" + i)));
                }
            } catch (Exception ex) {
                throw new RuntimeException(ex);
            }
            // and then, cursoring continues in the other thread
            while (!cursor.isDone()) {
                IndexedInts row = dimSelector.getRow();
                for (int i : row) {
                    Assert.assertTrue(i < cardinality);
                }
                cursor.advance();
            }
            return null;
        }
    }), new ArrayList<>());
}
Also used : DimensionSelector(io.druid.segment.DimensionSelector) StorageAdapter(io.druid.segment.StorageAdapter) Cursor(io.druid.segment.Cursor) DefaultDimensionSpec(io.druid.query.dimension.DefaultDimensionSpec) IOException(java.io.IOException) Function(com.google.common.base.Function) IndexedInts(io.druid.segment.data.IndexedInts) MapBasedInputRow(io.druid.data.input.MapBasedInputRow) Interval(org.joda.time.Interval) Test(org.junit.Test)

Example 3 with IndexedInts

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

the class DumpSegment method makeSelector.

private static ObjectColumnSelector makeSelector(final String columnName, final Column column, final ColumnSelectorFactory columnSelectorFactory) {
    final ObjectColumnSelector selector;
    if (column.getDictionaryEncoding() != null) {
        // Special case for dimensions -> always wrap multi-value in arrays
        final DimensionSelector dimensionSelector = columnSelectorFactory.makeDimensionSelector(new DefaultDimensionSpec(columnName, columnName));
        if (column.getDictionaryEncoding().hasMultipleValues()) {
            return new ObjectColumnSelector<List>() {

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

                @Override
                public List<String> get() {
                    final IndexedInts row = dimensionSelector.getRow();
                    if (row.size() == 0) {
                        return null;
                    } else {
                        final List<String> retVal = Lists.newArrayList();
                        for (int i = 0; i < row.size(); i++) {
                            retVal.add(dimensionSelector.lookupName(row.get(i)));
                        }
                        return retVal;
                    }
                }
            };
        } else {
            return new ObjectColumnSelector<String>() {

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

                @Override
                public String get() {
                    final IndexedInts row = dimensionSelector.getRow();
                    return row.size() == 0 ? null : dimensionSelector.lookupName(row.get(0));
                }
            };
        }
    } else {
        final ObjectColumnSelector maybeSelector = columnSelectorFactory.makeObjectColumnSelector(columnName);
        if (maybeSelector != null) {
            selector = maybeSelector;
        } else {
            // Selector failed to create (unrecognized column type?)
            log.warn("Could not create selector for column[%s], returning null.", columnName);
            selector = new ObjectColumnSelector() {

                @Override
                public Class classOfObject() {
                    return Object.class;
                }

                @Override
                public Object get() {
                    return null;
                }
            };
        }
    }
    return selector;
}
Also used : DimensionSelector(io.druid.segment.DimensionSelector) IndexedInts(io.druid.segment.data.IndexedInts) List(java.util.List) ImmutableList(com.google.common.collect.ImmutableList) DefaultDimensionSpec(io.druid.query.dimension.DefaultDimensionSpec) ObjectColumnSelector(io.druid.segment.ObjectColumnSelector)

Example 4 with IndexedInts

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

the class IncrementalIndexReadBenchmark method read.

@Benchmark
@BenchmarkMode(Mode.AverageTime)
@OutputTimeUnit(TimeUnit.MICROSECONDS)
public void read(Blackhole blackhole) throws Exception {
    IncrementalIndexStorageAdapter sa = new IncrementalIndexStorageAdapter(incIndex);
    Sequence<Cursor> cursors = makeCursors(sa, null);
    Cursor cursor = Sequences.toList(Sequences.limit(cursors, 1), Lists.<Cursor>newArrayList()).get(0);
    List<DimensionSelector> selectors = new ArrayList<>();
    selectors.add(cursor.makeDimensionSelector(new DefaultDimensionSpec("dimSequential", null)));
    selectors.add(cursor.makeDimensionSelector(new DefaultDimensionSpec("dimZipf", null)));
    selectors.add(cursor.makeDimensionSelector(new DefaultDimensionSpec("dimUniform", null)));
    selectors.add(cursor.makeDimensionSelector(new DefaultDimensionSpec("dimSequentialHalfNull", null)));
    cursor.reset();
    while (!cursor.isDone()) {
        for (DimensionSelector selector : selectors) {
            IndexedInts row = selector.getRow();
            blackhole.consume(selector.lookupName(row.get(0)));
        }
        cursor.advance();
    }
}
Also used : DimensionSelector(io.druid.segment.DimensionSelector) IndexedInts(io.druid.segment.data.IndexedInts) IncrementalIndexStorageAdapter(io.druid.segment.incremental.IncrementalIndexStorageAdapter) ArrayList(java.util.ArrayList) Cursor(io.druid.segment.Cursor) DefaultDimensionSpec(io.druid.query.dimension.DefaultDimensionSpec) BenchmarkMode(org.openjdk.jmh.annotations.BenchmarkMode) Benchmark(org.openjdk.jmh.annotations.Benchmark) OutputTimeUnit(org.openjdk.jmh.annotations.OutputTimeUnit)

Example 5 with IndexedInts

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

the class DictionaryBuildingStringGroupByColumnSelectorStrategy method initColumnValues.

@Override
public void initColumnValues(ColumnValueSelector selector, int columnIndex, Object[] valuess) {
    final DimensionSelector dimSelector = (DimensionSelector) selector;
    final IndexedInts row = dimSelector.getRow();
    final int[] newIds = new int[row.size()];
    for (int i = 0; i < row.size(); i++) {
        final String value = dimSelector.lookupName(row.get(i));
        final int dictId = reverseDictionary.getInt(value);
        if (dictId < 0) {
            dictionary.add(value);
            reverseDictionary.put(value, nextId);
            newIds[i] = nextId;
            nextId++;
        } else {
            newIds[i] = dictId;
        }
    }
    valuess[columnIndex] = ArrayBasedIndexedInts.of(newIds);
}
Also used : DimensionSelector(io.druid.segment.DimensionSelector) ArrayBasedIndexedInts(io.druid.segment.data.ArrayBasedIndexedInts) IndexedInts(io.druid.segment.data.IndexedInts)

Aggregations

IndexedInts (io.druid.segment.data.IndexedInts)41 DimensionSelector (io.druid.segment.DimensionSelector)14 ValueMatcher (io.druid.query.filter.ValueMatcher)9 ArrayBasedIndexedInts (io.druid.segment.data.ArrayBasedIndexedInts)8 Test (org.junit.Test)8 DefaultDimensionSpec (io.druid.query.dimension.DefaultDimensionSpec)6 Cursor (io.druid.segment.Cursor)6 BooleanValueMatcher (io.druid.segment.filter.BooleanValueMatcher)6 ArrayList (java.util.ArrayList)5 ByteBuffer (java.nio.ByteBuffer)3 BitSet (java.util.BitSet)3 Function (com.google.common.base.Function)2 ImmutableList (com.google.common.collect.ImmutableList)2 IAE (io.druid.java.util.common.IAE)2 Aggregator (io.druid.query.aggregation.Aggregator)2 DimFilter (io.druid.query.filter.DimFilter)2 ColumnSelectorFactory (io.druid.segment.ColumnSelectorFactory)2 IdLookup (io.druid.segment.IdLookup)2 CompressedVSizeIntsIndexedSupplier (io.druid.segment.data.CompressedVSizeIntsIndexedSupplier)2 IncrementalIndexTest (io.druid.segment.data.IncrementalIndexTest)2