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);
}
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);
}
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);
}
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;
}
}
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);
}
Aggregations