use of org.apache.druid.segment.vector.VectorValueSelector in project druid by druid-io.
the class NumericNullColumnSelectorTest method testFloatSelectorWithNullsCanResetOffset.
@Test
public void testFloatSelectorWithNullsCanResetOffset() {
for (ImmutableBitmap bitmap : bitmaps) {
ColumnarFloats floats = new ColumnarFloats() {
@Override
public int size() {
return numRows;
}
@Override
public float get(int index) {
return ThreadLocalRandom.current().nextFloat();
}
@Override
public void close() {
}
};
FloatsColumn columnWithNulls = FloatsColumn.create(floats, bitmap);
ColumnValueSelector<?> selector = columnWithNulls.makeColumnValueSelector(offset);
assertOffsetCanReset(selector, bitmap, offset);
VectorValueSelector vectorSelector = columnWithNulls.makeVectorValueSelector(vectorOffset);
assertVectorOffsetCanReset(vectorSelector, bitmap, vectorOffset);
VectorValueSelector anotherSelector = columnWithNulls.makeVectorValueSelector(anotherVectorOffset);
assertVectorChillWhenOffsetsOverlap(anotherSelector, bitmap, anotherVectorOffset);
}
}
use of org.apache.druid.segment.vector.VectorValueSelector in project druid by druid-io.
the class NumericNullColumnSelectorTest method testDoubleSelectorWithNullsCanResetOffset.
@Test
public void testDoubleSelectorWithNullsCanResetOffset() {
for (ImmutableBitmap bitmap : bitmaps) {
ColumnarDoubles doubles = new ColumnarDoubles() {
@Override
public int size() {
return numRows;
}
@Override
public double get(int index) {
return ThreadLocalRandom.current().nextDouble();
}
@Override
public void close() {
}
};
DoublesColumn columnWithNulls = DoublesColumn.create(doubles, 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 VectorCursorGranularizer method create.
@Nullable
public static VectorCursorGranularizer create(final StorageAdapter storageAdapter, final VectorCursor cursor, final Granularity granularity, final Interval queryInterval) {
final DateTime minTime = storageAdapter.getMinTime();
final DateTime maxTime = storageAdapter.getMaxTime();
final Interval storageAdapterInterval = new Interval(minTime, granularity.bucketEnd(maxTime));
final Interval clippedQueryInterval = queryInterval.overlap(storageAdapterInterval);
if (clippedQueryInterval == null) {
return null;
}
final Iterable<Interval> bucketIterable = granularity.getIterable(clippedQueryInterval);
final Interval firstBucket = granularity.bucket(clippedQueryInterval.getStart());
final VectorValueSelector timeSelector;
if (firstBucket.contains(clippedQueryInterval)) {
// Only one bucket, no need to read the time column.
assert Iterables.size(bucketIterable) == 1;
timeSelector = null;
} else {
// Multiple buckets, need to read the time column to know when we move from one to the next.
timeSelector = cursor.getColumnSelectorFactory().makeValueSelector(ColumnHolder.TIME_COLUMN_NAME);
}
return new VectorCursorGranularizer(cursor, bucketIterable, timeSelector);
}
use of org.apache.druid.segment.vector.VectorValueSelector in project druid by druid-io.
the class DoubleMinAggregationTest method testDoubleMinVectorAggregator.
@Test
public void testDoubleMinVectorAggregator() {
// Some sanity.
Assert.assertTrue(doubleMinVectorAggFactory.canVectorize(vectorColumnSelectorFactory));
VectorValueSelector vectorValueSelector = doubleMinVectorAggFactory.vectorSelector(vectorColumnSelectorFactory);
Assert.assertEquals(doubleValues1, vectorValueSelector.getDoubleVector());
VectorAggregator vectorAggregator = doubleMinVectorAggFactory.factorizeVector(vectorColumnSelectorFactory);
final ByteBuffer buf = ByteBuffer.allocate(doubleMinVectorAggFactory.getMaxIntermediateSizeWithNulls() * 3);
vectorAggregator.init(buf, 0);
vectorAggregator.aggregate(buf, 0, 0, 3);
Assert.assertEquals(doubleValues1[1], vectorAggregator.get(buf, 0));
vectorAggregator.init(buf, 8);
vectorAggregator.aggregate(buf, 8, 0, 3);
Assert.assertEquals(doubleValues1[1], vectorAggregator.get(buf, 8));
vectorAggregator.init(buf, 16);
vectorAggregator.aggregate(buf, 16, 3, 7);
Assert.assertEquals(doubleValues1[6], vectorAggregator.get(buf, 16));
vectorAggregator.init(buf, 0);
vectorAggregator.aggregate(buf, 0, 0, 10);
Assert.assertEquals(doubleValues1[7], vectorAggregator.get(buf, 0));
}
use of org.apache.druid.segment.vector.VectorValueSelector in project druid by druid-io.
the class LongMinAggregationTest method testLongMinVectorAggregator.
@Test
public void testLongMinVectorAggregator() {
// Some sanity.
Assert.assertTrue(longMinVectorAggFactory.canVectorize(vectorColumnSelectorFactory));
VectorValueSelector vectorValueSelector = longMinVectorAggFactory.vectorSelector(vectorColumnSelectorFactory);
Assert.assertEquals(longValues1, vectorValueSelector.getLongVector());
VectorAggregator vectorAggregator = longMinVectorAggFactory.factorizeVector(vectorColumnSelectorFactory);
final ByteBuffer buf = ByteBuffer.allocate(longMinAggFactory.getMaxIntermediateSizeWithNulls() * 2);
vectorAggregator.init(buf, 0);
vectorAggregator.aggregate(buf, 0, 0, 3);
Assert.assertEquals(longValues1[1], (long) vectorAggregator.get(buf, 0));
vectorAggregator.aggregate(buf, 1, 0, 3);
Assert.assertEquals(longValues1[1], (long) vectorAggregator.get(buf, 1));
vectorAggregator.aggregate(buf, 2, 3, 7);
Assert.assertEquals(longValues1[6], (long) vectorAggregator.get(buf, 2));
vectorAggregator.aggregate(buf, 0, 0, 10);
Assert.assertEquals(longValues1[7], (long) vectorAggregator.get(buf, 0));
}
Aggregations