use of org.apache.druid.segment.IndexableAdapter in project druid by druid-io.
the class IncrementalIndexAdapterTest method testGetBitmapIndex.
@Test
public void testGetBitmapIndex() throws Exception {
final long timestamp = System.currentTimeMillis();
IncrementalIndex incrementalIndex = indexCreator.createIndex("rollup");
IncrementalIndexTest.populateIndex(timestamp, incrementalIndex);
IndexableAdapter adapter = new IncrementalIndexAdapter(incrementalIndex.getInterval(), incrementalIndex, INDEX_SPEC.getBitmapSerdeFactory().getBitmapFactory());
String dimension = "dim1";
try (CloseableIndexed<String> dimValueLookup = adapter.getDimValueLookup(dimension)) {
for (int i = 0; i < dimValueLookup.size(); i++) {
BitmapValues bitmapValues = adapter.getBitmapValues(dimension, i);
Assert.assertEquals(1, bitmapValues.size());
}
}
}
use of org.apache.druid.segment.IndexableAdapter in project druid by druid-io.
the class IncrementalIndexAdapterTest method testGetRowsIterableNoRollup.
@Test
public void testGetRowsIterableNoRollup() throws Exception {
final long timestamp = System.currentTimeMillis();
IncrementalIndex toPersist1 = indexCreator.createIndex("plain");
IncrementalIndexTest.populateIndex(timestamp, toPersist1);
IncrementalIndexTest.populateIndex(timestamp, toPersist1);
IncrementalIndexTest.populateIndex(timestamp, toPersist1);
ArrayList<Integer> dim1Vals = new ArrayList<>();
for (IncrementalIndexRow row : toPersist1.getFacts().keySet()) {
dim1Vals.add(((int[]) row.getDims()[0])[0]);
}
ArrayList<Integer> dim2Vals = new ArrayList<>();
for (IncrementalIndexRow row : toPersist1.getFacts().keySet()) {
dim2Vals.add(((int[]) row.getDims()[1])[0]);
}
final IndexableAdapter incrementalAdapter = new IncrementalIndexAdapter(toPersist1.getInterval(), toPersist1, INDEX_SPEC.getBitmapSerdeFactory().getBitmapFactory());
RowIterator rows = incrementalAdapter.getRows();
List<String> rowStrings = new ArrayList<>();
while (rows.moveToNext()) {
rowStrings.add(rows.getPointer().toString());
}
Function<Integer, String> getExpected = (rowNumber) -> {
if (rowNumber < 3) {
return StringUtils.format("RowPointer{indexNum=0, rowNumber=%s, timestamp=%s, dimensions={dim1=1, dim2=2}, metrics={count=1}}", rowNumber, timestamp);
} else {
return StringUtils.format("RowPointer{indexNum=0, rowNumber=%s, timestamp=%s, dimensions={dim1=3, dim2=4}, metrics={count=1}}", rowNumber, timestamp);
}
};
// without sorting, output would be
// RowPointer{indexNum=0, rowNumber=0, timestamp=1533347274588, dimensions={dim1=1, dim2=2}, metrics={count=1}}
// RowPointer{indexNum=0, rowNumber=1, timestamp=1533347274588, dimensions={dim1=3, dim2=4}, metrics={count=1}}
// RowPointer{indexNum=0, rowNumber=2, timestamp=1533347274588, dimensions={dim1=1, dim2=2}, metrics={count=1}}
// RowPointer{indexNum=0, rowNumber=3, timestamp=1533347274588, dimensions={dim1=3, dim2=4}, metrics={count=1}}
// RowPointer{indexNum=0, rowNumber=4, timestamp=1533347274588, dimensions={dim1=1, dim2=2}, metrics={count=1}}
// RowPointer{indexNum=0, rowNumber=5, timestamp=1533347274588, dimensions={dim1=3, dim2=4}, metrics={count=1}}
// but with sorting, output should be
// RowPointer{indexNum=0, rowNumber=0, timestamp=1533347361396, dimensions={dim1=1, dim2=2}, metrics={count=1}}
// RowPointer{indexNum=0, rowNumber=1, timestamp=1533347361396, dimensions={dim1=1, dim2=2}, metrics={count=1}}
// RowPointer{indexNum=0, rowNumber=2, timestamp=1533347361396, dimensions={dim1=1, dim2=2}, metrics={count=1}}
// RowPointer{indexNum=0, rowNumber=3, timestamp=1533347361396, dimensions={dim1=3, dim2=4}, metrics={count=1}}
// RowPointer{indexNum=0, rowNumber=4, timestamp=1533347361396, dimensions={dim1=3, dim2=4}, metrics={count=1}}
// RowPointer{indexNum=0, rowNumber=5, timestamp=1533347361396, dimensions={dim1=3, dim2=4}, metrics={count=1}}
Assert.assertEquals(6, rowStrings.size());
for (int i = 0; i < 6; i++) {
if (i % 2 == 0) {
Assert.assertEquals(0, (long) dim1Vals.get(i));
Assert.assertEquals(0, (long) dim2Vals.get(i));
} else {
Assert.assertEquals(1, (long) dim1Vals.get(i));
Assert.assertEquals(1, (long) dim2Vals.get(i));
}
Assert.assertEquals(getExpected.apply(i), rowStrings.get(i));
}
}
use of org.apache.druid.segment.IndexableAdapter in project druid by druid-io.
the class IncrementalIndexAdapterTest method testGetRowsIterable.
@Test
public void testGetRowsIterable() throws Exception {
final long timestamp = System.currentTimeMillis();
IncrementalIndex toPersist1 = indexCreator.createIndex("rollup");
IncrementalIndexTest.populateIndex(timestamp, toPersist1);
final IndexableAdapter incrementalAdapter = new IncrementalIndexAdapter(toPersist1.getInterval(), toPersist1, INDEX_SPEC.getBitmapSerdeFactory().getBitmapFactory());
RowIterator rows = incrementalAdapter.getRows();
List<Integer> rowNums = new ArrayList<>();
while (rows.moveToNext()) {
rowNums.add(rows.getPointer().getRowNum());
}
Assert.assertEquals(2, rowNums.size());
Assert.assertEquals(0, (long) rowNums.get(0));
Assert.assertEquals(1, (long) rowNums.get(1));
}
Aggregations