use of org.apache.druid.segment.vector.MultiValueDimensionVectorSelector 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);
}
use of org.apache.druid.segment.vector.MultiValueDimensionVectorSelector in project druid by druid-io.
the class AlwaysTwoVectorizedVirtualColumn method makeMultiValueVectorDimensionSelector.
@Override
public MultiValueDimensionVectorSelector makeMultiValueVectorDimensionSelector(DimensionSpec dimensionSpec, VectorColumnSelectorFactory factory) {
Assert.assertEquals(outputName, dimensionSpec.getOutputName());
final IndexedInts[] rowVector = new IndexedInts[factory.getReadableVectorInspector().getMaxVectorSize()];
Arrays.fill(rowVector, new ArrayBasedIndexedInts(new int[] { 0, 0 }));
return new MultiValueDimensionVectorSelector() {
private final VectorSizeInspector inspector = factory.getReadableVectorInspector();
@Override
public IndexedInts[] getRowVector() {
return rowVector;
}
@Override
public int getValueCardinality() {
return dictionaryEncoded ? 1 : CARDINALITY_UNKNOWN;
}
@Nullable
@Override
public String lookupName(int id) {
return "2";
}
@Override
public boolean nameLookupPossibleInAdvance() {
return dictionaryEncoded;
}
@Nullable
@Override
public IdLookup idLookup() {
return null;
}
@Override
public int getMaxVectorSize() {
return inspector.getMaxVectorSize();
}
@Override
public int getCurrentVectorSize() {
return inspector.getCurrentVectorSize();
}
};
}
use of org.apache.druid.segment.vector.MultiValueDimensionVectorSelector in project druid by druid-io.
the class VirtualColumns method makeMultiValueDimensionVectorSelector.
/**
* Create a multi value dimension vector (string) selector.
*
* @throws IllegalArgumentException if the virtual column does not exist (see {@link #exists(String)}
*/
public MultiValueDimensionVectorSelector makeMultiValueDimensionVectorSelector(DimensionSpec dimensionSpec, VectorColumnSelectorFactory factory) {
final VirtualColumn virtualColumn = getVirtualColumnForSelector(dimensionSpec.getDimension());
final MultiValueDimensionVectorSelector selector = virtualColumn.makeMultiValueVectorDimensionSelector(dimensionSpec, factory);
Preconditions.checkNotNull(selector, "selector");
return selector;
}
use of org.apache.druid.segment.vector.MultiValueDimensionVectorSelector in project druid by druid-io.
the class CardinalityVectorAggregatorTest method testAggregateMultiValueString.
@Test
public void testAggregateMultiValueString() {
final IndexedInts[] ids = { new ArrayBasedIndexedInts(new int[] { 1, 2 }), new ArrayBasedIndexedInts(new int[] { 2, 3 }), new ArrayBasedIndexedInts(new int[] { 3, 3 }), new ArrayBasedIndexedInts(new int[] { 0 }) };
final String[] dict = { null, "abc", "def", "foo" };
final CardinalityVectorAggregator aggregator = new CardinalityVectorAggregator(Collections.singletonList(new MultiValueStringCardinalityVectorProcessor(new MultiValueDimensionVectorSelector() {
@Override
public IndexedInts[] getRowVector() {
return ids;
}
@Override
public int getValueCardinality() {
return dict.length;
}
@Nullable
@Override
public String lookupName(int id) {
return dict[id];
}
@Override
public boolean nameLookupPossibleInAdvance() {
return true;
}
@Nullable
@Override
public IdLookup idLookup() {
return null;
}
@Override
public int getMaxVectorSize() {
return ids.length;
}
@Override
public int getCurrentVectorSize() {
return ids.length;
}
})));
testAggregate(aggregator, ids.length, NullHandling.replaceWithDefault() ? 4 : 3);
}
Aggregations