Search in sources :

Example 1 with ColumnCapabilitiesImpl

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

the class VectorValueMatcherColumnProcessorFactoryTest method testSingleValueStringOneCardinalityBooleanMatcherIfNullAndNameLookupNotPossible.

@Test
public void testSingleValueStringOneCardinalityBooleanMatcherIfNullAndNameLookupNotPossible() {
    // if name lookup not possible in advance, use normal path, even if cardinality 1
    IdLookup lookup = EasyMock.createMock(IdLookup.class);
    SingleValueDimensionVectorSelector selector = EasyMock.createMock(SingleValueDimensionVectorSelector.class);
    EasyMock.expect(selector.getCurrentVectorSize()).andReturn(CURRENT_SIZE).anyTimes();
    EasyMock.expect(selector.getMaxVectorSize()).andReturn(VECTOR_SIZE).anyTimes();
    EasyMock.expect(selector.getValueCardinality()).andReturn(1).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().makeSingleValueDimensionProcessor(new ColumnCapabilitiesImpl().setType(ColumnType.STRING).setHasMultipleValues(false).setHasBitmapIndexes(true).setDictionaryValuesUnique(true).setDictionaryValuesSorted(true).setDictionaryEncoded(true), selector);
    Assert.assertTrue(matcherFactory instanceof SingleValueStringVectorValueMatcher);
    VectorValueMatcher matcher = matcherFactory.makeMatcher("any value");
    Assert.assertFalse(matcher instanceof BooleanVectorValueMatcher);
    Assert.assertEquals(VECTOR_SIZE, matcher.getMaxVectorSize());
    Assert.assertEquals(CURRENT_SIZE, matcher.getCurrentVectorSize());
    EasyMock.verify(selector, lookup);
}
Also used : IdLookup(org.apache.druid.segment.IdLookup) SingleValueDimensionVectorSelector(org.apache.druid.segment.vector.SingleValueDimensionVectorSelector) ColumnCapabilitiesImpl(org.apache.druid.segment.column.ColumnCapabilitiesImpl) InitializedNullHandlingTest(org.apache.druid.testing.InitializedNullHandlingTest) Test(org.junit.Test)

Example 2 with ColumnCapabilitiesImpl

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

the class VectorValueMatcherColumnProcessorFactoryTest method testSingleValueStringZeroCardinalityAlwaysBooleanMatcher.

@Test
public void testSingleValueStringZeroCardinalityAlwaysBooleanMatcher() {
    // cardinality 0 has special path to always use boolean matcher
    SingleValueDimensionVectorSelector selector = EasyMock.createMock(SingleValueDimensionVectorSelector.class);
    EasyMock.expect(selector.getCurrentVectorSize()).andReturn(CURRENT_SIZE).anyTimes();
    EasyMock.expect(selector.getMaxVectorSize()).andReturn(VECTOR_SIZE).anyTimes();
    EasyMock.expect(selector.getValueCardinality()).andReturn(0).anyTimes();
    EasyMock.replay(selector);
    VectorValueMatcherFactory matcherFactory = VectorValueMatcherColumnProcessorFactory.instance().makeSingleValueDimensionProcessor(new ColumnCapabilitiesImpl().setType(ColumnType.STRING).setHasMultipleValues(false).setHasBitmapIndexes(true).setDictionaryValuesUnique(true).setDictionaryValuesSorted(true).setDictionaryEncoded(true), selector);
    Assert.assertTrue(matcherFactory instanceof SingleValueStringVectorValueMatcher);
    VectorValueMatcher matcher = matcherFactory.makeMatcher("any value");
    Assert.assertTrue(matcher instanceof BooleanVectorValueMatcher);
    Assert.assertEquals(VECTOR_SIZE, matcher.getMaxVectorSize());
    Assert.assertEquals(CURRENT_SIZE, matcher.getCurrentVectorSize());
    // all are boolean with no valued column i guess
    VectorValueMatcher anotherMatcher = matcherFactory.makeMatcher((String) null);
    Assert.assertTrue(anotherMatcher instanceof BooleanVectorValueMatcher);
    Assert.assertEquals(VECTOR_SIZE, anotherMatcher.getMaxVectorSize());
    Assert.assertEquals(CURRENT_SIZE, anotherMatcher.getCurrentVectorSize());
    EasyMock.verify(selector);
}
Also used : SingleValueDimensionVectorSelector(org.apache.druid.segment.vector.SingleValueDimensionVectorSelector) ColumnCapabilitiesImpl(org.apache.druid.segment.column.ColumnCapabilitiesImpl) InitializedNullHandlingTest(org.apache.druid.testing.InitializedNullHandlingTest) Test(org.junit.Test)

Example 3 with ColumnCapabilitiesImpl

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

the class VectorValueMatcherColumnProcessorFactoryTest method testSingleValueString.

@Test
public void testSingleValueString() {
    IdLookup lookup = EasyMock.createMock(IdLookup.class);
    SingleValueDimensionVectorSelector selector = EasyMock.createMock(SingleValueDimensionVectorSelector.class);
    EasyMock.expect(selector.getCurrentVectorSize()).andReturn(CURRENT_SIZE).anyTimes();
    EasyMock.expect(selector.getMaxVectorSize()).andReturn(VECTOR_SIZE).anyTimes();
    EasyMock.expect(selector.getValueCardinality()).andReturn(1024).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("another value")).andReturn(-1).anyTimes();
    EasyMock.replay(selector, lookup);
    VectorValueMatcherFactory matcherFactory = VectorValueMatcherColumnProcessorFactory.instance().makeSingleValueDimensionProcessor(new ColumnCapabilitiesImpl().setType(ColumnType.STRING).setHasMultipleValues(false).setHasBitmapIndexes(true).setDictionaryValuesUnique(true).setDictionaryValuesSorted(true).setDictionaryEncoded(true), selector);
    Assert.assertTrue(matcherFactory instanceof SingleValueStringVectorValueMatcher);
    // value exists in column nonboolean matcher
    VectorValueMatcher matcher = matcherFactory.makeMatcher("any value");
    Assert.assertFalse(matcher instanceof BooleanVectorValueMatcher);
    Assert.assertEquals(VECTOR_SIZE, matcher.getMaxVectorSize());
    Assert.assertEquals(CURRENT_SIZE, matcher.getCurrentVectorSize());
    // value not exist in dictionary uses boolean matcher
    VectorValueMatcher booleanMatcher = matcherFactory.makeMatcher("another value");
    Assert.assertTrue(booleanMatcher instanceof BooleanVectorValueMatcher);
    Assert.assertEquals(VECTOR_SIZE, booleanMatcher.getMaxVectorSize());
    Assert.assertEquals(CURRENT_SIZE, booleanMatcher.getCurrentVectorSize());
    EasyMock.verify(selector, lookup);
}
Also used : IdLookup(org.apache.druid.segment.IdLookup) SingleValueDimensionVectorSelector(org.apache.druid.segment.vector.SingleValueDimensionVectorSelector) ColumnCapabilitiesImpl(org.apache.druid.segment.column.ColumnCapabilitiesImpl) InitializedNullHandlingTest(org.apache.druid.testing.InitializedNullHandlingTest) Test(org.junit.Test)

Example 4 with ColumnCapabilitiesImpl

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

the class IndexedTableColumnSelectorFactory method columnCapabilities.

@Nullable
static ColumnCapabilities columnCapabilities(final IndexedTable table, final String columnName) {
    final ColumnType valueType = table.rowSignature().getColumnType(columnName).orElse(null);
    if (valueType != null) {
        final ColumnCapabilitiesImpl capabilities = new ColumnCapabilitiesImpl().setType(valueType);
        if (valueType.is(ValueType.STRING)) {
            // IndexedTables are not _really_ dictionary-encoded, but we fake it using the row number as the dict. code.
            capabilities.setDictionaryEncoded(true);
        }
        capabilities.setDictionaryValuesSorted(false);
        capabilities.setDictionaryValuesUnique(false);
        capabilities.setHasMultipleValues(false);
        return capabilities;
    } else {
        return null;
    }
}
Also used : ColumnType(org.apache.druid.segment.column.ColumnType) ColumnCapabilitiesImpl(org.apache.druid.segment.column.ColumnCapabilitiesImpl) Nullable(javax.annotation.Nullable)

Example 5 with ColumnCapabilitiesImpl

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

the class GroupByQueryEngineV2Test method testCanPushDownLimitForComplexSelector.

@Test
public void testCanPushDownLimitForComplexSelector() {
    ColumnCapabilitiesImpl capabilities = new ColumnCapabilitiesImpl().setType(new ColumnType(ValueType.COMPLEX, "foo", null)).setHasBitmapIndexes(false).setHasMultipleValues(false).setDictionaryEncoded(false).setDictionaryValuesSorted(false).setDictionaryValuesUnique(false);
    EasyMock.expect(factory.getColumnCapabilities(DIM)).andReturn(capabilities).once();
    EasyMock.replay(factory);
    Assert.assertTrue(GroupByQueryEngineV2.canPushDownLimit(factory, DIM));
    EasyMock.verify(factory);
}
Also used : ColumnType(org.apache.druid.segment.column.ColumnType) ColumnCapabilitiesImpl(org.apache.druid.segment.column.ColumnCapabilitiesImpl) 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