use of org.apache.druid.query.filter.ValueMatcher in project druid by druid-io.
the class PredicateValueMatcherFactoryTest method testComplexProcessorMatchingStringList.
@Test
public void testComplexProcessorMatchingStringList() {
final TestColumnValueSelector<String> columnValueSelector = TestColumnValueSelector.of(String.class, ImmutableList.of(ImmutableList.of("val")), DateTimes.nowUtc());
columnValueSelector.advance();
final ValueMatcher matcher = forSelector("val").makeComplexProcessor(columnValueSelector);
Assert.assertTrue(matcher.matches());
}
use of org.apache.druid.query.filter.ValueMatcher in project druid by druid-io.
the class ForwardingFilteredDimensionSelector method makeValueMatcher.
@Override
public ValueMatcher makeValueMatcher(Predicate<String> predicate) {
final BitSet valueIds = DimensionSelectorUtils.makePredicateMatchingSet(this, predicate);
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) {
int forwardedValue = idMapping.getForwardedId(baseRow.get(i));
if (forwardedValue >= 0) {
if (valueIds.get(forwardedValue)) {
return true;
}
nullRow = false;
}
}
// null should match empty rows in multi-value columns
return nullRow && matchNull;
}
@Override
public void inspectRuntimeShape(RuntimeShapeInspector inspector) {
inspector.visit("selector", selector);
}
};
}
use of org.apache.druid.query.filter.ValueMatcher in project druid by druid-io.
the class PredicateFilteredDimensionSelector method makeValueMatcher.
@Override
public ValueMatcher makeValueMatcher(final String value) {
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 (Objects.equals(rowValue, value)) {
return true;
}
nullRow = false;
}
}
// null should match empty rows in multi-value columns
return nullRow && value == null;
}
@Override
public void inspectRuntimeShape(RuntimeShapeInspector inspector) {
// PredicateFilteredDimensionSelector.this inspects selector and predicate as well.
inspector.visit("selector", PredicateFilteredDimensionSelector.this);
}
};
}
use of org.apache.druid.query.filter.ValueMatcher in project druid by druid-io.
the class DimensionSelectorUtils method makeNonDictionaryEncodedValueMatcherGeneric.
private static ValueMatcher makeNonDictionaryEncodedValueMatcherGeneric(final DimensionSelector selector, @Nullable final String value) {
return new ValueMatcher() {
@Override
public boolean matches() {
final IndexedInts row = selector.getRow();
final int size = row.size();
if (size == 0) {
// null should match empty rows in multi-value columns
return value == null;
} else {
for (int i = 0; i < size; ++i) {
if (Objects.equals(selector.lookupName(row.get(i)), value)) {
return true;
}
}
return false;
}
}
@Override
public void inspectRuntimeShape(RuntimeShapeInspector inspector) {
inspector.visit("selector", selector);
}
};
}
use of org.apache.druid.query.filter.ValueMatcher in project druid by druid-io.
the class DimensionSelectorUtils method makeDictionaryEncodedValueMatcherGeneric.
private static ValueMatcher makeDictionaryEncodedValueMatcherGeneric(final DimensionSelector selector, Predicate<String> predicate) {
final BitSet checkedIds = new BitSet(selector.getValueCardinality());
final BitSet matchingIds = new BitSet(selector.getValueCardinality());
final boolean matchNull = predicate.apply(null);
// Lazy matcher; only check an id if matches() is called.
return new ValueMatcher() {
@Override
public boolean matches() {
final IndexedInts row = selector.getRow();
final int size = row.size();
if (size == 0) {
// null should match empty rows in multi-value columns
return matchNull;
} else {
for (int i = 0; i < size; ++i) {
final int id = row.get(i);
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) {
return true;
}
}
return false;
}
}
@Override
public void inspectRuntimeShape(RuntimeShapeInspector inspector) {
inspector.visit("selector", selector);
}
};
}
Aggregations