Search in sources :

Example 31 with Pair

use of io.druid.java.util.common.Pair in project druid by druid-io.

the class AggregatorUtilTest method testNullPostAggregatorNames.

@Test
public void testNullPostAggregatorNames() {
    AggregatorFactory agg1 = new DoubleSumAggregatorFactory("agg1", "value");
    AggregatorFactory agg2 = new DoubleSumAggregatorFactory("agg2", "count");
    PostAggregator postAgg1 = new ArithmeticPostAggregator(null, "*", Lists.<PostAggregator>newArrayList(new FieldAccessPostAggregator(null, "agg1"), new FieldAccessPostAggregator(null, "agg2")));
    PostAggregator postAgg2 = new ArithmeticPostAggregator("postAgg", "/", Lists.<PostAggregator>newArrayList(new FieldAccessPostAggregator(null, "agg1"), new FieldAccessPostAggregator(null, "agg2")));
    Assert.assertEquals(new Pair(Lists.newArrayList(agg1, agg2), Lists.newArrayList(postAgg2)), AggregatorUtil.condensedAggregators(Lists.newArrayList(agg1, agg2), Lists.newArrayList(postAgg1, postAgg2), "postAgg"));
}
Also used : ArithmeticPostAggregator(io.druid.query.aggregation.post.ArithmeticPostAggregator) FieldAccessPostAggregator(io.druid.query.aggregation.post.FieldAccessPostAggregator) FieldAccessPostAggregator(io.druid.query.aggregation.post.FieldAccessPostAggregator) ArithmeticPostAggregator(io.druid.query.aggregation.post.ArithmeticPostAggregator) ConstantPostAggregator(io.druid.query.aggregation.post.ConstantPostAggregator) Pair(io.druid.java.util.common.Pair) Test(org.junit.Test)

Example 32 with Pair

use of io.druid.java.util.common.Pair in project druid by druid-io.

the class DoubleLastAggregationTest method testDoubleLastBufferAggregator.

@Test
public void testDoubleLastBufferAggregator() {
    DoubleLastBufferAggregator agg = (DoubleLastBufferAggregator) doubleLastAggFactory.factorizeBuffered(colSelectorFactory);
    ByteBuffer buffer = ByteBuffer.wrap(new byte[doubleLastAggFactory.getMaxIntermediateSize()]);
    agg.init(buffer, 0);
    aggregate(agg, buffer, 0);
    aggregate(agg, buffer, 0);
    aggregate(agg, buffer, 0);
    aggregate(agg, buffer, 0);
    Pair<Long, Double> result = (Pair<Long, Double>) agg.get(buffer, 0);
    Assert.assertEquals(times[0], result.lhs.longValue());
    Assert.assertEquals(floatValues[0], result.rhs, 0.0001);
    Assert.assertEquals((long) floatValues[0], agg.getLong(buffer, 0));
    Assert.assertEquals(floatValues[0], agg.getFloat(buffer, 0), 0.0001);
}
Also used : ByteBuffer(java.nio.ByteBuffer) SerializablePair(io.druid.collections.SerializablePair) Pair(io.druid.java.util.common.Pair) Test(org.junit.Test)

Example 33 with Pair

use of io.druid.java.util.common.Pair in project druid by druid-io.

the class LongFirstAggregationTest method testLongFirstBufferAggregator.

@Test
public void testLongFirstBufferAggregator() {
    LongFirstBufferAggregator agg = (LongFirstBufferAggregator) longFirstAggFactory.factorizeBuffered(colSelectorFactory);
    ByteBuffer buffer = ByteBuffer.wrap(new byte[longFirstAggFactory.getMaxIntermediateSize()]);
    agg.init(buffer, 0);
    aggregate(agg, buffer, 0);
    aggregate(agg, buffer, 0);
    aggregate(agg, buffer, 0);
    aggregate(agg, buffer, 0);
    Pair<Long, Long> result = (Pair<Long, Long>) agg.get(buffer, 0);
    Assert.assertEquals(times[3], result.lhs.longValue());
    Assert.assertEquals(longValues[3], result.rhs.longValue());
    Assert.assertEquals(longValues[3], agg.getLong(buffer, 0));
    Assert.assertEquals(longValues[3], agg.getFloat(buffer, 0), 0.0001);
}
Also used : ByteBuffer(java.nio.ByteBuffer) SerializablePair(io.druid.collections.SerializablePair) Pair(io.druid.java.util.common.Pair) Test(org.junit.Test)

Example 34 with Pair

use of io.druid.java.util.common.Pair in project druid by druid-io.

the class LongFirstAggregationTest method testLongFirstCombiningBufferAggregator.

@Test
public void testLongFirstCombiningBufferAggregator() {
    LongFirstBufferAggregator agg = (LongFirstBufferAggregator) combiningAggFactory.factorizeBuffered(colSelectorFactory);
    ByteBuffer buffer = ByteBuffer.wrap(new byte[longFirstAggFactory.getMaxIntermediateSize()]);
    agg.init(buffer, 0);
    aggregate(agg, buffer, 0);
    aggregate(agg, buffer, 0);
    aggregate(agg, buffer, 0);
    aggregate(agg, buffer, 0);
    Pair<Long, Long> result = (Pair<Long, Long>) agg.get(buffer, 0);
    Pair<Long, Long> expected = (Pair<Long, Long>) pairs[0];
    Assert.assertEquals(expected.lhs, result.lhs);
    Assert.assertEquals(expected.rhs, result.rhs);
    Assert.assertEquals(expected.rhs.longValue(), agg.getLong(buffer, 0));
    Assert.assertEquals(expected.rhs, agg.getFloat(buffer, 0), 0.0001);
}
Also used : ByteBuffer(java.nio.ByteBuffer) SerializablePair(io.druid.collections.SerializablePair) Pair(io.druid.java.util.common.Pair) Test(org.junit.Test)

Example 35 with Pair

use of io.druid.java.util.common.Pair in project druid by druid-io.

the class ServerManagerTest method testReferenceCounting.

@Test
public void testReferenceCounting() throws Exception {
    loadQueryable("test", "3", new Interval("2011-04-04/2011-04-05"));
    Future future = assertQueryable(Granularities.DAY, "test", new Interval("2011-04-04/2011-04-06"), ImmutableList.<Pair<String, Interval>>of(new Pair<String, Interval>("3", new Interval("2011-04-04/2011-04-05"))));
    queryNotifyLatch.await(1000, TimeUnit.MILLISECONDS);
    Assert.assertEquals(1, factory.getSegmentReferences().size());
    for (ReferenceCountingSegment referenceCountingSegment : factory.getSegmentReferences()) {
        Assert.assertEquals(1, referenceCountingSegment.getNumReferences());
    }
    queryWaitYieldLatch.countDown();
    Assert.assertTrue(factory.getAdapters().size() == 1);
    for (SegmentForTesting segmentForTesting : factory.getAdapters()) {
        Assert.assertFalse(segmentForTesting.isClosed());
    }
    queryWaitLatch.countDown();
    future.get();
    dropQueryable("test", "3", new Interval("2011-04-04/2011-04-05"));
    for (SegmentForTesting segmentForTesting : factory.getAdapters()) {
        Assert.assertTrue(segmentForTesting.isClosed());
    }
}
Also used : ReferenceCountingSegment(io.druid.segment.ReferenceCountingSegment) Future(java.util.concurrent.Future) Interval(org.joda.time.Interval) Pair(io.druid.java.util.common.Pair) Test(org.junit.Test)

Aggregations

Pair (io.druid.java.util.common.Pair)62 Test (org.junit.Test)26 Interval (org.joda.time.Interval)15 DataSegment (io.druid.timeline.DataSegment)11 Map (java.util.Map)11 ByteBuffer (java.nio.ByteBuffer)10 HashMap (java.util.HashMap)9 SerializablePair (io.druid.collections.SerializablePair)8 SegmentDescriptor (io.druid.query.SegmentDescriptor)8 List (java.util.List)8 ImmutableMap (com.google.common.collect.ImmutableMap)7 Executor (java.util.concurrent.Executor)7 DateTime (org.joda.time.DateTime)7 Function (com.google.common.base.Function)6 ListenableFuture (com.google.common.util.concurrent.ListenableFuture)6 MapBasedInputRow (io.druid.data.input.MapBasedInputRow)6 TaskStatus (io.druid.indexing.common.TaskStatus)6 ISE (io.druid.java.util.common.ISE)6 Access (io.druid.server.security.Access)6 Action (io.druid.server.security.Action)6