use of org.apache.druid.segment.incremental.IncrementalIndexSchema in project druid by druid-io.
the class IndexMergerTestBase method testMaxColumnsToMerge.
@Test
public void testMaxColumnsToMerge() throws Exception {
IncrementalIndexSchema indexSchema = new IncrementalIndexSchema.Builder().withMetrics(new CountAggregatorFactory("count")).withRollup(true).build();
IncrementalIndex toPersistA = new OnheapIncrementalIndex.Builder().setIndexSchema(indexSchema).setMaxRowCount(1000).build();
toPersistA.add(getRowForTestMaxColumnsToMerge(10000, "a", "b", "c", "d", "e"));
toPersistA.add(getRowForTestMaxColumnsToMerge(99999, "1", "2", "3", "4", "5"));
IncrementalIndex toPersistB = new OnheapIncrementalIndex.Builder().setIndexSchema(indexSchema).setMaxRowCount(1000).build();
toPersistB.add(getRowForTestMaxColumnsToMerge(20000, "aa", "bb", "cc", "dd", "ee"));
toPersistB.add(getRowForTestMaxColumnsToMerge(99999, "1", "2", "3", "4", "5"));
IncrementalIndex toPersistC = new OnheapIncrementalIndex.Builder().setIndexSchema(indexSchema).setMaxRowCount(1000).build();
toPersistC.add(getRowForTestMaxColumnsToMerge(30000, "aaa", "bbb", "ccc", "ddd", "eee"));
toPersistC.add(getRowForTestMaxColumnsToMerge(99999, "1", "2", "3", "4", "5"));
final File tmpDirA = temporaryFolder.newFolder();
final File tmpDirB = temporaryFolder.newFolder();
final File tmpDirC = temporaryFolder.newFolder();
QueryableIndex indexA = closer.closeLater(indexIO.loadIndex(indexMerger.persist(toPersistA, tmpDirA, indexSpec, null)));
QueryableIndex indexB = closer.closeLater(indexIO.loadIndex(indexMerger.persist(toPersistB, tmpDirB, indexSpec, null)));
QueryableIndex indexC = closer.closeLater(indexIO.loadIndex(indexMerger.persist(toPersistC, tmpDirC, indexSpec, null)));
// no column limit
final File tmpDirMerged0 = temporaryFolder.newFolder();
final QueryableIndex merged0 = closer.closeLater(indexIO.loadIndex(indexMerger.mergeQueryableIndex(Arrays.asList(indexA, indexB, indexC), true, new AggregatorFactory[] { new CountAggregatorFactory("count") }, tmpDirMerged0, indexSpec, null, -1)));
validateTestMaxColumnsToMergeOutputSegment(merged0);
// column limit is greater than total # of columns
final File tmpDirMerged1 = temporaryFolder.newFolder();
final QueryableIndex merged1 = closer.closeLater(indexIO.loadIndex(indexMerger.mergeQueryableIndex(Arrays.asList(indexA, indexB, indexC), true, new AggregatorFactory[] { new CountAggregatorFactory("count") }, tmpDirMerged1, indexSpec, null, 50)));
validateTestMaxColumnsToMergeOutputSegment(merged1);
// column limit is greater than 2 segments worth of columns
final File tmpDirMerged2 = temporaryFolder.newFolder();
final QueryableIndex merged2 = closer.closeLater(indexIO.loadIndex(indexMerger.mergeQueryableIndex(Arrays.asList(indexA, indexB, indexC), true, new AggregatorFactory[] { new CountAggregatorFactory("count") }, tmpDirMerged2, indexSpec, null, 15)));
validateTestMaxColumnsToMergeOutputSegment(merged2);
// column limit is between 1 and 2 segments worth of columns (merge two segments at once)
final File tmpDirMerged3 = temporaryFolder.newFolder();
final QueryableIndex merged3 = closer.closeLater(indexIO.loadIndex(indexMerger.mergeQueryableIndex(Arrays.asList(indexA, indexB, indexC), true, new AggregatorFactory[] { new CountAggregatorFactory("count") }, tmpDirMerged3, indexSpec, null, 9)));
validateTestMaxColumnsToMergeOutputSegment(merged3);
// column limit is less than 1 segment
final File tmpDirMerged4 = temporaryFolder.newFolder();
final QueryableIndex merged4 = closer.closeLater(indexIO.loadIndex(indexMerger.mergeQueryableIndex(Arrays.asList(indexA, indexB, indexC), true, new AggregatorFactory[] { new CountAggregatorFactory("count") }, tmpDirMerged4, indexSpec, null, 3)));
validateTestMaxColumnsToMergeOutputSegment(merged4);
// column limit is exactly 1 segment's worth of columns
final File tmpDirMerged5 = temporaryFolder.newFolder();
final QueryableIndex merged5 = closer.closeLater(indexIO.loadIndex(indexMerger.mergeQueryableIndex(Arrays.asList(indexA, indexB, indexC), true, new AggregatorFactory[] { new CountAggregatorFactory("count") }, tmpDirMerged5, indexSpec, null, 6)));
validateTestMaxColumnsToMergeOutputSegment(merged5);
// column limit is exactly 2 segment's worth of columns
final File tmpDirMerged6 = temporaryFolder.newFolder();
final QueryableIndex merged6 = closer.closeLater(indexIO.loadIndex(indexMerger.mergeQueryableIndex(Arrays.asList(indexA, indexB, indexC), true, new AggregatorFactory[] { new CountAggregatorFactory("count") }, tmpDirMerged6, indexSpec, null, 12)));
validateTestMaxColumnsToMergeOutputSegment(merged6);
// column limit is exactly the total number of columns
final File tmpDirMerged7 = temporaryFolder.newFolder();
final QueryableIndex merged7 = closer.closeLater(indexIO.loadIndex(indexMerger.mergeQueryableIndex(Arrays.asList(indexA, indexB, indexC), true, new AggregatorFactory[] { new CountAggregatorFactory("count") }, tmpDirMerged7, indexSpec, null, 18)));
validateTestMaxColumnsToMergeOutputSegment(merged7);
}
use of org.apache.druid.segment.incremental.IncrementalIndexSchema in project druid by druid-io.
the class IndexMergerTestBase method testMergeWithDimensionsList.
@Test
public void testMergeWithDimensionsList() throws Exception {
IncrementalIndexSchema schema = new IncrementalIndexSchema.Builder().withDimensionsSpec(new DimensionsSpec(makeDimensionSchemas(Arrays.asList("dimA", "dimB", "dimC")))).withMetrics(new CountAggregatorFactory("count")).build();
IncrementalIndex toPersist1 = new OnheapIncrementalIndex.Builder().setIndexSchema(schema).setMaxRowCount(1000).build();
IncrementalIndex toPersist2 = new OnheapIncrementalIndex.Builder().setIndexSchema(schema).setMaxRowCount(1000).build();
IncrementalIndex toPersist3 = new OnheapIncrementalIndex.Builder().setIndexSchema(schema).setMaxRowCount(1000).build();
addDimValuesToIndex(toPersist1, "dimA", Arrays.asList("1", "2"));
addDimValuesToIndex(toPersist2, "dimA", Arrays.asList("1", "2"));
addDimValuesToIndex(toPersist3, "dimC", Arrays.asList("1", "2"));
final File tmpDir = temporaryFolder.newFolder();
final File tmpDir2 = temporaryFolder.newFolder();
final File tmpDir3 = temporaryFolder.newFolder();
final File tmpDirMerged = temporaryFolder.newFolder();
QueryableIndex index1 = closer.closeLater(indexIO.loadIndex(indexMerger.persist(toPersist1, tmpDir, indexSpec, null)));
QueryableIndex index2 = closer.closeLater(indexIO.loadIndex(indexMerger.persist(toPersist2, tmpDir2, indexSpec, null)));
QueryableIndex index3 = closer.closeLater(indexIO.loadIndex(indexMerger.persist(toPersist3, tmpDir3, indexSpec, null)));
final QueryableIndex merged = closer.closeLater(indexIO.loadIndex(indexMerger.mergeQueryableIndex(Arrays.asList(index1, index2, index3), true, new AggregatorFactory[] { new CountAggregatorFactory("count") }, tmpDirMerged, indexSpec, null, -1)));
final QueryableIndexIndexableAdapter adapter = new QueryableIndexIndexableAdapter(merged);
final List<DebugRow> rowList = RowIteratorHelper.toList(adapter.getRows());
Assert.assertEquals(ImmutableList.of("dimA", "dimC"), ImmutableList.copyOf(adapter.getDimensionNames()));
Assert.assertEquals(4, rowList.size());
Assert.assertEquals(Arrays.asList(null, "1"), rowList.get(0).dimensionValues());
Assert.assertEquals(Collections.singletonList(1L), rowList.get(0).metricValues());
Assert.assertEquals(Arrays.asList(null, "2"), rowList.get(1).dimensionValues());
Assert.assertEquals(Collections.singletonList(1L), rowList.get(1).metricValues());
Assert.assertEquals(Arrays.asList("1", null), rowList.get(2).dimensionValues());
Assert.assertEquals(Collections.singletonList(2L), rowList.get(2).metricValues());
Assert.assertEquals(Arrays.asList("2", null), rowList.get(3).dimensionValues());
Assert.assertEquals(Collections.singletonList(2L), rowList.get(3).metricValues());
Assert.assertEquals(useBitmapIndexes, adapter.getCapabilities("dimA").hasBitmapIndexes());
Assert.assertEquals(useBitmapIndexes, adapter.getCapabilities("dimC").hasBitmapIndexes());
if (useBitmapIndexes) {
checkBitmapIndex(Arrays.asList(0, 1), adapter.getBitmapIndex("dimA", null));
checkBitmapIndex(Collections.singletonList(2), adapter.getBitmapIndex("dimA", "1"));
checkBitmapIndex(Collections.singletonList(3), adapter.getBitmapIndex("dimA", "2"));
checkBitmapIndex(Collections.emptyList(), adapter.getBitmapIndex("dimB", null));
checkBitmapIndex(Arrays.asList(2, 3), adapter.getBitmapIndex("dimC", null));
checkBitmapIndex(Collections.singletonList(0), adapter.getBitmapIndex("dimC", "1"));
checkBitmapIndex(Collections.singletonList(1), adapter.getBitmapIndex("dimC", "2"));
}
checkBitmapIndex(Collections.emptyList(), adapter.getBitmapIndex("dimB", ""));
}
use of org.apache.druid.segment.incremental.IncrementalIndexSchema in project druid by druid-io.
the class IndexMergerTestBase method testNoRollupMergeWithDuplicateRow.
@Test
public void testNoRollupMergeWithDuplicateRow() throws Exception {
// (d3, d6, d8, d9) as actually data from index1 and index2
// index1 has two duplicate rows
// index2 has 1 row which is same as index1 row and another different row
// then we can test
// 1. incrementalIndex with duplicate rows
// 2. incrementalIndex without duplicate rows
// 3. merge 2 indexes with duplicate rows
IncrementalIndexSchema indexSchema = new IncrementalIndexSchema.Builder().withMetrics(new CountAggregatorFactory("count")).withRollup(false).build();
IncrementalIndex toPersistA = new OnheapIncrementalIndex.Builder().setIndexSchema(indexSchema).setMaxRowCount(1000).build();
toPersistA.add(new MapBasedInputRow(1, Arrays.asList("d1", "d2", "d3", "d4", "d5", "d6", "d7", "d8", "d9"), ImmutableMap.of("d1", "", "d2", "", "d3", "310", "d7", "", "d9", "910")));
toPersistA.add(new MapBasedInputRow(1, Arrays.asList("d1", "d2", "d3", "d4", "d5", "d6", "d7", "d8", "d9"), ImmutableMap.of("d1", "", "d2", "", "d3", "310", "d7", "", "d9", "910")));
IncrementalIndex toPersistB = new OnheapIncrementalIndex.Builder().setIndexSchema(indexSchema).setMaxRowCount(1000).build();
toPersistB.add(new MapBasedInputRow(1, Arrays.asList("d1", "d2", "d3", "d4", "d5", "d6", "d7", "d8", "d9"), ImmutableMap.of("d1", "", "d2", "", "d3", "310", "d7", "", "d9", "910")));
toPersistB.add(new MapBasedInputRow(4, Arrays.asList("d4", "d5", "d6", "d7", "d8", "d9"), ImmutableMap.of("d5", "", "d6", "621", "d7", "", "d8", "821", "d9", "921")));
final File tmpDirA = temporaryFolder.newFolder();
final File tmpDirB = temporaryFolder.newFolder();
final File tmpDirMerged = temporaryFolder.newFolder();
QueryableIndex indexA = closer.closeLater(indexIO.loadIndex(indexMerger.persist(toPersistA, tmpDirA, indexSpec, null)));
QueryableIndex indexB = closer.closeLater(indexIO.loadIndex(indexMerger.persist(toPersistB, tmpDirB, indexSpec, null)));
final QueryableIndex merged = closer.closeLater(indexIO.loadIndex(indexMerger.mergeQueryableIndex(Arrays.asList(indexA, indexB), false, new AggregatorFactory[] { new CountAggregatorFactory("count") }, tmpDirMerged, indexSpec, null, -1)));
final QueryableIndexIndexableAdapter adapter = new QueryableIndexIndexableAdapter(merged);
final List<DebugRow> rowList = RowIteratorHelper.toList(adapter.getRows());
if (NullHandling.replaceWithDefault()) {
Assert.assertEquals(ImmutableList.of("d3", "d6", "d8", "d9"), ImmutableList.copyOf(adapter.getDimensionNames()));
} else {
Assert.assertEquals(ImmutableList.of("d1", "d2", "d3", "d5", "d6", "d7", "d8", "d9"), ImmutableList.copyOf(adapter.getDimensionNames()));
}
Assert.assertEquals(4, rowList.size());
if (NullHandling.replaceWithDefault()) {
Assert.assertEquals(Arrays.asList("310", null, null, "910"), rowList.get(0).dimensionValues());
Assert.assertEquals(Arrays.asList("310", null, null, "910"), rowList.get(1).dimensionValues());
Assert.assertEquals(Arrays.asList("310", null, null, "910"), rowList.get(2).dimensionValues());
Assert.assertEquals(Arrays.asList(null, "621", "821", "921"), rowList.get(3).dimensionValues());
} else {
Assert.assertEquals(Arrays.asList("", "", "310", null, null, "", null, "910"), rowList.get(0).dimensionValues());
Assert.assertEquals(Arrays.asList("", "", "310", null, null, "", null, "910"), rowList.get(1).dimensionValues());
Assert.assertEquals(Arrays.asList("", "", "310", null, null, "", null, "910"), rowList.get(2).dimensionValues());
Assert.assertEquals(Arrays.asList(null, null, null, "", "621", "", "821", "921"), rowList.get(3).dimensionValues());
}
checkBitmapIndex(Collections.singletonList(3), adapter.getBitmapIndex("d3", null));
checkBitmapIndex(Arrays.asList(0, 1, 2), adapter.getBitmapIndex("d3", "310"));
checkBitmapIndex(Arrays.asList(0, 1, 2), adapter.getBitmapIndex("d6", null));
checkBitmapIndex(Collections.singletonList(3), adapter.getBitmapIndex("d6", "621"));
checkBitmapIndex(Arrays.asList(0, 1, 2), adapter.getBitmapIndex("d8", null));
checkBitmapIndex(Collections.singletonList(3), adapter.getBitmapIndex("d8", "821"));
checkBitmapIndex(Collections.emptyList(), adapter.getBitmapIndex("d9", null));
checkBitmapIndex(Arrays.asList(0, 1, 2), adapter.getBitmapIndex("d9", "910"));
checkBitmapIndex(Collections.singletonList(3), adapter.getBitmapIndex("d9", "921"));
}
use of org.apache.druid.segment.incremental.IncrementalIndexSchema in project druid by druid-io.
the class IndexMergerTestBase method testJointDimMerge.
@Test
public void testJointDimMerge() throws Exception {
// (d1, d2, d3) from only one index, and their dim values are ('empty', 'has null', 'no null')
// (d4, d5, d6, d7, d8, d9) are from both indexes
// d4: 'empty' join 'empty'
// d5: 'empty' join 'has null'
// d6: 'empty' join 'no null'
// d7: 'has null' join 'has null'
// d8: 'has null' join 'no null'
// d9: 'no null' join 'no null'
IncrementalIndexSchema rollupIndexSchema = new IncrementalIndexSchema.Builder().withMetrics(new CountAggregatorFactory("count")).build();
IncrementalIndexSchema noRollupIndexSchema = new IncrementalIndexSchema.Builder().withMetrics(new CountAggregatorFactory("count")).withRollup(false).build();
for (IncrementalIndexSchema indexSchema : Arrays.asList(rollupIndexSchema, noRollupIndexSchema)) {
IncrementalIndex toPersistA = new OnheapIncrementalIndex.Builder().setIndexSchema(indexSchema).setMaxRowCount(1000).build();
toPersistA.add(new MapBasedInputRow(1, Arrays.asList("d1", "d2", "d3", "d4", "d5", "d6", "d7", "d8", "d9"), ImmutableMap.of("d1", "", "d2", "", "d3", "310", "d7", "", "d9", "910")));
toPersistA.add(new MapBasedInputRow(2, Arrays.asList("d1", "d2", "d3", "d4", "d5", "d6", "d7", "d8", "d9"), ImmutableMap.of("d2", "210", "d3", "311", "d7", "710", "d8", "810", "d9", "911")));
IncrementalIndex toPersistB = new OnheapIncrementalIndex.Builder().setIndexSchema(indexSchema).setMaxRowCount(1000).build();
toPersistB.add(new MapBasedInputRow(3, Arrays.asList("d4", "d5", "d6", "d7", "d8", "d9"), ImmutableMap.of("d5", "520", "d6", "620", "d7", "720", "d8", "820", "d9", "920")));
toPersistB.add(new MapBasedInputRow(4, Arrays.asList("d4", "d5", "d6", "d7", "d8", "d9"), ImmutableMap.of("d5", "", "d6", "621", "d7", "", "d8", "821", "d9", "921")));
final File tmpDirA = temporaryFolder.newFolder();
final File tmpDirB = temporaryFolder.newFolder();
final File tmpDirMerged = temporaryFolder.newFolder();
QueryableIndex indexA = closer.closeLater(indexIO.loadIndex(indexMerger.persist(toPersistA, tmpDirA, indexSpec, null)));
QueryableIndex indexB = closer.closeLater(indexIO.loadIndex(indexMerger.persist(toPersistB, tmpDirB, indexSpec, null)));
final QueryableIndex merged = closer.closeLater(indexIO.loadIndex(indexMerger.mergeQueryableIndex(Arrays.asList(indexA, indexB), true, new AggregatorFactory[] { new CountAggregatorFactory("count") }, tmpDirMerged, indexSpec, null, -1)));
final QueryableIndexIndexableAdapter adapter = new QueryableIndexIndexableAdapter(merged);
final List<DebugRow> rowList = RowIteratorHelper.toList(adapter.getRows());
if (NullHandling.replaceWithDefault()) {
Assert.assertEquals(ImmutableList.of("d2", "d3", "d5", "d6", "d7", "d8", "d9"), ImmutableList.copyOf(adapter.getDimensionNames()));
} else {
Assert.assertEquals(ImmutableList.of("d1", "d2", "d3", "d5", "d6", "d7", "d8", "d9"), ImmutableList.copyOf(adapter.getDimensionNames()));
}
Assert.assertEquals(4, rowList.size());
if (NullHandling.replaceWithDefault()) {
Assert.assertEquals(Arrays.asList(null, "310", null, null, null, null, "910"), rowList.get(0).dimensionValues());
Assert.assertEquals(Arrays.asList("210", "311", null, null, "710", "810", "911"), rowList.get(1).dimensionValues());
Assert.assertEquals(Arrays.asList(null, null, "520", "620", "720", "820", "920"), rowList.get(2).dimensionValues());
Assert.assertEquals(Arrays.asList(null, null, null, "621", null, "821", "921"), rowList.get(3).dimensionValues());
checkBitmapIndex(Arrays.asList(0, 2, 3), adapter.getBitmapIndex("d2", null));
checkBitmapIndex(Arrays.asList(0, 1, 3), adapter.getBitmapIndex("d5", null));
checkBitmapIndex(Arrays.asList(0, 3), adapter.getBitmapIndex("d7", null));
} else {
Assert.assertEquals(Arrays.asList("", "", "310", null, null, "", null, "910"), rowList.get(0).dimensionValues());
Assert.assertEquals(Arrays.asList(null, "210", "311", null, null, "710", "810", "911"), rowList.get(1).dimensionValues());
Assert.assertEquals(Arrays.asList(null, null, null, "520", "620", "720", "820", "920"), rowList.get(2).dimensionValues());
Assert.assertEquals(Arrays.asList(null, null, null, "", "621", "", "821", "921"), rowList.get(3).dimensionValues());
checkBitmapIndex(Arrays.asList(2, 3), adapter.getBitmapIndex("d2", null));
checkBitmapIndex(Arrays.asList(0, 1), adapter.getBitmapIndex("d5", null));
checkBitmapIndex(Collections.emptyList(), adapter.getBitmapIndex("d7", null));
}
checkBitmapIndex(Collections.singletonList(1), adapter.getBitmapIndex("d2", "210"));
checkBitmapIndex(Arrays.asList(2, 3), adapter.getBitmapIndex("d3", null));
checkBitmapIndex(Collections.singletonList(0), adapter.getBitmapIndex("d3", "310"));
checkBitmapIndex(Collections.singletonList(1), adapter.getBitmapIndex("d3", "311"));
checkBitmapIndex(Collections.singletonList(2), adapter.getBitmapIndex("d5", "520"));
checkBitmapIndex(Arrays.asList(0, 1), adapter.getBitmapIndex("d6", null));
checkBitmapIndex(Collections.singletonList(2), adapter.getBitmapIndex("d6", "620"));
checkBitmapIndex(Collections.singletonList(3), adapter.getBitmapIndex("d6", "621"));
checkBitmapIndex(Collections.singletonList(1), adapter.getBitmapIndex("d7", "710"));
checkBitmapIndex(Collections.singletonList(2), adapter.getBitmapIndex("d7", "720"));
checkBitmapIndex(Collections.singletonList(0), adapter.getBitmapIndex("d8", null));
checkBitmapIndex(Collections.singletonList(1), adapter.getBitmapIndex("d8", "810"));
checkBitmapIndex(Collections.singletonList(2), adapter.getBitmapIndex("d8", "820"));
checkBitmapIndex(Collections.singletonList(3), adapter.getBitmapIndex("d8", "821"));
checkBitmapIndex(Collections.emptyList(), adapter.getBitmapIndex("d9", null));
checkBitmapIndex(Collections.singletonList(0), adapter.getBitmapIndex("d9", "910"));
checkBitmapIndex(Collections.singletonList(1), adapter.getBitmapIndex("d9", "911"));
checkBitmapIndex(Collections.singletonList(2), adapter.getBitmapIndex("d9", "920"));
checkBitmapIndex(Collections.singletonList(3), adapter.getBitmapIndex("d9", "921"));
}
}
use of org.apache.druid.segment.incremental.IncrementalIndexSchema in project druid by druid-io.
the class IndexMergerTestBase method testMultivalDim_persistAndMerge_dimensionValueOrderingRules.
@Test
public void testMultivalDim_persistAndMerge_dimensionValueOrderingRules() throws Exception {
List<String> dims = Arrays.asList("dimA", "dimMultiVal");
IncrementalIndexSchema indexSchema = new IncrementalIndexSchema.Builder().withDimensionsSpec(new DimensionsSpec(ImmutableList.of(new StringDimensionSchema("dimA", MultiValueHandling.SORTED_ARRAY, true), new StringDimensionSchema("dimMultiVal", MultiValueHandling.SORTED_ARRAY, true)))).withMetrics(new LongSumAggregatorFactory("sumCount", "sumCount")).withRollup(true).build();
Map<String, Object> nullEvent = new HashMap<>();
nullEvent.put("dimA", "leek");
nullEvent.put("sumCount", 1L);
Map<String, Object> nullEvent2 = new HashMap<>();
nullEvent2.put("dimA", "leek");
nullEvent2.put("dimMultiVal", null);
nullEvent2.put("sumCount", 1L);
Map<String, Object> emptyListEvent = new HashMap<>();
emptyListEvent.put("dimA", "leek");
emptyListEvent.put("dimMultiVal", ImmutableList.of());
emptyListEvent.put("sumCount", 1L);
List<String> listWithNull = new ArrayList<>();
listWithNull.add(null);
Map<String, Object> listWithNullEvent = new HashMap<>();
listWithNullEvent.put("dimA", "leek");
listWithNullEvent.put("dimMultiVal", listWithNull);
listWithNullEvent.put("sumCount", 1L);
Map<String, Object> emptyStringEvent = new HashMap<>();
emptyStringEvent.put("dimA", "leek");
emptyStringEvent.put("dimMultiVal", "");
emptyStringEvent.put("sumCount", 1L);
Map<String, Object> listWithEmptyStringEvent = new HashMap<>();
listWithEmptyStringEvent.put("dimA", "leek");
listWithEmptyStringEvent.put("dimMultiVal", ImmutableList.of(""));
listWithEmptyStringEvent.put("sumCount", 1L);
Map<String, Object> singleValEvent = new HashMap<>();
singleValEvent.put("dimA", "leek");
singleValEvent.put("dimMultiVal", "1");
singleValEvent.put("sumCount", 1L);
Map<String, Object> singleValEvent2 = new HashMap<>();
singleValEvent2.put("dimA", "leek");
singleValEvent2.put("dimMultiVal", "2");
singleValEvent2.put("sumCount", 1L);
Map<String, Object> singleValEvent3 = new HashMap<>();
singleValEvent3.put("dimA", "potato");
singleValEvent3.put("dimMultiVal", "2");
singleValEvent3.put("sumCount", 1L);
Map<String, Object> listWithSingleValEvent = new HashMap<>();
listWithSingleValEvent.put("dimA", "leek");
listWithSingleValEvent.put("dimMultiVal", ImmutableList.of("1"));
listWithSingleValEvent.put("sumCount", 1L);
Map<String, Object> listWithSingleValEvent2 = new HashMap<>();
listWithSingleValEvent2.put("dimA", "leek");
listWithSingleValEvent2.put("dimMultiVal", ImmutableList.of("2"));
listWithSingleValEvent2.put("sumCount", 1L);
Map<String, Object> listWithSingleValEvent3 = new HashMap<>();
listWithSingleValEvent3.put("dimA", "potato");
listWithSingleValEvent3.put("dimMultiVal", ImmutableList.of("2"));
listWithSingleValEvent3.put("sumCount", 1L);
Map<String, Object> multivalEvent = new HashMap<>();
multivalEvent.put("dimA", "leek");
multivalEvent.put("dimMultiVal", ImmutableList.of("1", "3"));
multivalEvent.put("sumCount", 1L);
Map<String, Object> multivalEvent2 = new HashMap<>();
multivalEvent2.put("dimA", "leek");
multivalEvent2.put("dimMultiVal", ImmutableList.of("1", "4"));
multivalEvent2.put("sumCount", 1L);
Map<String, Object> multivalEvent3 = new HashMap<>();
multivalEvent3.put("dimA", "leek");
multivalEvent3.put("dimMultiVal", ImmutableList.of("1", "3", "5"));
multivalEvent3.put("sumCount", 1L);
Map<String, Object> multivalEvent4 = new HashMap<>();
multivalEvent4.put("dimA", "leek");
multivalEvent4.put("dimMultiVal", ImmutableList.of("1", "2", "3"));
multivalEvent4.put("sumCount", 1L);
List<String> multivalEvent5List = Arrays.asList("1", "2", "3", null);
Map<String, Object> multivalEvent5 = new HashMap<>();
multivalEvent5.put("dimA", "leek");
multivalEvent5.put("dimMultiVal", multivalEvent5List);
multivalEvent5.put("sumCount", 1L);
List<String> multivalEvent6List = Arrays.asList(null, "3");
Map<String, Object> multivalEvent6 = new HashMap<>();
multivalEvent6.put("dimA", "leek");
multivalEvent6.put("dimMultiVal", multivalEvent6List);
multivalEvent6.put("sumCount", 1L);
Map<String, Object> multivalEvent7 = new HashMap<>();
multivalEvent7.put("dimA", "leek");
multivalEvent7.put("dimMultiVal", ImmutableList.of("1", "2", "3", ""));
multivalEvent7.put("sumCount", 1L);
Map<String, Object> multivalEvent8 = new HashMap<>();
multivalEvent8.put("dimA", "leek");
multivalEvent8.put("dimMultiVal", ImmutableList.of("", "3"));
multivalEvent8.put("sumCount", 1L);
Map<String, Object> multivalEvent9 = new HashMap<>();
multivalEvent9.put("dimA", "potato");
multivalEvent9.put("dimMultiVal", ImmutableList.of("1", "3"));
multivalEvent9.put("sumCount", 1L);
List<Map<String, Object>> events = ImmutableList.of(nullEvent, nullEvent2, emptyListEvent, listWithNullEvent, emptyStringEvent, listWithEmptyStringEvent, singleValEvent, singleValEvent2, singleValEvent3, listWithSingleValEvent, listWithSingleValEvent2, listWithSingleValEvent3, multivalEvent, multivalEvent2, multivalEvent3, multivalEvent4, multivalEvent5, multivalEvent6, multivalEvent7, multivalEvent8, multivalEvent9);
IncrementalIndex toPersistA = new OnheapIncrementalIndex.Builder().setIndexSchema(indexSchema).setMaxRowCount(1000).build();
for (Map<String, Object> event : events) {
toPersistA.add(new MapBasedInputRow(1, dims, event));
}
final File tmpDirA = temporaryFolder.newFolder();
QueryableIndex indexA = closer.closeLater(indexIO.loadIndex(indexMerger.persist(toPersistA, tmpDirA, indexSpec, null)));
List<QueryableIndex> singleEventIndexes = new ArrayList<>();
for (Map<String, Object> event : events) {
IncrementalIndex toPersist = new OnheapIncrementalIndex.Builder().setIndexSchema(indexSchema).setMaxRowCount(1000).build();
toPersist.add(new MapBasedInputRow(1, dims, event));
final File tmpDir = temporaryFolder.newFolder();
QueryableIndex queryableIndex = closer.closeLater(indexIO.loadIndex(indexMerger.persist(toPersist, tmpDir, indexSpec, null)));
singleEventIndexes.add(queryableIndex);
}
singleEventIndexes.add(indexA);
final File tmpDirMerged = temporaryFolder.newFolder();
final QueryableIndex merged = closer.closeLater(indexIO.loadIndex(indexMerger.mergeQueryableIndex(singleEventIndexes, true, new AggregatorFactory[] { new LongSumAggregatorFactory("sumCount", "sumCount") }, tmpDirMerged, indexSpec, null, -1)));
final QueryableIndexIndexableAdapter adapter = new QueryableIndexIndexableAdapter(merged);
final List<DebugRow> rowList = RowIteratorHelper.toList(adapter.getRows());
Assert.assertEquals(ImmutableList.of("dimA", "dimMultiVal"), ImmutableList.copyOf(adapter.getDimensionNames()));
if (NullHandling.replaceWithDefault()) {
Assert.assertEquals(11, rowList.size());
Assert.assertEquals(Arrays.asList("leek", null), rowList.get(0).dimensionValues());
Assert.assertEquals(12L, rowList.get(0).metricValues().get(0));
Assert.assertEquals(Arrays.asList("leek", Arrays.asList(null, "1", "2", "3")), rowList.get(1).dimensionValues());
Assert.assertEquals(4L, rowList.get(1).metricValues().get(0));
Assert.assertEquals(Arrays.asList("leek", Arrays.asList(null, "3")), rowList.get(2).dimensionValues());
Assert.assertEquals(4L, rowList.get(2).metricValues().get(0));
Assert.assertEquals(Arrays.asList("leek", "1"), rowList.get(3).dimensionValues());
Assert.assertEquals(4L, rowList.get(3).metricValues().get(0));
Assert.assertEquals(Arrays.asList("leek", Arrays.asList("1", "2", "3")), rowList.get(4).dimensionValues());
Assert.assertEquals(2L, rowList.get(4).metricValues().get(0));
Assert.assertEquals(Arrays.asList("leek", Arrays.asList("1", "3")), rowList.get(5).dimensionValues());
Assert.assertEquals(2L, rowList.get(5).metricValues().get(0));
Assert.assertEquals(Arrays.asList("leek", Arrays.asList("1", "3", "5")), rowList.get(6).dimensionValues());
Assert.assertEquals(2L, rowList.get(6).metricValues().get(0));
Assert.assertEquals(Arrays.asList("leek", Arrays.asList("1", "4")), rowList.get(7).dimensionValues());
Assert.assertEquals(2L, rowList.get(7).metricValues().get(0));
Assert.assertEquals(Arrays.asList("leek", "2"), rowList.get(8).dimensionValues());
Assert.assertEquals(4L, rowList.get(8).metricValues().get(0));
Assert.assertEquals(Arrays.asList("potato", Arrays.asList("1", "3")), rowList.get(9).dimensionValues());
Assert.assertEquals(2L, rowList.get(9).metricValues().get(0));
Assert.assertEquals(Arrays.asList("potato", "2"), rowList.get(10).dimensionValues());
Assert.assertEquals(4L, rowList.get(10).metricValues().get(0));
checkBitmapIndex(Arrays.asList(0, 1, 2, 3, 4, 5, 6, 7, 8), adapter.getBitmapIndex("dimA", "leek"));
checkBitmapIndex(Arrays.asList(9, 10), adapter.getBitmapIndex("dimA", "potato"));
checkBitmapIndex(Arrays.asList(0, 1, 2), adapter.getBitmapIndex("dimMultiVal", null));
checkBitmapIndex(ImmutableList.of(), adapter.getBitmapIndex("dimMultiVal", ""));
checkBitmapIndex(Arrays.asList(1, 3, 4, 5, 6, 7, 9), adapter.getBitmapIndex("dimMultiVal", "1"));
checkBitmapIndex(Arrays.asList(1, 4, 8, 10), adapter.getBitmapIndex("dimMultiVal", "2"));
checkBitmapIndex(Arrays.asList(1, 2, 4, 5, 6, 9), adapter.getBitmapIndex("dimMultiVal", "3"));
checkBitmapIndex(Collections.singletonList(7), adapter.getBitmapIndex("dimMultiVal", "4"));
checkBitmapIndex(Collections.singletonList(6), adapter.getBitmapIndex("dimMultiVal", "5"));
} else {
Assert.assertEquals(14, rowList.size());
Assert.assertEquals(Arrays.asList("leek", null), rowList.get(0).dimensionValues());
Assert.assertEquals(8L, rowList.get(0).metricValues().get(0));
Assert.assertEquals(Arrays.asList("leek", Arrays.asList(null, "1", "2", "3")), rowList.get(1).dimensionValues());
Assert.assertEquals(2L, rowList.get(1).metricValues().get(0));
Assert.assertEquals(Arrays.asList("leek", Arrays.asList(null, "3")), rowList.get(2).dimensionValues());
Assert.assertEquals(2L, rowList.get(2).metricValues().get(0));
Assert.assertEquals(Arrays.asList("leek", ""), rowList.get(3).dimensionValues());
Assert.assertEquals(4L, rowList.get(3).metricValues().get(0));
Assert.assertEquals(Arrays.asList("leek", Arrays.asList("", "1", "2", "3")), rowList.get(4).dimensionValues());
Assert.assertEquals(2L, rowList.get(4).metricValues().get(0));
Assert.assertEquals(Arrays.asList("leek", Arrays.asList("", "3")), rowList.get(5).dimensionValues());
Assert.assertEquals(2L, rowList.get(5).metricValues().get(0));
Assert.assertEquals(Arrays.asList("leek", "1"), rowList.get(6).dimensionValues());
Assert.assertEquals(4L, rowList.get(6).metricValues().get(0));
Assert.assertEquals(Arrays.asList("leek", Arrays.asList("1", "2", "3")), rowList.get(7).dimensionValues());
Assert.assertEquals(2L, rowList.get(7).metricValues().get(0));
Assert.assertEquals(Arrays.asList("leek", Arrays.asList("1", "3")), rowList.get(8).dimensionValues());
Assert.assertEquals(2L, rowList.get(8).metricValues().get(0));
Assert.assertEquals(Arrays.asList("leek", Arrays.asList("1", "3", "5")), rowList.get(9).dimensionValues());
Assert.assertEquals(2L, rowList.get(9).metricValues().get(0));
Assert.assertEquals(Arrays.asList("leek", Arrays.asList("1", "4")), rowList.get(10).dimensionValues());
Assert.assertEquals(2L, rowList.get(10).metricValues().get(0));
Assert.assertEquals(Arrays.asList("leek", "2"), rowList.get(11).dimensionValues());
Assert.assertEquals(4L, rowList.get(11).metricValues().get(0));
Assert.assertEquals(Arrays.asList("potato", Arrays.asList("1", "3")), rowList.get(12).dimensionValues());
Assert.assertEquals(2L, rowList.get(12).metricValues().get(0));
Assert.assertEquals(Arrays.asList("potato", "2"), rowList.get(13).dimensionValues());
Assert.assertEquals(4L, rowList.get(13).metricValues().get(0));
checkBitmapIndex(Arrays.asList(0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11), adapter.getBitmapIndex("dimA", "leek"));
checkBitmapIndex(Arrays.asList(12, 13), adapter.getBitmapIndex("dimA", "potato"));
checkBitmapIndex(Arrays.asList(0, 1, 2), adapter.getBitmapIndex("dimMultiVal", null));
checkBitmapIndex(ImmutableList.of(3, 4, 5), adapter.getBitmapIndex("dimMultiVal", ""));
checkBitmapIndex(Arrays.asList(1, 4, 6, 7, 8, 9, 10, 12), adapter.getBitmapIndex("dimMultiVal", "1"));
checkBitmapIndex(Arrays.asList(1, 4, 7, 11, 13), adapter.getBitmapIndex("dimMultiVal", "2"));
checkBitmapIndex(Arrays.asList(1, 2, 4, 5, 7, 8, 9, 12), adapter.getBitmapIndex("dimMultiVal", "3"));
checkBitmapIndex(Collections.singletonList(10), adapter.getBitmapIndex("dimMultiVal", "4"));
checkBitmapIndex(Collections.singletonList(9), adapter.getBitmapIndex("dimMultiVal", "5"));
}
}
Aggregations