use of org.apache.druid.segment.vector.SingleValueDimensionVectorSelector in project druid by druid-io.
the class VirtualColumns method makeSingleValueDimensionVectorSelector.
/**
* Create a single value dimension vector (string) selector.
*
* @throws IllegalArgumentException if the virtual column does not exist (see {@link #exists(String)}
*/
public SingleValueDimensionVectorSelector makeSingleValueDimensionVectorSelector(DimensionSpec dimensionSpec, VectorColumnSelectorFactory factory) {
final VirtualColumn virtualColumn = getVirtualColumnForSelector(dimensionSpec.getDimension());
final SingleValueDimensionVectorSelector selector = virtualColumn.makeSingleValueVectorDimensionSelector(dimensionSpec, factory);
Preconditions.checkNotNull(selector, "selector");
return selector;
}
use of org.apache.druid.segment.vector.SingleValueDimensionVectorSelector in project druid by druid-io.
the class VectorValueMatcherColumnProcessorFactoryTest method testSingleValueStringOneCardinalityBooleanMatcherIfNullAndNameLookupPossible.
@Test
public void testSingleValueStringOneCardinalityBooleanMatcherIfNullAndNameLookupPossible() {
// single value string column with cardinality 1 and name lookup possible in advance uses boolean matcher for
// matches
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(true).anyTimes();
EasyMock.expect(selector.lookupName(0)).andReturn(null).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);
// false matcher
VectorValueMatcher booleanMatcher = matcherFactory.makeMatcher("any value");
Assert.assertTrue(booleanMatcher instanceof BooleanVectorValueMatcher);
Assert.assertEquals(VECTOR_SIZE, booleanMatcher.getMaxVectorSize());
Assert.assertEquals(CURRENT_SIZE, booleanMatcher.getCurrentVectorSize());
// true matcher
VectorValueMatcher anotherBooleanMatcher = matcherFactory.makeMatcher((String) null);
Assert.assertTrue(anotherBooleanMatcher instanceof BooleanVectorValueMatcher);
Assert.assertEquals(VECTOR_SIZE, anotherBooleanMatcher.getMaxVectorSize());
Assert.assertEquals(CURRENT_SIZE, anotherBooleanMatcher.getCurrentVectorSize());
EasyMock.verify(selector);
}
use of org.apache.druid.segment.vector.SingleValueDimensionVectorSelector in project druid by druid-io.
the class BaseFilterTest method selectColumnValuesMatchingFilterUsingVectorizedPostFiltering.
private List<String> selectColumnValuesMatchingFilterUsingVectorizedPostFiltering(final DimFilter filter, final String selectColumn) {
final Filter theFilter = makeFilter(filter);
final Filter postFilteringFilter = new Filter() {
@Override
public <T> T getBitmapResult(BitmapIndexSelector selector, BitmapResultFactory<T> bitmapResultFactory) {
throw new UnsupportedOperationException();
}
@Override
public ValueMatcher makeMatcher(ColumnSelectorFactory factory) {
return theFilter.makeMatcher(factory);
}
@Override
public boolean supportsBitmapIndex(BitmapIndexSelector selector) {
return false;
}
@Override
public boolean shouldUseBitmapIndex(BitmapIndexSelector selector) {
return false;
}
@Override
public VectorValueMatcher makeVectorMatcher(VectorColumnSelectorFactory factory) {
return theFilter.makeVectorMatcher(factory);
}
@Override
public boolean canVectorizeMatcher(ColumnInspector inspector) {
return theFilter.canVectorizeMatcher(inspector);
}
@Override
public Set<String> getRequiredColumns() {
return null;
}
@Override
public boolean supportsSelectivityEstimation(ColumnSelector columnSelector, BitmapIndexSelector indexSelector) {
return false;
}
@Override
public double estimateSelectivity(BitmapIndexSelector indexSelector) {
return 1.0;
}
};
try (final VectorCursor cursor = makeVectorCursor(postFilteringFilter)) {
final SingleValueDimensionVectorSelector selector = cursor.getColumnSelectorFactory().makeSingleValueDimensionSelector(new DefaultDimensionSpec(selectColumn, selectColumn));
final List<String> values = new ArrayList<>();
while (!cursor.isDone()) {
final int[] rowVector = selector.getRowVector();
for (int i = 0; i < cursor.getCurrentVectorSize(); i++) {
values.add(selector.lookupName(rowVector[i]));
}
cursor.advance();
}
return values;
}
}
use of org.apache.druid.segment.vector.SingleValueDimensionVectorSelector in project druid by druid-io.
the class BaseFilterTest method selectColumnValuesMatchingFilterUsingVectorCursor.
private List<String> selectColumnValuesMatchingFilterUsingVectorCursor(final DimFilter filter, final String selectColumn) {
try (final VectorCursor cursor = makeVectorCursor(makeFilter(filter))) {
final SingleValueDimensionVectorSelector selector = cursor.getColumnSelectorFactory().makeSingleValueDimensionSelector(new DefaultDimensionSpec(selectColumn, selectColumn));
final List<String> values = new ArrayList<>();
while (!cursor.isDone()) {
final int[] rowVector = selector.getRowVector();
for (int i = 0; i < cursor.getCurrentVectorSize(); i++) {
values.add(selector.lookupName(rowVector[i]));
}
cursor.advance();
}
return values;
}
}
Aggregations