use of org.apache.druid.segment.vector.VectorValueSelector in project druid by druid-io.
the class LongMaxAggregationTest method testLongMaxVectorAggregator.
@Test
public void testLongMaxVectorAggregator() {
// Some sanity.
Assert.assertTrue(longMaxVectorAggFactory.canVectorize(vectorColumnSelectorFactory));
VectorValueSelector vectorValueSelector = longMaxVectorAggFactory.vectorSelector(vectorColumnSelectorFactory);
Assert.assertEquals(longValues1, vectorValueSelector.getLongVector());
VectorAggregator vectorAggregator = longMaxVectorAggFactory.factorizeVector(vectorColumnSelectorFactory);
final ByteBuffer buf = ByteBuffer.allocate(longMaxAggFactory.getMaxIntermediateSizeWithNulls() * 3);
vectorAggregator.init(buf, 0);
vectorAggregator.aggregate(buf, 0, 0, 3);
Assert.assertEquals(longValues1[0], (long) vectorAggregator.get(buf, 0));
vectorAggregator.aggregate(buf, 8, 0, 3);
Assert.assertEquals(longValues1[0], (long) vectorAggregator.get(buf, 8));
vectorAggregator.aggregate(buf, 16, 3, 7);
Assert.assertEquals(longValues1[3], (long) vectorAggregator.get(buf, 16));
vectorAggregator.init(buf, 0);
vectorAggregator.aggregate(buf, 0, 0, 10);
Assert.assertEquals(longValues1[3], (long) vectorAggregator.get(buf, 0));
}
use of org.apache.druid.segment.vector.VectorValueSelector in project druid by druid-io.
the class NumericNullColumnSelectorTest method testLongSelectorWithNullsCanResetOffset.
@Test
public void testLongSelectorWithNullsCanResetOffset() {
for (ImmutableBitmap bitmap : bitmaps) {
ColumnarLongs longs = new ColumnarLongs() {
@Override
public int size() {
return numRows;
}
@Override
public long get(int index) {
return ThreadLocalRandom.current().nextLong();
}
@Override
public void close() {
}
};
LongsColumn columnWithNulls = LongsColumn.create(longs, bitmap);
ColumnValueSelector<?> selector = columnWithNulls.makeColumnValueSelector(offset);
assertOffsetCanReset(selector, bitmap, offset);
VectorValueSelector vectorSelector = columnWithNulls.makeVectorValueSelector(vectorOffset);
assertVectorOffsetCanReset(vectorSelector, bitmap, vectorOffset);
}
}
use of org.apache.druid.segment.vector.VectorValueSelector 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;
}
}
Aggregations