Search in sources :

Example 1 with AggregatorAdapters

use of org.apache.druid.query.aggregation.AggregatorAdapters in project druid by druid-io.

the class HashVectorGrouperTest method testGrowFourTimes.

@Test
public void testGrowFourTimes() {
    final int maxVectorSize = 512;
    final int keySize = 4;
    final int aggSize = 8;
    final WritableMemory keySpace = WritableMemory.allocate(keySize * maxVectorSize);
    final AggregatorAdapters aggregatorAdapters = Mockito.mock(AggregatorAdapters.class);
    Mockito.when(aggregatorAdapters.spaceNeeded()).thenReturn(aggSize);
    int startingNumBuckets = 4;
    int maxBuckets = 128;
    final int bufferSize = (keySize + aggSize) * maxBuckets;
    final ByteBuffer buffer = ByteBuffer.wrap(new byte[bufferSize]);
    final HashVectorGrouper grouper = new HashVectorGrouper(Suppliers.ofInstance(buffer), keySize, aggregatorAdapters, maxBuckets, 0.f, startingNumBuckets);
    grouper.initVectorized(maxVectorSize);
    int tableStart = grouper.getTableStart();
    // two keys should cause buffer to grow
    fillKeyspace(keySpace, maxVectorSize, 2);
    AggregateResult result = grouper.aggregateVector(keySpace, 0, maxVectorSize);
    Assert.assertTrue(result.isOk());
    Assert.assertEquals(tableStart, grouper.getTableStart());
    // 3rd key should cause buffer to grow
    // buffer should grow to next size, but is not full
    fillKeyspace(keySpace, maxVectorSize, 3);
    result = grouper.aggregateVector(keySpace, 0, maxVectorSize);
    Assert.assertTrue(result.isOk());
    Assert.assertTrue(grouper.getTableStart() > tableStart);
    tableStart = grouper.getTableStart();
    // grow it again
    fillKeyspace(keySpace, maxVectorSize, 6);
    result = grouper.aggregateVector(keySpace, 0, maxVectorSize);
    Assert.assertTrue(result.isOk());
    Assert.assertTrue(grouper.getTableStart() > tableStart);
    tableStart = grouper.getTableStart();
    // more
    fillKeyspace(keySpace, maxVectorSize, 14);
    result = grouper.aggregateVector(keySpace, 0, maxVectorSize);
    Assert.assertTrue(result.isOk());
    Assert.assertTrue(grouper.getTableStart() > tableStart);
    // this time should be all the way
    fillKeyspace(keySpace, maxVectorSize, 25);
    result = grouper.aggregateVector(keySpace, 0, maxVectorSize);
    Assert.assertTrue(result.isOk());
    Assert.assertEquals(0, grouper.getTableStart());
}
Also used : WritableMemory(org.apache.datasketches.memory.WritableMemory) AggregatorAdapters(org.apache.druid.query.aggregation.AggregatorAdapters) ByteBuffer(java.nio.ByteBuffer) Test(org.junit.Test)

Example 2 with AggregatorAdapters

use of org.apache.druid.query.aggregation.AggregatorAdapters in project druid by druid-io.

the class HashVectorGrouperTest method testGrowOnce.

@Test
public void testGrowOnce() {
    final int maxVectorSize = 512;
    final int keySize = 4;
    final int aggSize = 8;
    final WritableMemory keySpace = WritableMemory.allocate(keySize * maxVectorSize);
    final AggregatorAdapters aggregatorAdapters = Mockito.mock(AggregatorAdapters.class);
    Mockito.when(aggregatorAdapters.spaceNeeded()).thenReturn(aggSize);
    int startingNumBuckets = 4;
    int maxBuckets = 16;
    final int bufferSize = (keySize + aggSize) * maxBuckets;
    final ByteBuffer buffer = ByteBuffer.wrap(new byte[bufferSize]);
    final HashVectorGrouper grouper = new HashVectorGrouper(Suppliers.ofInstance(buffer), keySize, aggregatorAdapters, maxBuckets, 0.f, startingNumBuckets);
    grouper.initVectorized(maxVectorSize);
    int tableStart = grouper.getTableStart();
    // two keys should not cause buffer to grow
    fillKeyspace(keySpace, maxVectorSize, 2);
    AggregateResult result = grouper.aggregateVector(keySpace, 0, maxVectorSize);
    Assert.assertTrue(result.isOk());
    Assert.assertEquals(tableStart, grouper.getTableStart());
    // 3rd key should cause buffer to grow
    // buffer should grow to maximum size
    fillKeyspace(keySpace, maxVectorSize, 3);
    result = grouper.aggregateVector(keySpace, 0, maxVectorSize);
    Assert.assertTrue(result.isOk());
    Assert.assertEquals(0, grouper.getTableStart());
}
Also used : WritableMemory(org.apache.datasketches.memory.WritableMemory) AggregatorAdapters(org.apache.druid.query.aggregation.AggregatorAdapters) ByteBuffer(java.nio.ByteBuffer) Test(org.junit.Test)

Example 3 with AggregatorAdapters

use of org.apache.druid.query.aggregation.AggregatorAdapters in project druid by druid-io.

the class HashVectorGrouperTest method testTableStartIsNotMemoryStartIfIsMaxSized.

@Test
public void testTableStartIsNotMemoryStartIfIsMaxSized() {
    final int maxVectorSize = 512;
    final int keySize = 10000;
    final int bufferSize = 100 * 1024;
    final ByteBuffer buffer = ByteBuffer.wrap(new byte[bufferSize]);
    final AggregatorAdapters aggregatorAdapters = Mockito.mock(AggregatorAdapters.class);
    final HashVectorGrouper grouper = new HashVectorGrouper(Suppliers.ofInstance(buffer), keySize, aggregatorAdapters, 4, 0.f, 4);
    grouper.initVectorized(maxVectorSize);
    Assert.assertEquals(0, grouper.getTableStart());
}
Also used : AggregatorAdapters(org.apache.druid.query.aggregation.AggregatorAdapters) ByteBuffer(java.nio.ByteBuffer) Test(org.junit.Test)

Example 4 with AggregatorAdapters

use of org.apache.druid.query.aggregation.AggregatorAdapters in project druid by druid-io.

the class HashVectorGrouperTest method testGrowThreeTimes.

@Test
public void testGrowThreeTimes() {
    final int maxVectorSize = 512;
    final int keySize = 4;
    final int aggSize = 8;
    final WritableMemory keySpace = WritableMemory.allocate(keySize * maxVectorSize);
    final AggregatorAdapters aggregatorAdapters = Mockito.mock(AggregatorAdapters.class);
    Mockito.when(aggregatorAdapters.spaceNeeded()).thenReturn(aggSize);
    int startingNumBuckets = 4;
    int maxBuckets = 64;
    final int bufferSize = (keySize + aggSize) * maxBuckets;
    final ByteBuffer buffer = ByteBuffer.wrap(new byte[bufferSize]);
    final HashVectorGrouper grouper = new HashVectorGrouper(Suppliers.ofInstance(buffer), keySize, aggregatorAdapters, maxBuckets, 0.f, startingNumBuckets);
    grouper.initVectorized(maxVectorSize);
    int tableStart = grouper.getTableStart();
    // two keys should cause buffer to grow
    fillKeyspace(keySpace, maxVectorSize, 2);
    AggregateResult result = grouper.aggregateVector(keySpace, 0, maxVectorSize);
    Assert.assertTrue(result.isOk());
    Assert.assertEquals(tableStart, grouper.getTableStart());
    // 3rd key should cause buffer to grow
    // buffer should grow to next size, but is not full
    fillKeyspace(keySpace, maxVectorSize, 3);
    result = grouper.aggregateVector(keySpace, 0, maxVectorSize);
    Assert.assertTrue(result.isOk());
    Assert.assertTrue(grouper.getTableStart() > tableStart);
    tableStart = grouper.getTableStart();
    // grow it again
    fillKeyspace(keySpace, maxVectorSize, 6);
    result = grouper.aggregateVector(keySpace, 0, maxVectorSize);
    Assert.assertTrue(result.isOk());
    Assert.assertTrue(grouper.getTableStart() > tableStart);
    // this time should be all the way
    fillKeyspace(keySpace, maxVectorSize, 14);
    result = grouper.aggregateVector(keySpace, 0, maxVectorSize);
    Assert.assertTrue(result.isOk());
    Assert.assertEquals(0, grouper.getTableStart());
}
Also used : WritableMemory(org.apache.datasketches.memory.WritableMemory) AggregatorAdapters(org.apache.druid.query.aggregation.AggregatorAdapters) ByteBuffer(java.nio.ByteBuffer) Test(org.junit.Test)

Example 5 with AggregatorAdapters

use of org.apache.druid.query.aggregation.AggregatorAdapters in project druid by druid-io.

the class HashVectorGrouperTest method testTableStartIsNotMemoryStartIfNotMaxSized.

@Test
public void testTableStartIsNotMemoryStartIfNotMaxSized() {
    final int maxVectorSize = 512;
    final int keySize = 4;
    final int bufferSize = 100 * 1024;
    final WritableMemory keySpace = WritableMemory.allocate(keySize * maxVectorSize);
    final ByteBuffer buffer = ByteBuffer.wrap(new byte[bufferSize]);
    final AggregatorAdapters aggregatorAdapters = Mockito.mock(AggregatorAdapters.class);
    final HashVectorGrouper grouper = new HashVectorGrouper(Suppliers.ofInstance(buffer), keySize, aggregatorAdapters, 8, 0.f, 4);
    grouper.initVectorized(maxVectorSize);
    Assert.assertNotEquals(0, grouper.getTableStart());
}
Also used : WritableMemory(org.apache.datasketches.memory.WritableMemory) AggregatorAdapters(org.apache.druid.query.aggregation.AggregatorAdapters) ByteBuffer(java.nio.ByteBuffer) Test(org.junit.Test)

Aggregations

ByteBuffer (java.nio.ByteBuffer)8 AggregatorAdapters (org.apache.druid.query.aggregation.AggregatorAdapters)8 Test (org.junit.Test)7 WritableMemory (org.apache.datasketches.memory.WritableMemory)5 ISE (org.apache.druid.java.util.common.ISE)1 Closer (org.apache.druid.java.util.common.io.Closer)1 AggregatorFactory (org.apache.druid.query.aggregation.AggregatorFactory)1 VectorCursorGranularizer (org.apache.druid.query.vector.VectorCursorGranularizer)1 VectorColumnSelectorFactory (org.apache.druid.segment.vector.VectorColumnSelectorFactory)1 VectorCursor (org.apache.druid.segment.vector.VectorCursor)1