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());
}
}
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<>());
}
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;
}
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();
}
}
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);
}
Aggregations