use of org.apache.druid.segment.vector.VectorCursor in project druid by druid-io.
the class ToObjectVectorColumnProcessorFactoryTest method readColumn.
private List<Object> readColumn(final String column, final int limit) {
try (final VectorCursor cursor = makeCursor()) {
final Supplier<Object[]> supplier = ColumnProcessors.makeVectorProcessor(column, ToObjectVectorColumnProcessorFactory.INSTANCE, cursor.getColumnSelectorFactory());
final List<Object> retVal = new ArrayList<>();
while (!cursor.isDone()) {
final Object[] objects = supplier.get();
for (int i = 0; i < cursor.getCurrentVectorSize(); i++) {
retVal.add(objects[i]);
if (retVal.size() >= limit) {
return retVal;
}
}
cursor.advance();
}
return retVal;
}
}
use of org.apache.druid.segment.vector.VectorCursor in project druid by druid-io.
the class ExpressionVectorSelectorBenchmark method scan.
@Benchmark
@BenchmarkMode(Mode.AverageTime)
@OutputTimeUnit(TimeUnit.MILLISECONDS)
public void scan(Blackhole blackhole) {
final VirtualColumns virtualColumns = VirtualColumns.create(ImmutableList.of(new ExpressionVirtualColumn("v", expression, ExpressionType.toColumnType(outputType), TestExprMacroTable.INSTANCE)));
if (vectorize) {
VectorCursor cursor = new QueryableIndexStorageAdapter(index).makeVectorCursor(null, index.getDataInterval(), virtualColumns, false, 512, null);
if (outputType.isNumeric()) {
VectorValueSelector selector = cursor.getColumnSelectorFactory().makeValueSelector("v");
if (outputType.is(ExprType.DOUBLE)) {
while (!cursor.isDone()) {
blackhole.consume(selector.getDoubleVector());
blackhole.consume(selector.getNullVector());
cursor.advance();
}
} else {
while (!cursor.isDone()) {
blackhole.consume(selector.getLongVector());
blackhole.consume(selector.getNullVector());
cursor.advance();
}
}
closer.register(cursor);
}
} else {
Sequence<Cursor> cursors = new QueryableIndexStorageAdapter(index).makeCursors(null, index.getDataInterval(), virtualColumns, Granularities.ALL, false, null);
int rowCount = cursors.map(cursor -> {
final ColumnValueSelector selector = cursor.getColumnSelectorFactory().makeColumnValueSelector("v");
int rows = 0;
while (!cursor.isDone()) {
blackhole.consume(selector.getObject());
rows++;
cursor.advance();
}
return rows;
}).accumulate(0, (acc, in) -> acc + in);
blackhole.consume(rowCount);
}
}
use of org.apache.druid.segment.vector.VectorCursor in project druid by druid-io.
the class BaseFilterTest method selectColumnValuesMatchingFilterUsingVectorizedPostFiltering.
private List<String> selectColumnValuesMatchingFilterUsingVectorizedPostFiltering(final DimFilter filter, final String selectColumn) {
final Filter theFilter = makeFilter(filter);
final Filter postFilteringFilter = new Filter() {
@Override
public <T> T getBitmapResult(BitmapIndexSelector selector, BitmapResultFactory<T> bitmapResultFactory) {
throw new UnsupportedOperationException();
}
@Override
public ValueMatcher makeMatcher(ColumnSelectorFactory factory) {
return theFilter.makeMatcher(factory);
}
@Override
public boolean supportsBitmapIndex(BitmapIndexSelector selector) {
return false;
}
@Override
public boolean shouldUseBitmapIndex(BitmapIndexSelector selector) {
return false;
}
@Override
public VectorValueMatcher makeVectorMatcher(VectorColumnSelectorFactory factory) {
return theFilter.makeVectorMatcher(factory);
}
@Override
public boolean canVectorizeMatcher(ColumnInspector inspector) {
return theFilter.canVectorizeMatcher(inspector);
}
@Override
public Set<String> getRequiredColumns() {
return null;
}
@Override
public boolean supportsSelectivityEstimation(ColumnSelector columnSelector, BitmapIndexSelector indexSelector) {
return false;
}
@Override
public double estimateSelectivity(BitmapIndexSelector indexSelector) {
return 1.0;
}
};
try (final VectorCursor cursor = makeVectorCursor(postFilteringFilter)) {
final SingleValueDimensionVectorSelector selector = cursor.getColumnSelectorFactory().makeSingleValueDimensionSelector(new DefaultDimensionSpec(selectColumn, selectColumn));
final List<String> values = new ArrayList<>();
while (!cursor.isDone()) {
final int[] rowVector = selector.getRowVector();
for (int i = 0; i < cursor.getCurrentVectorSize(); i++) {
values.add(selector.lookupName(rowVector[i]));
}
cursor.advance();
}
return values;
}
}
use of org.apache.druid.segment.vector.VectorCursor in project druid by druid-io.
the class BaseFilterTest method selectColumnValuesMatchingFilterUsingVectorVirtualColumnCursor.
private List<String> selectColumnValuesMatchingFilterUsingVectorVirtualColumnCursor(final DimFilter filter, final String virtualColumn, final String selectColumn) {
final Expr parsedIdentifier = Parser.parse(selectColumn, TestExprMacroTable.INSTANCE);
try (final VectorCursor cursor = makeVectorCursor(makeFilter(filter))) {
final ExpressionType outputType = parsedIdentifier.getOutputType(cursor.getColumnSelectorFactory());
final List<String> values = new ArrayList<>();
if (outputType.is(ExprType.STRING)) {
final VectorObjectSelector objectSelector = cursor.getColumnSelectorFactory().makeObjectSelector(virtualColumn);
while (!cursor.isDone()) {
final Object[] rowVector = objectSelector.getObjectVector();
for (int i = 0; i < cursor.getCurrentVectorSize(); i++) {
values.add((String) rowVector[i]);
}
cursor.advance();
}
} else {
final VectorValueSelector valueSelector = cursor.getColumnSelectorFactory().makeValueSelector(virtualColumn);
while (!cursor.isDone()) {
final boolean[] nulls = valueSelector.getNullVector();
if (outputType.is(ExprType.DOUBLE)) {
final double[] doubles = valueSelector.getDoubleVector();
for (int i = 0; i < cursor.getCurrentVectorSize(); i++) {
if (nulls != null && nulls[i]) {
values.add(null);
} else {
values.add(String.valueOf(doubles[i]));
}
}
} else {
final long[] longs = valueSelector.getLongVector();
for (int i = 0; i < cursor.getCurrentVectorSize(); i++) {
if (nulls != null && nulls[i]) {
values.add(null);
} else {
values.add(String.valueOf(longs[i]));
}
}
}
cursor.advance();
}
}
return values;
}
}
use of org.apache.druid.segment.vector.VectorCursor in project druid by druid-io.
the class BaseFilterTest method selectColumnValuesMatchingFilterUsingVectorCursor.
private List<String> selectColumnValuesMatchingFilterUsingVectorCursor(final DimFilter filter, final String selectColumn) {
try (final VectorCursor cursor = makeVectorCursor(makeFilter(filter))) {
final SingleValueDimensionVectorSelector selector = cursor.getColumnSelectorFactory().makeSingleValueDimensionSelector(new DefaultDimensionSpec(selectColumn, selectColumn));
final List<String> values = new ArrayList<>();
while (!cursor.isDone()) {
final int[] rowVector = selector.getRowVector();
for (int i = 0; i < cursor.getCurrentVectorSize(); i++) {
values.add(selector.lookupName(rowVector[i]));
}
cursor.advance();
}
return values;
}
}
Aggregations