Search in sources :

Example 1 with RowIterator

use of org.apache.druid.segment.RowIterator 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));
    }
}
Also used : Collection(java.util.Collection) RunWith(org.junit.runner.RunWith) StringUtils(org.apache.druid.java.util.common.StringUtils) JsonProcessingException(com.fasterxml.jackson.core.JsonProcessingException) IndexSpec(org.apache.druid.segment.IndexSpec) InitializedNullHandlingTest(org.apache.druid.testing.InitializedNullHandlingTest) Test(org.junit.Test) CloseableIndexed(org.apache.druid.segment.data.CloseableIndexed) IndexableAdapter(org.apache.druid.segment.IndexableAdapter) Function(java.util.function.Function) CompressionFactory(org.apache.druid.segment.data.CompressionFactory) ArrayList(java.util.ArrayList) List(java.util.List) Rule(org.junit.Rule) CompressionStrategy(org.apache.druid.segment.data.CompressionStrategy) RowIterator(org.apache.druid.segment.RowIterator) CloserRule(org.apache.druid.segment.CloserRule) IncrementalIndexTest(org.apache.druid.segment.data.IncrementalIndexTest) Assert(org.junit.Assert) ConciseBitmapSerdeFactory(org.apache.druid.segment.data.ConciseBitmapSerdeFactory) CountAggregatorFactory(org.apache.druid.query.aggregation.CountAggregatorFactory) BitmapValues(org.apache.druid.segment.data.BitmapValues) Parameterized(org.junit.runners.Parameterized) ArrayList(java.util.ArrayList) RowIterator(org.apache.druid.segment.RowIterator) IndexableAdapter(org.apache.druid.segment.IndexableAdapter) InitializedNullHandlingTest(org.apache.druid.testing.InitializedNullHandlingTest) Test(org.junit.Test) IncrementalIndexTest(org.apache.druid.segment.data.IncrementalIndexTest)

Example 2 with RowIterator

use of org.apache.druid.segment.RowIterator 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));
}
Also used : RowIterator(org.apache.druid.segment.RowIterator) ArrayList(java.util.ArrayList) IndexableAdapter(org.apache.druid.segment.IndexableAdapter) InitializedNullHandlingTest(org.apache.druid.testing.InitializedNullHandlingTest) Test(org.junit.Test) IncrementalIndexTest(org.apache.druid.segment.data.IncrementalIndexTest)

Aggregations

ArrayList (java.util.ArrayList)2 IndexableAdapter (org.apache.druid.segment.IndexableAdapter)2 RowIterator (org.apache.druid.segment.RowIterator)2 IncrementalIndexTest (org.apache.druid.segment.data.IncrementalIndexTest)2 InitializedNullHandlingTest (org.apache.druid.testing.InitializedNullHandlingTest)2 Test (org.junit.Test)2 JsonProcessingException (com.fasterxml.jackson.core.JsonProcessingException)1 Collection (java.util.Collection)1 List (java.util.List)1 Function (java.util.function.Function)1 StringUtils (org.apache.druid.java.util.common.StringUtils)1 CountAggregatorFactory (org.apache.druid.query.aggregation.CountAggregatorFactory)1 CloserRule (org.apache.druid.segment.CloserRule)1 IndexSpec (org.apache.druid.segment.IndexSpec)1 BitmapValues (org.apache.druid.segment.data.BitmapValues)1 CloseableIndexed (org.apache.druid.segment.data.CloseableIndexed)1 CompressionFactory (org.apache.druid.segment.data.CompressionFactory)1 CompressionStrategy (org.apache.druid.segment.data.CompressionStrategy)1 ConciseBitmapSerdeFactory (org.apache.druid.segment.data.ConciseBitmapSerdeFactory)1 Assert (org.junit.Assert)1