use of io.trino.spi.block.BlockBuilder in project trino by trinodb.
the class ArrayConcatUtils method prependElement.
// Usage of prependElement: ElementToArrayConcatFunction
@UsedByGeneratedCode
public static Block prependElement(Type elementType, Slice value, Block block) {
BlockBuilder blockBuilder = elementType.createBlockBuilder(null, block.getPositionCount() + 1);
elementType.writeSlice(blockBuilder, value);
for (int i = 0; i < block.getPositionCount(); i++) {
elementType.appendTo(block, i, blockBuilder);
}
return blockBuilder.build();
}
use of io.trino.spi.block.BlockBuilder in project trino by trinodb.
the class ArrayConcatUtils method appendElement.
@UsedByGeneratedCode
public static Block appendElement(Type elementType, Block block, Slice value) {
BlockBuilder blockBuilder = elementType.createBlockBuilder(null, block.getPositionCount() + 1);
for (int i = 0; i < block.getPositionCount(); i++) {
elementType.appendTo(block, i, blockBuilder);
}
elementType.writeSlice(blockBuilder, value);
return blockBuilder.build();
}
use of io.trino.spi.block.BlockBuilder in project trino by trinodb.
the class ArrayDistinctFunction method bigintDistinct.
@SqlType("array(bigint)")
public Block bigintDistinct(@SqlType("array(bigint)") Block array) {
if (array.getPositionCount() == 0) {
return array;
}
boolean containsNull = false;
LongSet set = new LongOpenHashSet(array.getPositionCount());
int distinctCount = 0;
if (pageBuilder.isFull()) {
pageBuilder.reset();
}
BlockBuilder distinctElementBlockBuilder = pageBuilder.getBlockBuilder(0);
for (int i = 0; i < array.getPositionCount(); i++) {
if (array.isNull(i)) {
if (!containsNull) {
containsNull = true;
distinctElementBlockBuilder.appendNull();
distinctCount++;
}
continue;
}
long value = BIGINT.getLong(array, i);
if (!set.contains(value)) {
set.add(value);
distinctCount++;
BIGINT.appendTo(array, i, distinctElementBlockBuilder);
}
}
pageBuilder.declarePositions(distinctCount);
return distinctElementBlockBuilder.getRegion(distinctElementBlockBuilder.getPositionCount() - distinctCount, distinctCount);
}
use of io.trino.spi.block.BlockBuilder in project trino by trinodb.
the class ArrayFilterFunction method filterDouble.
@TypeParameter("T")
@TypeParameterSpecialization(name = "T", nativeContainerType = double.class)
@SqlType("array(T)")
public static Block filterDouble(@TypeParameter("T") Type elementType, @SqlType("array(T)") Block arrayBlock, @SqlType("function(T, boolean)") DoubleToBooleanFunction function) {
int positionCount = arrayBlock.getPositionCount();
BlockBuilder resultBuilder = elementType.createBlockBuilder(null, positionCount);
for (int position = 0; position < positionCount; position++) {
Double input = null;
if (!arrayBlock.isNull(position)) {
input = elementType.getDouble(arrayBlock, position);
}
Boolean keep = function.apply(input);
if (TRUE.equals(keep)) {
elementType.appendTo(arrayBlock, position, resultBuilder);
}
}
return resultBuilder.build();
}
use of io.trino.spi.block.BlockBuilder in project trino by trinodb.
the class ArrayFilterFunction method filterObject.
@TypeParameter("T")
@TypeParameterSpecialization(name = "T", nativeContainerType = Object.class)
@SqlType("array(T)")
public static Block filterObject(@TypeParameter("T") Type elementType, @SqlType("array(T)") Block arrayBlock, @SqlType("function(T, boolean)") ObjectToBooleanFunction function) {
int positionCount = arrayBlock.getPositionCount();
BlockBuilder resultBuilder = elementType.createBlockBuilder(null, positionCount);
for (int position = 0; position < positionCount; position++) {
Object input = null;
if (!arrayBlock.isNull(position)) {
input = elementType.getObject(arrayBlock, position);
}
Boolean keep = function.apply(input);
if (TRUE.equals(keep)) {
elementType.appendTo(arrayBlock, position, resultBuilder);
}
}
return resultBuilder.build();
}
Aggregations