use of io.druid.query.filter.ValueMatcher in project druid by druid-io.
the class DimensionSelectorUtils method makeDictionaryEncodedValueMatcherGeneric.
private static ValueMatcher makeDictionaryEncodedValueMatcherGeneric(final DimensionSelector selector, final int valueId, final boolean matchNull) {
if (valueId >= 0) {
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) {
if (row.get(i) == valueId) {
return true;
}
}
return false;
}
}
};
} else {
if (matchNull) {
return new ValueMatcher() {
@Override
public boolean matches() {
final IndexedInts row = selector.getRow();
final int size = row.size();
return size == 0;
}
};
} else {
return BooleanValueMatcher.of(false);
}
}
}
use of io.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 predicateMatchingValueIds = makePredicateMatchingSet(selector, predicate);
final boolean matchNull = predicate.apply(null);
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) {
if (predicateMatchingValueIds.get(row.get(i))) {
return true;
}
}
return false;
}
}
};
}
use of io.druid.query.filter.ValueMatcher in project druid by druid-io.
the class DimensionSelectorUtils method makeNonDictionaryEncodedValueMatcherGeneric.
private static ValueMatcher makeNonDictionaryEncodedValueMatcherGeneric(final DimensionSelector selector, 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;
}
}
};
}
use of io.druid.query.filter.ValueMatcher in project druid by druid-io.
the class RowBasedColumnSelectorFactory method makeDimensionSelectorUndecorated.
private DimensionSelector makeDimensionSelectorUndecorated(DimensionSpec dimensionSpec) {
final String dimension = dimensionSpec.getDimension();
final ExtractionFn extractionFn = dimensionSpec.getExtractionFn();
if (Column.TIME_COLUMN_NAME.equals(dimensionSpec.getDimension())) {
if (extractionFn == null) {
throw new UnsupportedOperationException("time dimension must provide an extraction function");
}
return new DimensionSelector() {
@Override
public IndexedInts getRow() {
return ZeroIndexedInts.instance();
}
@Override
public ValueMatcher makeValueMatcher(final String value) {
return new ValueMatcher() {
@Override
public boolean matches() {
String rowValue = extractionFn.apply(row.get().getTimestampFromEpoch());
return Objects.equals(rowValue, value);
}
};
}
@Override
public ValueMatcher makeValueMatcher(final Predicate<String> predicate) {
return new ValueMatcher() {
@Override
public boolean matches() {
String rowValue = extractionFn.apply(row.get().getTimestampFromEpoch());
return predicate.apply(rowValue);
}
};
}
@Override
public int getValueCardinality() {
return DimensionSelector.CARDINALITY_UNKNOWN;
}
@Override
public String lookupName(int id) {
return extractionFn.apply(row.get().getTimestampFromEpoch());
}
@Override
public boolean nameLookupPossibleInAdvance() {
return false;
}
@Nullable
@Override
public IdLookup idLookup() {
return null;
}
@Override
public void inspectRuntimeShape(RuntimeShapeInspector inspector) {
inspector.visit("row", row);
inspector.visit("extractionFn", extractionFn);
}
};
} else {
return new DimensionSelector() {
@Override
public IndexedInts getRow() {
final List<String> dimensionValues = row.get().getDimension(dimension);
return RangeIndexedInts.create(dimensionValues != null ? dimensionValues.size() : 0);
}
@Override
public ValueMatcher makeValueMatcher(final String value) {
if (extractionFn == null) {
return new ValueMatcher() {
@Override
public boolean matches() {
final List<String> dimensionValues = row.get().getDimension(dimension);
if (dimensionValues == null || dimensionValues.isEmpty()) {
return value == null;
}
for (String dimensionValue : dimensionValues) {
if (Objects.equals(Strings.emptyToNull(dimensionValue), value)) {
return true;
}
}
return false;
}
};
} else {
return new ValueMatcher() {
@Override
public boolean matches() {
final List<String> dimensionValues = row.get().getDimension(dimension);
if (dimensionValues == null || dimensionValues.isEmpty()) {
return value == null;
}
for (String dimensionValue : dimensionValues) {
if (Objects.equals(extractionFn.apply(Strings.emptyToNull(dimensionValue)), value)) {
return true;
}
}
return false;
}
};
}
}
@Override
public ValueMatcher makeValueMatcher(final Predicate<String> predicate) {
final boolean matchNull = predicate.apply(null);
if (extractionFn == null) {
return new ValueMatcher() {
@Override
public boolean matches() {
final List<String> dimensionValues = row.get().getDimension(dimension);
if (dimensionValues == null || dimensionValues.isEmpty()) {
return matchNull;
}
for (String dimensionValue : dimensionValues) {
if (predicate.apply(Strings.emptyToNull(dimensionValue))) {
return true;
}
}
return false;
}
};
} else {
return new ValueMatcher() {
@Override
public boolean matches() {
final List<String> dimensionValues = row.get().getDimension(dimension);
if (dimensionValues == null || dimensionValues.isEmpty()) {
return matchNull;
}
for (String dimensionValue : dimensionValues) {
if (predicate.apply(extractionFn.apply(Strings.emptyToNull(dimensionValue)))) {
return true;
}
}
return false;
}
};
}
}
@Override
public int getValueCardinality() {
return DimensionSelector.CARDINALITY_UNKNOWN;
}
@Override
public String lookupName(int id) {
final String value = Strings.emptyToNull(row.get().getDimension(dimension).get(id));
return extractionFn == null ? value : extractionFn.apply(value);
}
@Override
public boolean nameLookupPossibleInAdvance() {
return false;
}
@Nullable
@Override
public IdLookup idLookup() {
return null;
}
@Override
public void inspectRuntimeShape(RuntimeShapeInspector inspector) {
inspector.visit("row", row);
inspector.visit("extractionFn", extractionFn);
}
};
}
}
use of io.druid.query.filter.ValueMatcher 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 = forwardMapping.get(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;
}
};
} else {
return BooleanValueMatcher.of(false);
}
} else {
// Employ precomputed BitSet optimization
return makeValueMatcher(Predicates.equalTo(value));
}
}
Aggregations