use of org.apache.druid.segment.data.IndexedInts in project druid by druid-io.
the class ForwardingFilteredDimensionSelector method makeValueMatcher.
@Override
public ValueMatcher makeValueMatcher(final String value) {
IdLookup idLookup = idLookup();
if (idLookup != null) {
final int valueId = idLookup.lookupId(value);
if (valueId >= 0 || value == null) {
return new ValueMatcher() {
@Override
public boolean matches() {
final IndexedInts baseRow = selector.getRow();
final int baseRowSize = baseRow.size();
boolean nullRow = true;
for (int i = 0; i < baseRowSize; i++) {
int forwardedValue = idMapping.getForwardedId(baseRow.get(i));
if (forwardedValue >= 0) {
// valueId is -1, we don't want to return true from matches().
if (forwardedValue == valueId) {
return true;
}
nullRow = false;
}
}
// null should match empty rows in multi-value columns
return nullRow && value == null;
}
@Override
public void inspectRuntimeShape(RuntimeShapeInspector inspector) {
inspector.visit("selector", selector);
}
};
} else {
return BooleanValueMatcher.of(false);
}
} else {
// Employ precomputed BitSet optimization
return makeValueMatcher(Predicates.equalTo(value));
}
}
use of org.apache.druid.segment.data.IndexedInts in project druid by druid-io.
the class ForwardingFilteredDimensionSelector method getRow.
@Override
public IndexedInts getRow() {
IndexedInts baseRow = selector.getRow();
int baseRowSize = baseRow.size();
row.ensureSize(baseRowSize);
int resultSize = 0;
for (int i = 0; i < baseRowSize; i++) {
int forwardedValue = idMapping.getForwardedId(baseRow.get(i));
if (forwardedValue >= 0) {
row.setValue(resultSize, forwardedValue);
resultSize++;
}
}
row.setSize(resultSize);
return row;
}
use of org.apache.druid.segment.data.IndexedInts in project druid by druid-io.
the class PredicateFilteredDimensionSelector method makeValueMatcher.
@Override
public ValueMatcher makeValueMatcher(final Predicate<String> matcherPredicate) {
final boolean matchNull = predicate.apply(null);
return new ValueMatcher() {
@Override
public boolean matches() {
final IndexedInts baseRow = selector.getRow();
final int baseRowSize = baseRow.size();
boolean nullRow = true;
for (int i = 0; i < baseRowSize; ++i) {
String rowValue = lookupName(baseRow.get(i));
if (predicate.apply(rowValue)) {
if (matcherPredicate.apply(rowValue)) {
return true;
}
nullRow = false;
}
}
// null should match empty rows in multi-value columns
return nullRow && matchNull;
}
@Override
public void inspectRuntimeShape(RuntimeShapeInspector inspector) {
// PredicateFilteredDimensionSelector.this inspects selector and predicate as well.
inspector.visit("selector", PredicateFilteredDimensionSelector.this);
inspector.visit("matcherPredicate", matcherPredicate);
}
};
}
use of org.apache.druid.segment.data.IndexedInts in project druid by druid-io.
the class PredicateFilteredDimensionSelector method getRow.
@Override
public IndexedInts getRow() {
IndexedInts baseRow = selector.getRow();
int baseRowSize = baseRow.size();
row.ensureSize(baseRowSize);
int resultSize = 0;
for (int i = 0; i < baseRowSize; i++) {
int id = baseRow.get(i);
if (predicate.apply(selector.lookupName(id))) {
row.setValue(resultSize, id);
resultSize++;
}
}
row.setSize(resultSize);
return row;
}
use of org.apache.druid.segment.data.IndexedInts in project druid by druid-io.
the class MultiValueStringVectorValueMatcher method makeMatcher.
private VectorValueMatcher makeMatcher(final Predicate<String> predicate) {
final boolean matchNull = predicate.apply(null);
if (selector.getValueCardinality() > 0) {
final BitSet checkedIds = new BitSet(selector.getValueCardinality());
final BitSet matchingIds = new BitSet(selector.getValueCardinality());
// Lazy matcher; only check an id if matches() is called.
return new BaseVectorValueMatcher(selector) {
private 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 (matchNull) {
selection[numRows++] = rowNum;
}
} else {
for (int j = 0; j < n; j++) {
final int id = ints.get(j);
final boolean matches;
if (checkedIds.get(id)) {
matches = matchingIds.get(id);
} else {
matches = predicate.apply(selector.lookupName(id));
checkedIds.set(id);
if (matches) {
matchingIds.set(id);
}
}
if (matches) {
selection[numRows++] = rowNum;
break;
}
}
}
}
match.setSelectionSize(numRows);
assert match.isValid(mask);
return match;
}
};
} else {
// Evaluate "lookupName" and "predicate" on every row.
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 (matchNull) {
selection[numRows++] = rowNum;
}
} else {
for (int j = 0; j < n; j++) {
final int id = ints.get(j);
if (predicate.apply(selector.lookupName(id))) {
selection[numRows++] = rowNum;
break;
}
}
}
}
match.setSelectionSize(numRows);
assert match.isValid(mask);
return match;
}
};
}
}
Aggregations