use of org.apache.druid.segment.data.IndexedInts in project druid by druid-io.
the class DictionaryEncodedColumnMerger method processMergedRow.
@Override
public void processMergedRow(ColumnValueSelector selector) throws IOException {
IndexedInts row = getRow(selector);
int rowSize = row.size();
if (rowSize == 0) {
nullRowsBitmap.add(rowCount);
} else if (hasNull && isNullRow(row, rowSize)) {
// If this dimension has the null/empty str in its dictionary, a row with nulls at all positions should also be
// added to nullRowBitmap.
nullRowsBitmap.add(rowCount);
}
if (encodedValueSerializer instanceof ColumnarMultiIntsSerializer) {
((ColumnarMultiIntsSerializer) encodedValueSerializer).addValues(row);
} else {
int value = row.size() == 0 ? 0 : row.get(0);
((SingleValueColumnarIntsSerializer) encodedValueSerializer).addValue(value);
}
rowCount++;
}
use of org.apache.druid.segment.data.IndexedInts in project druid by druid-io.
the class StringTopNColumnAggregatesProcessor method scanAndAggregateWithCardinalityKnown.
private long scanAndAggregateWithCardinalityKnown(TopNQuery query, Cursor cursor, DimensionSelector selector, Aggregator[][] rowSelector) {
long processedRows = 0;
while (!cursor.isDone()) {
final IndexedInts dimValues = selector.getRow();
for (int i = 0, size = dimValues.size(); i < size; ++i) {
final int dimIndex = dimValues.get(i);
Aggregator[] aggs = rowSelector[dimIndex];
if (aggs == null) {
final Comparable<?> key = dimensionValueConverter.apply(selector.lookupName(dimIndex));
aggs = aggregatesStore.computeIfAbsent(key, k -> BaseTopNAlgorithm.makeAggregators(cursor, query.getAggregatorSpecs()));
rowSelector[dimIndex] = aggs;
}
for (Aggregator aggregator : aggs) {
aggregator.aggregate();
}
}
cursor.advance();
processedRows++;
}
return processedRows;
}
use of org.apache.druid.segment.data.IndexedInts 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.segment.data.IndexedInts 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);
}
};
}
use of org.apache.druid.segment.data.IndexedInts in project druid by druid-io.
the class DimensionSelectorUtils method makeNonDictionaryEncodedValueMatcherGeneric.
private static ValueMatcher makeNonDictionaryEncodedValueMatcherGeneric(final DimensionSelector selector, final Predicate<String> 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 (predicate.apply(selector.lookupName(row.get(i)))) {
return true;
}
}
return false;
}
}
@Override
public void inspectRuntimeShape(RuntimeShapeInspector inspector) {
inspector.visit("selector", selector);
inspector.visit("predicate", predicate);
}
};
}
Aggregations