use of io.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();
int[] result = new int[baseRowSize];
int resultSize = 0;
for (int i = 0; i < baseRowSize; i++) {
if (predicate.apply(selector.lookupName(baseRow.get(i)))) {
result[resultSize++] = i;
}
}
return ArrayBasedIndexedInts.of(result, resultSize);
}
use of io.druid.segment.data.IndexedInts 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;
}
};
}
use of io.druid.segment.data.IndexedInts in project druid by druid-io.
the class StringCardinalityAggregatorColumnSelectorStrategy method hashRow.
@Override
public void hashRow(DimensionSelector dimSelector, Hasher hasher) {
final IndexedInts row = dimSelector.getRow();
final int size = row.size();
// nothing to add to hasher if size == 0, only handle size == 1 and size != 0 cases.
if (size == 1) {
final String value = dimSelector.lookupName(row.get(0));
hasher.putUnencodedChars(nullToSpecial(value));
} else if (size != 0) {
final String[] values = new String[size];
for (int i = 0; i < size; ++i) {
final String value = dimSelector.lookupName(row.get(i));
values[i] = nullToSpecial(value);
}
// Values need to be sorted to ensure consistent multi-value ordering across different segments
Arrays.sort(values);
for (int i = 0; i < size; ++i) {
if (i != 0) {
hasher.putChar(CARDINALITY_AGG_SEPARATOR);
}
hasher.putUnencodedChars(values[i]);
}
}
}
use of io.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 ImmutableBitmap getBitmapIndex(BitmapIndexSelector selector) {
throw new UnsupportedOperationException();
}
@Override
public ValueMatcher makeMatcher(ColumnSelectorFactory factory) {
return theFilter.makeMatcher(factory);
}
@Override
public boolean supportsBitmapIndex(BitmapIndexSelector selector) {
return false;
}
@Override
public boolean supportsSelectivityEstimation(ColumnSelector columnSelector, BitmapIndexSelector indexSelector) {
return false;
}
@Override
public double estimateSelectivity(BitmapIndexSelector indexSelector) {
return 1.0;
}
};
final Sequence<Cursor> cursors = makeCursorSequence(postFilteringFilter);
Sequence<List<String>> seq = Sequences.map(cursors, new Function<Cursor, List<String>>() {
@Override
public List<String> apply(Cursor input) {
final DimensionSelector selector = input.makeDimensionSelector(new DefaultDimensionSpec(selectColumn, selectColumn));
final List<String> values = Lists.newArrayList();
while (!input.isDone()) {
IndexedInts row = selector.getRow();
Preconditions.checkState(row.size() == 1);
values.add(selector.lookupName(row.get(0)));
input.advance();
}
return values;
}
});
return Sequences.toList(seq, new ArrayList<List<String>>()).get(0);
}
use of io.druid.segment.data.IndexedInts in project druid by druid-io.
the class MapVirtualColumn method makeObjectColumnSelector.
@Override
public ObjectColumnSelector makeObjectColumnSelector(String dimension, ColumnSelectorFactory factory) {
final DimensionSelector keySelector = factory.makeDimensionSelector(DefaultDimensionSpec.of(keyDimension));
final DimensionSelector valueSelector = factory.makeDimensionSelector(DefaultDimensionSpec.of(valueDimension));
final String subColumnName = VirtualColumns.splitColumnName(dimension).rhs;
if (subColumnName == null) {
return new ObjectColumnSelector<Map>() {
@Override
public Class classOfObject() {
return Map.class;
}
@Override
public Map get() {
final IndexedInts keyIndices = keySelector.getRow();
final IndexedInts valueIndices = valueSelector.getRow();
if (keyIndices == null || valueIndices == null) {
return null;
}
final int limit = Math.min(keyIndices.size(), valueIndices.size());
final Map<String, String> map = Maps.newHashMapWithExpectedSize(limit);
for (int i = 0; i < limit; i++) {
map.put(keySelector.lookupName(keyIndices.get(i)), valueSelector.lookupName(valueIndices.get(i)));
}
return map;
}
};
}
IdLookup keyIdLookup = keySelector.idLookup();
if (keyIdLookup != null) {
final int keyId = keyIdLookup.lookupId(subColumnName);
if (keyId < 0) {
return NullStringObjectColumnSelector.instance();
}
return new ObjectColumnSelector<String>() {
@Override
public Class classOfObject() {
return String.class;
}
@Override
public String get() {
final IndexedInts keyIndices = keySelector.getRow();
final IndexedInts valueIndices = valueSelector.getRow();
if (keyIndices == null || valueIndices == null) {
return null;
}
final int limit = Math.min(keyIndices.size(), valueIndices.size());
for (int i = 0; i < limit; i++) {
if (keyIndices.get(i) == keyId) {
return valueSelector.lookupName(valueIndices.get(i));
}
}
return null;
}
};
} else {
return new ObjectColumnSelector<String>() {
@Override
public Class classOfObject() {
return String.class;
}
@Override
public String get() {
final IndexedInts keyIndices = keySelector.getRow();
final IndexedInts valueIndices = valueSelector.getRow();
if (keyIndices == null || valueIndices == null) {
return null;
}
final int limit = Math.min(keyIndices.size(), valueIndices.size());
for (int i = 0; i < limit; i++) {
if (Objects.equals(keySelector.lookupName(keyIndices.get(i)), subColumnName)) {
return valueSelector.lookupName(valueIndices.get(i));
}
}
return null;
}
};
}
}
Aggregations