Search in sources :

Example 16 with ColumnCapabilitiesImpl

use of org.apache.druid.segment.column.ColumnCapabilitiesImpl in project druid by druid-io.

the class VarianceAggregatorTest method testObjectVarianceBufferAggregatorWithZeroCount.

@Test
public void testObjectVarianceBufferAggregatorWithZeroCount() {
    VarianceAggregatorCollector holder1 = new VarianceAggregatorCollector().add(1.1f);
    VarianceAggregatorCollector holder2 = new VarianceAggregatorCollector().add(2.7f);
    VarianceAggregatorCollector holder3 = new VarianceAggregatorCollector();
    VarianceAggregatorCollector[] values = { holder1, holder2, holder3 };
    TestObjectColumnSelector<VarianceAggregatorCollector> selector = new TestObjectColumnSelector(values);
    colSelectorFactory = EasyMock.createMock(ColumnSelectorFactory.class);
    EasyMock.expect(colSelectorFactory.makeColumnValueSelector("nilly")).andReturn(selector);
    EasyMock.expect(colSelectorFactory.getColumnCapabilities("nilly")).andReturn(new ColumnCapabilitiesImpl().setType(VarianceAggregatorFactory.TYPE));
    EasyMock.replay(colSelectorFactory);
    VarianceBufferAggregator agg = (VarianceBufferAggregator) aggFactory.factorizeBuffered(colSelectorFactory);
    ByteBuffer buffer = ByteBuffer.wrap(new byte[aggFactory.getMaxIntermediateSizeWithNulls()]);
    agg.init(buffer, 0);
    assertValues((VarianceAggregatorCollector) agg.get(buffer, 0), 0, 0d, 0d);
    aggregate(selector, agg, buffer, 0);
    assertValues((VarianceAggregatorCollector) agg.get(buffer, 0), 1, 1.1d, 0d);
    aggregate(selector, agg, buffer, 0);
    assertValues((VarianceAggregatorCollector) agg.get(buffer, 0), 2, 3.8d, 1.28d);
    aggregate(selector, agg, buffer, 0);
    assertValues((VarianceAggregatorCollector) agg.get(buffer, 0), 2, 3.8d, 1.28d);
}
Also used : TestObjectColumnSelector(org.apache.druid.query.aggregation.TestObjectColumnSelector) ColumnSelectorFactory(org.apache.druid.segment.ColumnSelectorFactory) ByteBuffer(java.nio.ByteBuffer) ColumnCapabilitiesImpl(org.apache.druid.segment.column.ColumnCapabilitiesImpl) InitializedNullHandlingTest(org.apache.druid.testing.InitializedNullHandlingTest) Test(org.junit.Test)

Example 17 with ColumnCapabilitiesImpl

use of org.apache.druid.segment.column.ColumnCapabilitiesImpl in project druid by druid-io.

the class StringLastAggregationTest method setup.

@Before
public void setup() {
    NullHandling.initializeForTests();
    stringLastAggFactory = new StringLastAggregatorFactory("billy", "nilly", null, MAX_STRING_SIZE);
    combiningAggFactory = stringLastAggFactory.getCombiningFactory();
    timeSelector = new TestLongColumnSelector(times);
    customTimeSelector = new TestLongColumnSelector(customTimes);
    valueSelector = new TestObjectColumnSelector<>(strings);
    objectSelector = new TestObjectColumnSelector<>(pairs);
    colSelectorFactory = EasyMock.createMock(ColumnSelectorFactory.class);
    EasyMock.expect(colSelectorFactory.makeColumnValueSelector(ColumnHolder.TIME_COLUMN_NAME)).andReturn(timeSelector);
    EasyMock.expect(colSelectorFactory.makeColumnValueSelector("customTime")).andReturn(customTimeSelector);
    EasyMock.expect(colSelectorFactory.makeColumnValueSelector("nilly")).andReturn(valueSelector);
    EasyMock.expect(colSelectorFactory.makeColumnValueSelector("billy")).andReturn(objectSelector);
    EasyMock.expect(colSelectorFactory.getColumnCapabilities("nilly")).andReturn(new ColumnCapabilitiesImpl().setType(ColumnType.STRING));
    EasyMock.expect(colSelectorFactory.getColumnCapabilities("billy")).andReturn(null);
    EasyMock.replay(colSelectorFactory);
}
Also used : ColumnSelectorFactory(org.apache.druid.segment.ColumnSelectorFactory) TestLongColumnSelector(org.apache.druid.query.aggregation.TestLongColumnSelector) ColumnCapabilitiesImpl(org.apache.druid.segment.column.ColumnCapabilitiesImpl) Before(org.junit.Before)

Example 18 with ColumnCapabilitiesImpl

use of org.apache.druid.segment.column.ColumnCapabilitiesImpl in project druid by druid-io.

the class ApproximateHistogramFoldingVectorAggregatorTest method setup.

@Before
public void setup() {
    h1 = new ApproximateHistogram(5);
    h2 = new ApproximateHistogram(5);
    for (int i = 0; i < 5; ++i) {
        h1.offer(FLOATS[i]);
    }
    for (int i = 5; i < FLOATS.length; ++i) {
        h2.offer(FLOATS[i]);
    }
    VectorObjectSelector vectorObjectSelector = createMock(VectorObjectSelector.class);
    expect(vectorObjectSelector.getObjectVector()).andReturn(new Object[] { h1, null, h2, null }).anyTimes();
    EasyMock.replay(vectorObjectSelector);
    vectorColumnSelectorFactory = createMock(VectorColumnSelectorFactory.class);
    expect(vectorColumnSelectorFactory.makeObjectSelector("field")).andReturn(vectorObjectSelector).anyTimes();
    expect(vectorColumnSelectorFactory.getColumnCapabilities("field")).andReturn(new ColumnCapabilitiesImpl().setType(ApproximateHistogramAggregatorFactory.TYPE));
    expect(vectorColumnSelectorFactory.getColumnCapabilities("string_field")).andReturn(new ColumnCapabilitiesImpl().setType(ColumnType.STRING));
    expect(vectorColumnSelectorFactory.getColumnCapabilities("double_field")).andReturn(new ColumnCapabilitiesImpl().setType(ColumnType.STRING));
    EasyMock.replay(vectorColumnSelectorFactory);
}
Also used : VectorObjectSelector(org.apache.druid.segment.vector.VectorObjectSelector) VectorColumnSelectorFactory(org.apache.druid.segment.vector.VectorColumnSelectorFactory) ColumnCapabilitiesImpl(org.apache.druid.segment.column.ColumnCapabilitiesImpl) Before(org.junit.Before)

Example 19 with ColumnCapabilitiesImpl

use of org.apache.druid.segment.column.ColumnCapabilitiesImpl in project druid by druid-io.

the class IncrementalIndex method loadDimensionIterable.

/**
 * Currently called to initialize IncrementalIndex dimension order during index creation
 * Index dimension ordering could be changed to initialize from DimensionsSpec after resolution of
 * https://github.com/apache/druid/issues/2011
 */
public void loadDimensionIterable(Iterable<String> oldDimensionOrder, Map<String, ColumnCapabilities> oldColumnCapabilities) {
    synchronized (dimensionDescs) {
        if (!dimensionDescs.isEmpty()) {
            throw new ISE("Cannot load dimension order when existing order[%s] is not empty.", dimensionDescs.keySet());
        }
        for (String dim : oldDimensionOrder) {
            if (dimensionDescs.get(dim) == null) {
                ColumnCapabilitiesImpl capabilities = ColumnCapabilitiesImpl.snapshot(oldColumnCapabilities.get(dim), IndexMergerV9.DIMENSION_CAPABILITY_MERGE_LOGIC);
                DimensionHandler handler = DimensionHandlerUtils.getHandlerFromCapabilities(dim, capabilities, null);
                addNewDimension(dim, handler);
            }
        }
    }
}
Also used : DimensionHandler(org.apache.druid.segment.DimensionHandler) ISE(org.apache.druid.java.util.common.ISE) ColumnCapabilitiesImpl(org.apache.druid.segment.column.ColumnCapabilitiesImpl)

Example 20 with ColumnCapabilitiesImpl

use of org.apache.druid.segment.column.ColumnCapabilitiesImpl in project druid by druid-io.

the class VectorValueMatcherColumnProcessorFactoryTest method testMultiValueString.

@Test
public void testMultiValueString() {
    IdLookup lookup = EasyMock.createMock(IdLookup.class);
    MultiValueDimensionVectorSelector selector = EasyMock.createMock(MultiValueDimensionVectorSelector.class);
    EasyMock.expect(selector.getCurrentVectorSize()).andReturn(CURRENT_SIZE).anyTimes();
    EasyMock.expect(selector.getMaxVectorSize()).andReturn(VECTOR_SIZE).anyTimes();
    EasyMock.expect(selector.getValueCardinality()).andReturn(11).anyTimes();
    EasyMock.expect(selector.nameLookupPossibleInAdvance()).andReturn(false).anyTimes();
    EasyMock.expect(selector.idLookup()).andReturn(lookup).anyTimes();
    EasyMock.expect(lookup.lookupId("any value")).andReturn(-1).anyTimes();
    EasyMock.expect(lookup.lookupId(null)).andReturn(0).anyTimes();
    EasyMock.replay(selector, lookup);
    VectorValueMatcherFactory matcherFactory = VectorValueMatcherColumnProcessorFactory.instance().makeMultiValueDimensionProcessor(new ColumnCapabilitiesImpl().setType(ColumnType.STRING).setHasMultipleValues(false).setHasBitmapIndexes(true).setDictionaryValuesUnique(true).setDictionaryValuesSorted(true).setDictionaryEncoded(true), selector);
    Assert.assertTrue(matcherFactory instanceof MultiValueStringVectorValueMatcher);
    VectorValueMatcher valueNotExistMatcher = matcherFactory.makeMatcher("any value");
    Assert.assertTrue(valueNotExistMatcher instanceof BooleanVectorValueMatcher);
    Assert.assertEquals(VECTOR_SIZE, valueNotExistMatcher.getMaxVectorSize());
    Assert.assertEquals(CURRENT_SIZE, valueNotExistMatcher.getCurrentVectorSize());
    VectorValueMatcher valueExistMatcher = matcherFactory.makeMatcher((String) null);
    Assert.assertFalse(valueExistMatcher instanceof BooleanVectorValueMatcher);
    Assert.assertEquals(VECTOR_SIZE, valueExistMatcher.getMaxVectorSize());
    Assert.assertEquals(CURRENT_SIZE, valueExistMatcher.getCurrentVectorSize());
    EasyMock.verify(selector, lookup);
}
Also used : IdLookup(org.apache.druid.segment.IdLookup) MultiValueDimensionVectorSelector(org.apache.druid.segment.vector.MultiValueDimensionVectorSelector) ColumnCapabilitiesImpl(org.apache.druid.segment.column.ColumnCapabilitiesImpl) InitializedNullHandlingTest(org.apache.druid.testing.InitializedNullHandlingTest) Test(org.junit.Test)

Aggregations

ColumnCapabilitiesImpl (org.apache.druid.segment.column.ColumnCapabilitiesImpl)34 Test (org.junit.Test)20 ColumnSelectorFactory (org.apache.druid.segment.ColumnSelectorFactory)11 Before (org.junit.Before)10 InitializedNullHandlingTest (org.apache.druid.testing.InitializedNullHandlingTest)9 ColumnCapabilities (org.apache.druid.segment.column.ColumnCapabilities)8 VectorColumnSelectorFactory (org.apache.druid.segment.vector.VectorColumnSelectorFactory)8 VectorValueSelector (org.apache.druid.segment.vector.VectorValueSelector)7 IdLookup (org.apache.druid.segment.IdLookup)5 SingleValueDimensionVectorSelector (org.apache.druid.segment.vector.SingleValueDimensionVectorSelector)4 Nullable (javax.annotation.Nullable)3 ColumnType (org.apache.druid.segment.column.ColumnType)3 ByteBuffer (java.nio.ByteBuffer)2 BufferAggregator (org.apache.druid.query.aggregation.BufferAggregator)2 TestLongColumnSelector (org.apache.druid.query.aggregation.TestLongColumnSelector)2 DimensionSpec (org.apache.druid.query.dimension.DimensionSpec)2 ValueMatcher (org.apache.druid.query.filter.ValueMatcher)2 RuntimeShapeInspector (org.apache.druid.query.monomorphicprocessing.RuntimeShapeInspector)2 IndexedInts (org.apache.druid.segment.data.IndexedInts)2 Predicate (com.google.common.base.Predicate)1