Search in sources :

Example 16 with VectorAggregator

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

the class ApproximateHistogramVectorAggregatorTest method testAggregateMultiPositions.

@Test
public void testAggregateMultiPositions() {
    ApproximateHistogramAggregatorFactory factory = buildHistogramAggFactory("field_2");
    int size = factory.getMaxIntermediateSize();
    ByteBuffer byteBuffer = ByteBuffer.allocate(size * 2);
    VectorAggregator vectorAggregator = factory.factorizeVector(vectorColumnSelectorFactory);
    int[] positions = new int[] { 0, size };
    vectorAggregator.init(byteBuffer, positions[0]);
    vectorAggregator.init(byteBuffer, positions[1]);
    vectorAggregator.aggregate(byteBuffer, 2, positions, null, 0);
    // Put rest of 10 elements using the access indirection. Second vector gets the same element always
    for (int i = 1; i < 10; i++) {
        vectorAggregator.aggregate(byteBuffer, 2, positions, new int[] { i, 1 }, 0);
    }
    ApproximateHistogram h0 = (ApproximateHistogram) vectorAggregator.get(byteBuffer, 0);
    Assert.assertArrayEquals(new float[] { 2, 9.5f, 19.33f, 32.67f, 45f }, h0.positions(), 0.1f);
    Assert.assertArrayEquals(new long[] { 1, 2, 3, 3, 1 }, h0.bins());
    ApproximateHistogram h2 = (ApproximateHistogram) vectorAggregator.get(byteBuffer, size);
    Assert.assertArrayEquals(new float[] { 19 }, h2.positions(), 0.1f);
    Assert.assertArrayEquals(new long[] { 10 }, h2.bins());
}
Also used : VectorAggregator(org.apache.druid.query.aggregation.VectorAggregator) ByteBuffer(java.nio.ByteBuffer) Test(org.junit.Test)

Example 17 with VectorAggregator

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

the class ApproximateHistogramVectorAggregatorTest method testAggregateSinglePosition.

@Test
public void testAggregateSinglePosition() {
    ApproximateHistogramAggregatorFactory factory = buildHistogramAggFactory("field_1");
    ByteBuffer byteBuffer = ByteBuffer.allocate(factory.getMaxIntermediateSizeWithNulls());
    Assert.assertTrue(factory.canVectorize(vectorColumnSelectorFactory));
    VectorAggregator vectorAggregator = factory.factorizeVector(vectorColumnSelectorFactory);
    vectorAggregator.init(byteBuffer, 0);
    vectorAggregator.aggregate(byteBuffer, 0, 0, 11);
    ApproximateHistogram h = (ApproximateHistogram) vectorAggregator.get(byteBuffer, 0);
    // (2, 1), (9.5, 2), (19.33, 3), (32.67, 3), (45, 1)
    Assert.assertArrayEquals(new float[] { 2, 9.5f, 19.33f, 32.67f, 45f }, h.positions(), 0.1f);
    Assert.assertArrayEquals(new long[] { 1, 2, 3, 3, 1 }, h.bins());
    factory = buildHistogramAggFactory("field_2");
    vectorAggregator = factory.factorizeVector(vectorColumnSelectorFactory);
    vectorAggregator.init(byteBuffer, 0);
    vectorAggregator.aggregate(byteBuffer, 0, 0, 10);
    h = (ApproximateHistogram) vectorAggregator.get(byteBuffer, 0);
    Assert.assertArrayEquals(new float[] { 2, 9.5f, 19.33f, 32.67f, 45f }, h.positions(), 0.1f);
    Assert.assertArrayEquals(new long[] { 1, 2, 3, 3, 1 }, h.bins());
}
Also used : VectorAggregator(org.apache.druid.query.aggregation.VectorAggregator) ByteBuffer(java.nio.ByteBuffer) Test(org.junit.Test)

Example 18 with VectorAggregator

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

the class ApproximateHistogramFoldingVectorAggregatorTest method testAggregateSinglePosition.

@Test
public void testAggregateSinglePosition() {
    ApproximateHistogramFoldingAggregatorFactory factory = buildHistogramFactory();
    ByteBuffer byteBuffer = ByteBuffer.allocate(factory.getMaxIntermediateSize());
    Assert.assertTrue(factory.canVectorize(vectorColumnSelectorFactory));
    VectorAggregator vectorAggregator = factory.factorizeVector(vectorColumnSelectorFactory);
    vectorAggregator.init(byteBuffer, 0);
    vectorAggregator.aggregate(byteBuffer, 0, 0, 4);
    ApproximateHistogram h = (ApproximateHistogram) vectorAggregator.get(byteBuffer, 0);
    Assert.assertArrayEquals(new float[] { 19.6f, 45.0f }, h.positions(), 0.1f);
    Assert.assertArrayEquals(new long[] { 9, 1 }, h.bins());
    Assert.assertEquals(10, h.count());
    Assert.assertEquals(2.0f, h.min(), 0.1f);
    Assert.assertEquals(45.0f, h.max(), 0.1f);
}
Also used : VectorAggregator(org.apache.druid.query.aggregation.VectorAggregator) ByteBuffer(java.nio.ByteBuffer) Test(org.junit.Test)

Example 19 with VectorAggregator

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

the class FixedBucketsHistogramVectorAggregatorTest method testAggregateMultiPositions.

@Test
public void testAggregateMultiPositions() {
    int size = FixedBucketsHistogram.getFullStorageSize(2);
    ByteBuffer byteBuffer = ByteBuffer.allocate(size * 2);
    FixedBucketsHistogramAggregatorFactory factory = buildHistogramAggFactory("field_2");
    VectorAggregator vectorAggregator = factory.factorizeVector(vectorColumnSelectorFactory);
    int[] positions = new int[] { 0, size };
    vectorAggregator.init(byteBuffer, positions[0]);
    vectorAggregator.init(byteBuffer, positions[1]);
    vectorAggregator.aggregate(byteBuffer, 2, positions, null, 0);
    FixedBucketsHistogram h0 = (FixedBucketsHistogram) vectorAggregator.get(byteBuffer, 0);
    Assert.assertEquals(2, h0.getNumBuckets());
    Assert.assertEquals(10.0, h0.getBucketSize(), 0.01);
    Assert.assertEquals(1, h0.getLowerLimit(), 0.01);
    Assert.assertEquals(21, h0.getUpperLimit(), 0.01);
    Assert.assertEquals(FixedBucketsHistogram.OutlierHandlingMode.OVERFLOW, h0.getOutlierHandlingMode());
    Assert.assertArrayEquals(new long[] { 1, 0 }, h0.getHistogram());
    Assert.assertEquals(1, h0.getCount());
    Assert.assertEquals(1.0, h0.getMin(), 0.01);
    Assert.assertEquals(1.0, h0.getMax(), 0.01);
    Assert.assertEquals(0, h0.getMissingValueCount());
    Assert.assertEquals(0, h0.getLowerOutlierCount());
    Assert.assertEquals(0, h0.getUpperOutlierCount());
    FixedBucketsHistogram h1 = (FixedBucketsHistogram) vectorAggregator.get(byteBuffer, positions[1]);
    Assert.assertEquals(2, h1.getNumBuckets());
    Assert.assertEquals(10.0, h1.getBucketSize(), 0.01);
    Assert.assertEquals(1, h1.getLowerLimit(), 0.01);
    Assert.assertEquals(21, h1.getUpperLimit(), 0.01);
    Assert.assertEquals(FixedBucketsHistogram.OutlierHandlingMode.OVERFLOW, h1.getOutlierHandlingMode());
    Assert.assertArrayEquals(new long[] { 0, 1 }, h1.getHistogram());
    Assert.assertEquals(1, h1.getCount());
    Assert.assertEquals(12.0, h1.getMin(), 0.01);
    Assert.assertEquals(12.0, h1.getMax(), 0.01);
    Assert.assertEquals(0, h1.getMissingValueCount());
    Assert.assertEquals(0, h1.getLowerOutlierCount());
    Assert.assertEquals(0, h1.getUpperOutlierCount());
    // Tests when there is a level of indirection in accessing the vector
    byteBuffer = ByteBuffer.allocate(size * 2);
    vectorAggregator.init(byteBuffer, positions[0]);
    vectorAggregator.init(byteBuffer, positions[1]);
    vectorAggregator.aggregate(byteBuffer, 2, positions, new int[] { 2, 3 }, 0);
    FixedBucketsHistogram h2 = (FixedBucketsHistogram) vectorAggregator.get(byteBuffer, 0);
    Assert.assertEquals(2, h2.getNumBuckets());
    Assert.assertEquals(10.0, h2.getBucketSize(), 0.01);
    Assert.assertEquals(1, h2.getLowerLimit(), 0.01);
    Assert.assertEquals(21, h2.getUpperLimit(), 0.01);
    Assert.assertEquals(FixedBucketsHistogram.OutlierHandlingMode.OVERFLOW, h2.getOutlierHandlingMode());
    Assert.assertArrayEquals(new long[] { 1, 0 }, h2.getHistogram());
    Assert.assertEquals(1, h2.getCount());
    Assert.assertEquals(3.0, h2.getMin(), 0.01);
    Assert.assertEquals(3.0, h2.getMax(), 0.01);
    Assert.assertEquals(0, h2.getMissingValueCount());
    Assert.assertEquals(0, h2.getLowerOutlierCount());
    Assert.assertEquals(0, h2.getUpperOutlierCount());
    FixedBucketsHistogram h3 = (FixedBucketsHistogram) vectorAggregator.get(byteBuffer, positions[1]);
    Assert.assertEquals(2, h3.getNumBuckets());
    Assert.assertEquals(10.0, h3.getBucketSize(), 0.01);
    Assert.assertEquals(1, h3.getLowerLimit(), 0.01);
    Assert.assertEquals(21, h3.getUpperLimit(), 0.01);
    Assert.assertEquals(FixedBucketsHistogram.OutlierHandlingMode.OVERFLOW, h3.getOutlierHandlingMode());
    Assert.assertArrayEquals(new long[] { 0, 1 }, h3.getHistogram());
    Assert.assertEquals(1, h3.getCount());
    Assert.assertEquals(14.0, h3.getMin(), 0.01);
    Assert.assertEquals(14.0, h3.getMax(), 0.01);
    Assert.assertEquals(0, h3.getMissingValueCount());
    Assert.assertEquals(0, h3.getLowerOutlierCount());
    Assert.assertEquals(0, h3.getUpperOutlierCount());
}
Also used : VectorAggregator(org.apache.druid.query.aggregation.VectorAggregator) ByteBuffer(java.nio.ByteBuffer) Test(org.junit.Test)

Example 20 with VectorAggregator

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

the class DoubleAnyAggregatorFactoryTest method factorizeVectorShouldReturnDoubleVectorAggregator.

@Test
public void factorizeVectorShouldReturnDoubleVectorAggregator() {
    VectorAggregator aggregator = target.factorizeVector(selectorFactory);
    Assert.assertNotNull(aggregator);
    Assert.assertEquals(DoubleAnyVectorAggregator.class, aggregator.getClass());
}
Also used : VectorAggregator(org.apache.druid.query.aggregation.VectorAggregator) InitializedNullHandlingTest(org.apache.druid.testing.InitializedNullHandlingTest) Test(org.junit.Test)

Aggregations

VectorAggregator (org.apache.druid.query.aggregation.VectorAggregator)21 Test (org.junit.Test)20 InitializedNullHandlingTest (org.apache.druid.testing.InitializedNullHandlingTest)14 ByteBuffer (java.nio.ByteBuffer)7 ISE (org.apache.druid.java.util.common.ISE)1 CountAggregatorFactory (org.apache.druid.query.aggregation.CountAggregatorFactory)1 FilteredAggregatorFactory (org.apache.druid.query.aggregation.FilteredAggregatorFactory)1 VectorCursor (org.apache.druid.segment.vector.VectorCursor)1