Search in sources :

Example 6 with VectorAggregator

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

the class DoubleAnyAggregatorFactoryTest method factorizeVectorForStringTypeShouldReturnDoubleVectorAggregatorWithNilSelector.

@Test
public void factorizeVectorForStringTypeShouldReturnDoubleVectorAggregatorWithNilSelector() {
    Mockito.doReturn(capabilities).when(selectorFactory).getColumnCapabilities(FIELD_NAME);
    Mockito.doReturn(false).when(capabilities).isNumeric();
    VectorAggregator aggregator = target.factorizeVector(selectorFactory);
    Assert.assertNotNull(aggregator);
    Assert.assertEquals(NullHandling.defaultDoubleValue(), aggregator.get(BUFFER, POSITION));
}
Also used : VectorAggregator(org.apache.druid.query.aggregation.VectorAggregator) InitializedNullHandlingTest(org.apache.druid.testing.InitializedNullHandlingTest) Test(org.junit.Test)

Example 7 with VectorAggregator

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

the class VarianceAggregatorFactoryUnitTest method factorizeVectorForDoubleShouldReturnFloatVectorAggregator.

@Test
public void factorizeVectorForDoubleShouldReturnFloatVectorAggregator() {
    target = new VarianceAggregatorFactory(NAME, FIELD_NAME, null, DOUBLE);
    VectorAggregator agg = target.factorizeVector(selectorFactory);
    Assert.assertNotNull(agg);
    Assert.assertEquals(VarianceDoubleVectorAggregator.class, agg.getClass());
}
Also used : VectorAggregator(org.apache.druid.query.aggregation.VectorAggregator) InitializedNullHandlingTest(org.apache.druid.testing.InitializedNullHandlingTest) Test(org.junit.Test)

Example 8 with VectorAggregator

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

the class VarianceAggregatorFactoryUnitTest method factorizeVectorForComplexShouldReturnObjectVectorAggregator.

@Test
public void factorizeVectorForComplexShouldReturnObjectVectorAggregator() {
    mockType(VarianceAggregatorFactory.TYPE);
    VectorAggregator agg = target.factorizeVector(selectorFactory);
    Assert.assertNotNull(agg);
    Assert.assertEquals(VarianceObjectVectorAggregator.class, agg.getClass());
}
Also used : VectorAggregator(org.apache.druid.query.aggregation.VectorAggregator) InitializedNullHandlingTest(org.apache.druid.testing.InitializedNullHandlingTest) Test(org.junit.Test)

Example 9 with VectorAggregator

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

the class ApproximateHistogramFoldingVectorAggregatorTest method testAggregateMultiPositions.

@Test
public void testAggregateMultiPositions() {
    ApproximateHistogramFoldingAggregatorFactory factory = buildHistogramFactory();
    ByteBuffer byteBuffer = ByteBuffer.allocate(factory.getMaxIntermediateSize() * 2);
    int[] positions = new int[] { 0, factory.getMaxIntermediateSize() };
    VectorAggregator vectorAggregator = factory.factorizeVector(vectorColumnSelectorFactory);
    vectorAggregator.init(byteBuffer, 0);
    vectorAggregator.init(byteBuffer, positions[1]);
    vectorAggregator.aggregate(byteBuffer, 2, positions, null, 0);
    // indirection
    vectorAggregator.aggregate(byteBuffer, 2, positions, new int[] { 1, 2 }, 0);
    ApproximateHistogram actualH1 = (ApproximateHistogram) vectorAggregator.get(byteBuffer, 0);
    ApproximateHistogram actualH2 = (ApproximateHistogram) vectorAggregator.get(byteBuffer, positions[1]);
    Assert.assertEquals(actualH1, h1);
    Assert.assertEquals(actualH2, h2);
}
Also used : VectorAggregator(org.apache.druid.query.aggregation.VectorAggregator) ByteBuffer(java.nio.ByteBuffer) Test(org.junit.Test)

Example 10 with VectorAggregator

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

the class FixedBucketsHistogramVectorAggregatorTest method testAggregateSinglePosition.

@Test
public void testAggregateSinglePosition() {
    ByteBuffer byteBuffer = ByteBuffer.allocate(FixedBucketsHistogram.getFullStorageSize(2));
    FixedBucketsHistogramAggregatorFactory factory = buildHistogramAggFactory("field_1");
    Assert.assertTrue(factory.canVectorize(vectorColumnSelectorFactory));
    VectorAggregator vectorAggregator = factory.factorizeVector(vectorColumnSelectorFactory);
    vectorAggregator.init(byteBuffer, 0);
    vectorAggregator.aggregate(byteBuffer, 0, 0, 6);
    FixedBucketsHistogram h = (FixedBucketsHistogram) vectorAggregator.get(byteBuffer, 0);
    Assert.assertEquals(2, h.getNumBuckets());
    Assert.assertEquals(10.0, h.getBucketSize(), 0.01);
    Assert.assertEquals(1, h.getLowerLimit(), 0.01);
    Assert.assertEquals(21, h.getUpperLimit(), 0.01);
    Assert.assertEquals(FixedBucketsHistogram.OutlierHandlingMode.OVERFLOW, h.getOutlierHandlingMode());
    Assert.assertArrayEquals(new long[] { 2, 3 }, h.getHistogram());
    Assert.assertEquals(5, h.getCount());
    Assert.assertEquals(1.0, h.getMin(), 0.01);
    Assert.assertEquals(16.0, h.getMax(), 0.01);
    // Default value of null is 0 which is an outlier.
    Assert.assertEquals(NullHandling.replaceWithDefault() ? 0 : 1, h.getMissingValueCount());
    Assert.assertEquals(NullHandling.replaceWithDefault() ? 1 : 0, h.getLowerOutlierCount());
    Assert.assertEquals(0, h.getUpperOutlierCount());
    factory = buildHistogramAggFactory("field_2");
    vectorAggregator = factory.factorizeVector(vectorColumnSelectorFactory);
    vectorAggregator.init(byteBuffer, 0);
    vectorAggregator.aggregate(byteBuffer, 0, 0, 6);
    h = (FixedBucketsHistogram) vectorAggregator.get(byteBuffer, 0);
    Assert.assertEquals(2, h.getNumBuckets());
    Assert.assertEquals(10.0, h.getBucketSize(), 0.01);
    Assert.assertEquals(1, h.getLowerLimit(), 0.01);
    Assert.assertEquals(21, h.getUpperLimit(), 0.01);
    Assert.assertEquals(FixedBucketsHistogram.OutlierHandlingMode.OVERFLOW, h.getOutlierHandlingMode());
    Assert.assertArrayEquals(new long[] { 2, 4 }, h.getHistogram());
    Assert.assertEquals(6, h.getCount());
    Assert.assertEquals(1.0, h.getMin(), 0.01);
    Assert.assertEquals(16.0, h.getMax(), 0.01);
    Assert.assertEquals(0, h.getMissingValueCount());
    Assert.assertEquals(0, h.getLowerOutlierCount());
    Assert.assertEquals(0, h.getUpperOutlierCount());
}
Also used : VectorAggregator(org.apache.druid.query.aggregation.VectorAggregator) ByteBuffer(java.nio.ByteBuffer) 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