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