use of com.facebook.presto.spi.block.BlockBuilder in project presto by prestodb.
the class AggregationTestUtils method getFinalBlock.
public static Block getFinalBlock(Accumulator accumulator) {
BlockBuilder blockBuilder = accumulator.getFinalType().createBlockBuilder(new BlockBuilderStatus(), 1000);
accumulator.evaluateFinal(blockBuilder);
return blockBuilder.build();
}
use of com.facebook.presto.spi.block.BlockBuilder in project presto by prestodb.
the class TestApproximatePercentileAggregation method createRLEBlock.
private static RunLengthEncodedBlock createRLEBlock(Iterable<Double> percentiles, int positionCount) {
BlockBuilder rleBlockBuilder = new ArrayType(DOUBLE).createBlockBuilder(new BlockBuilderStatus(), 1);
BlockBuilder arrayBlockBuilder = rleBlockBuilder.beginBlockEntry();
for (double percentile : percentiles) {
DOUBLE.writeDouble(arrayBlockBuilder, percentile);
}
rleBlockBuilder.closeEntry();
return new RunLengthEncodedBlock(rleBlockBuilder.build(), positionCount);
}
use of com.facebook.presto.spi.block.BlockBuilder in project presto by prestodb.
the class BenchmarkArraySort method oldArraySort.
@ScalarFunction
@SqlType("array(varchar)")
public static Block oldArraySort(@SqlType("array(varchar)") Block block) {
List<Integer> positions = Ints.asList(new int[block.getPositionCount()]);
for (int i = 0; i < block.getPositionCount(); i++) {
positions.set(i, i);
}
Collections.sort(positions, new Comparator<Integer>() {
@Override
public int compare(Integer p1, Integer p2) {
//TODO: This could be quite slow, it should use parametric equals
return VARCHAR.compareTo(block, p1, block, p2);
}
});
BlockBuilder blockBuilder = VARCHAR.createBlockBuilder(new BlockBuilderStatus(), block.getPositionCount());
for (int position : positions) {
VARCHAR.appendTo(block, position, blockBuilder);
}
return blockBuilder.build();
}
use of com.facebook.presto.spi.block.BlockBuilder in project presto by prestodb.
the class BenchmarkArrayDistinct method oldArrayDistinct.
@ScalarFunction
@SqlType("array(varchar)")
public static Block oldArrayDistinct(@SqlType("array(varchar)") Block array) {
if (array.getPositionCount() == 0) {
return array;
}
TypedSet typedSet = new TypedSet(VARCHAR, array.getPositionCount());
BlockBuilder distinctElementBlockBuilder = VARCHAR.createBlockBuilder(new BlockBuilderStatus(), array.getPositionCount());
for (int i = 0; i < array.getPositionCount(); i++) {
if (!typedSet.contains(array, i)) {
typedSet.add(array, i);
VARCHAR.appendTo(array, i, distinctElementBlockBuilder);
}
}
return distinctElementBlockBuilder.build();
}
use of com.facebook.presto.spi.block.BlockBuilder in project presto by prestodb.
the class TestTypedHistogram method testMassive.
@Test
public void testMassive() throws Exception {
BlockBuilder inputBlockBuilder = BIGINT.createBlockBuilder(new BlockBuilderStatus(), 5000);
TypedHistogram typedHistogram = new TypedHistogram(BIGINT, 1000);
IntStream.range(1, 2000).flatMap(i -> IntStream.iterate(i, IntUnaryOperator.identity()).limit(i)).forEach(j -> BIGINT.writeLong(inputBlockBuilder, j));
Block inputBlock = inputBlockBuilder.build();
for (int i = 0; i < inputBlock.getPositionCount(); i++) {
typedHistogram.add(i, inputBlock, 1);
}
Block outputBlock = typedHistogram.serialize();
for (int i = 0; i < outputBlock.getPositionCount(); i += 2) {
assertEquals(BIGINT.getLong(outputBlock, i + 1), BIGINT.getLong(outputBlock, i));
}
}
Aggregations