use of org.apache.druid.segment.data.IndexedInts in project druid by druid-io.
the class FilterPartitionBenchmark method readCursors.
private void readCursors(Sequence<Cursor> cursors, Blackhole blackhole) {
final Sequence<Void> voids = Sequences.map(cursors, input -> {
List<DimensionSelector> selectors = new ArrayList<>();
selectors.add(input.getColumnSelectorFactory().makeDimensionSelector(new DefaultDimensionSpec("dimSequential", null)));
while (!input.isDone()) {
for (DimensionSelector selector : selectors) {
IndexedInts row = selector.getRow();
blackhole.consume(selector.lookupName(row.get(0)));
}
input.advance();
}
return null;
});
blackhole.consume(voids.toList());
}
use of org.apache.druid.segment.data.IndexedInts in project druid by druid-io.
the class ArrayOfDoublesSketchBuildAggregator method aggregate.
/**
* This method uses synchronization because it can be used during indexing,
* and Druid can call aggregate() and get() concurrently
* https://github.com/apache/druid/pull/3956
*/
@Override
public void aggregate() {
final IndexedInts keys = keySelector.getRow();
for (int i = 0; i < valueSelectors.length; i++) {
if (valueSelectors[i].isNull()) {
return;
} else {
values[i] = valueSelectors[i].getDouble();
}
}
synchronized (this) {
if (canLookupUtf8) {
for (int i = 0, keysSize = keys.size(); i < keysSize; i++) {
final ByteBuffer key;
if (canCacheById) {
key = (ByteBuffer) stringCache.computeIfAbsent(keys.get(i), keySelector::lookupNameUtf8);
} else {
key = keySelector.lookupNameUtf8(keys.get(i));
}
if (key != null) {
byte[] bytes = new byte[key.remaining()];
key.mark();
key.get(bytes);
key.reset();
sketch.update(bytes, values);
}
}
} else {
for (int i = 0, keysSize = keys.size(); i < keysSize; i++) {
final String key;
if (canCacheById) {
key = (String) stringCache.computeIfAbsent(keys.get(i), keySelector::lookupName);
} else {
key = keySelector.lookupName(keys.get(i));
}
sketch.update(key, values);
}
}
}
}
use of org.apache.druid.segment.data.IndexedInts in project druid by druid-io.
the class MapVirtualColumn method makeColumnValueSelector.
@Override
public ColumnValueSelector<?> makeColumnValueSelector(String columnName, ColumnSelectorFactory factory) {
final DimensionSelector keySelector = factory.makeDimensionSelector(DefaultDimensionSpec.of(keyDimension));
final DimensionSelector valueSelector = factory.makeDimensionSelector(DefaultDimensionSpec.of(valueDimension));
final String subColumnName = VirtualColumns.splitColumnName(columnName).rhs;
if (subColumnName == null) {
return new MapVirtualColumnValueSelector<Map>(keySelector, valueSelector) {
@Override
public Class<Map> classOfObject() {
return Map.class;
}
@Override
public Map getObject() {
final IndexedInts keyIndices = keySelector.getRow();
final IndexedInts valueIndices = valueSelector.getRow();
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 NilColumnValueSelector.instance();
}
return new MapVirtualColumnValueSelector<String>(keySelector, valueSelector) {
@Override
public Class<String> classOfObject() {
return String.class;
}
@Nullable
@Override
public String getObject() {
final IndexedInts keyIndices = keySelector.getRow();
final IndexedInts valueIndices = valueSelector.getRow();
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 MapVirtualColumnValueSelector<String>(keySelector, valueSelector) {
@Override
public Class<String> classOfObject() {
return String.class;
}
@Nullable
@Override
public String getObject() {
final IndexedInts keyIndices = keySelector.getRow();
final IndexedInts valueIndices = valueSelector.getRow();
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;
}
};
}
}
use of org.apache.druid.segment.data.IndexedInts in project druid by druid-io.
the class StringTypeMapVirtualColumnDimensionSelector method findValueIndicesIndexForSubColumn.
/**
* Find the index of valueIndices which is {@link IndexedInts} returned from {@link #getValueSelector()#getRow()}
* corresponding to the {@link #subColumnName}.
*
* @return index for valueIndices if found. -1 otherwise.
*/
private int findValueIndicesIndexForSubColumn() {
final DimensionSelector keySelector = getKeySelector();
final DimensionSelector valueSelector = getValueSelector();
final IndexedInts keyIndices = keySelector.getRow();
final IndexedInts valueIndices = valueSelector.getRow();
final int limit = Math.min(keyIndices.size(), valueIndices.size());
return IntStream.range(0, limit).filter(// subColumnName is never null
i -> subColumnName.equals(keySelector.lookupName(keyIndices.get(i)))).findAny().orElse(-1);
}
use of org.apache.druid.segment.data.IndexedInts in project druid by druid-io.
the class StringTypeMapVirtualColumnDimensionSelector method getObject.
@Nullable
@Override
public Object getObject() {
final int valueIndex = findValueIndicesIndexForSubColumn();
if (valueIndex < 0) {
return null;
} else {
final DimensionSelector valueSelector = getValueSelector();
final IndexedInts valueIndices = valueSelector.getRow();
return valueSelector.lookupName(valueIndices.get(valueIndex));
}
}
Aggregations