Search in sources :

Example 6 with Entry

use of org.apache.druid.query.groupby.epinephelinae.Grouper.Entry in project druid by druid-io.

the class ConcurrentGrouperTest method testAggregate.

@Test()
public void testAggregate() throws InterruptedException, ExecutionException, IOException {
    final ConcurrentGrouper<Long> grouper = new ConcurrentGrouper<>(bufferSupplier, TEST_RESOURCE_HOLDER, KEY_SERDE_FACTORY, KEY_SERDE_FACTORY, NULL_FACTORY, new AggregatorFactory[] { new CountAggregatorFactory("cnt") }, 1024, 0.7f, 1, new LimitedTemporaryStorage(temporaryFolder.newFolder(), 1024 * 1024), new DefaultObjectMapper(), 8, null, false, MoreExecutors.listeningDecorator(SERVICE), 0, false, 0, 4, 8);
    grouper.init();
    final int numRows = 1000;
    Future<?>[] futures = new Future[8];
    for (int i = 0; i < 8; i++) {
        futures[i] = SERVICE.submit(new Runnable() {

            @Override
            public void run() {
                for (long i = 0; i < numRows; i++) {
                    grouper.aggregate(i);
                }
            }
        });
    }
    for (Future eachFuture : futures) {
        eachFuture.get();
    }
    final CloseableIterator<Entry<Long>> iterator = grouper.iterator(true);
    final List<Entry<Long>> actual = Lists.newArrayList(iterator);
    iterator.close();
    Assert.assertTrue(TEST_RESOURCE_HOLDER.taken);
    final List<Entry<Long>> expected = new ArrayList<>();
    for (long i = 0; i < numRows; i++) {
        expected.add(new Entry<>(i, new Object[] { 8L }));
    }
    Assert.assertEquals(expected, actual);
    grouper.close();
}
Also used : ArrayList(java.util.ArrayList) Entry(org.apache.druid.query.groupby.epinephelinae.Grouper.Entry) CountAggregatorFactory(org.apache.druid.query.aggregation.CountAggregatorFactory) Future(java.util.concurrent.Future) DefaultObjectMapper(org.apache.druid.jackson.DefaultObjectMapper) Test(org.junit.Test)

Aggregations

Entry (org.apache.druid.query.groupby.epinephelinae.Grouper.Entry)6 ArrayList (java.util.ArrayList)3 Future (java.util.concurrent.Future)3 MapBasedRow (org.apache.druid.data.input.MapBasedRow)3 Test (org.junit.Test)3 ListenableFuture (com.google.common.util.concurrent.ListenableFuture)2 ByteBuffer (java.nio.ByteBuffer)2 Comparator (java.util.Comparator)2 List (java.util.List)2 CountAggregatorFactory (org.apache.druid.query.aggregation.CountAggregatorFactory)2 Suppliers (com.google.common.base.Suppliers)1 ImmutableList (com.google.common.collect.ImmutableList)1 ImmutableMap (com.google.common.collect.ImmutableMap)1 Lists (com.google.common.collect.Lists)1 Ordering (com.google.common.collect.Ordering)1 Ints (com.google.common.primitives.Ints)1 IOException (java.io.IOException)1 ExecutorService (java.util.concurrent.ExecutorService)1 Releaser (org.apache.druid.collections.Releaser)1 NullHandling (org.apache.druid.common.config.NullHandling)1