use of org.apache.druid.segment.data.IndexedInts in project druid by druid-io.
the class MultiValueStringVectorValueMatcher method makeMatcher.
@Override
public VectorValueMatcher makeMatcher(@Nullable final String value) {
final String etnValue = NullHandling.emptyToNullIfNeeded(NullHandling.emptyToNullIfNeeded(value));
final IdLookup idLookup = selector.idLookup();
final int id;
if (idLookup != null) {
// Optimization when names can be looked up to IDs ahead of time.
id = idLookup.lookupId(etnValue);
if (id < 0) {
// Value doesn't exist in this column.
return BooleanVectorValueMatcher.of(selector, false);
}
// Check for "id".
return new BaseVectorValueMatcher(selector) {
final VectorMatch match = VectorMatch.wrap(new int[selector.getMaxVectorSize()]);
@Override
public ReadableVectorMatch match(final ReadableVectorMatch mask) {
final IndexedInts[] vector = selector.getRowVector();
final int[] selection = match.getSelection();
int numRows = 0;
for (int i = 0; i < mask.getSelectionSize(); i++) {
final int rowNum = mask.getSelection()[i];
final IndexedInts ints = vector[rowNum];
final int n = ints.size();
if (n == 0) {
// null should match empty rows in multi-value columns
if (etnValue == null) {
selection[numRows++] = rowNum;
}
} else {
for (int j = 0; j < n; j++) {
if (ints.get(j) == id) {
selection[numRows++] = rowNum;
break;
}
}
}
}
match.setSelectionSize(numRows);
assert match.isValid(mask);
return match;
}
};
} else {
return makeMatcher(s -> Objects.equals(s, etnValue));
}
}
use of org.apache.druid.segment.data.IndexedInts 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);
}
use of org.apache.druid.segment.data.IndexedInts in project druid by druid-io.
the class BaseFilterTest method selectColumnValuesMatchingFilterUsingPostFiltering.
private List<String> selectColumnValuesMatchingFilterUsingPostFiltering(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 boolean supportsSelectivityEstimation(ColumnSelector columnSelector, BitmapIndexSelector indexSelector) {
return false;
}
@Override
public Set<String> getRequiredColumns() {
return Collections.emptySet();
}
@Override
public double estimateSelectivity(BitmapIndexSelector indexSelector) {
return 1.0;
}
};
final Sequence<Cursor> cursors = makeCursorSequence(postFilteringFilter);
Sequence<List<String>> seq = Sequences.map(cursors, cursor -> {
final DimensionSelector selector = cursor.getColumnSelectorFactory().makeDimensionSelector(new DefaultDimensionSpec(selectColumn, selectColumn));
final List<String> values = new ArrayList<>();
while (!cursor.isDone()) {
IndexedInts row = selector.getRow();
Preconditions.checkState(row.size() == 1);
values.add(selector.lookupName(row.get(0)));
cursor.advance();
}
return values;
});
return seq.toList().get(0);
}
Aggregations