use of io.trino.spi.block.BlockBuilder in project trino by trinodb.
the class ArrayFilterFunction method filterBoolean.
@TypeParameter("T")
@TypeParameterSpecialization(name = "T", nativeContainerType = boolean.class)
@SqlType("array(T)")
public static Block filterBoolean(@TypeParameter("T") Type elementType, @SqlType("array(T)") Block arrayBlock, @SqlType("function(T, boolean)") BooleanToBooleanFunction function) {
int positionCount = arrayBlock.getPositionCount();
BlockBuilder resultBuilder = elementType.createBlockBuilder(null, positionCount);
for (int position = 0; position < positionCount; position++) {
Boolean input = null;
if (!arrayBlock.isNull(position)) {
input = elementType.getBoolean(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 PagePartitioner method appendToOutputPartition.
private void appendToOutputPartition(PageBuilder outputPartition, Page page, IntArrayList positions, PositionsAppender[] positionsAppenders) {
outputPartition.declarePositions(positions.size());
for (int channel = 0; channel < positionsAppenders.length; channel++) {
Block partitionBlock = page.getBlock(channel);
BlockBuilder target = outputPartition.getBlockBuilder(channel);
positionsAppenders[channel].appendTo(positions, partitionBlock, target);
}
}
use of io.trino.spi.block.BlockBuilder in project trino by trinodb.
the class PropertyUtil method evaluateProperty.
private static Object evaluateProperty(Expression expression, PropertyMetadata<?> property, Session session, PlannerContext plannerContext, AccessControl accessControl, Map<NodeRef<Parameter>, Expression> parameters, ErrorCodeSupplier errorCode, String propertyTypeDescription) {
Object sqlObjectValue;
try {
Type expectedType = property.getSqlType();
Expression rewritten = ExpressionTreeRewriter.rewriteWith(new ParameterRewriter(parameters), expression);
Object value = evaluateConstantExpression(rewritten, expectedType, plannerContext, session, accessControl, parameters);
// convert to object value type of SQL type
BlockBuilder blockBuilder = expectedType.createBlockBuilder(null, 1);
writeNativeValue(expectedType, blockBuilder, value);
sqlObjectValue = expectedType.getObjectValue(session.toConnectorSession(), blockBuilder, 0);
} catch (TrinoException e) {
throw new TrinoException(errorCode, format("Invalid value for %s '%s': Cannot convert [%s] to %s", propertyTypeDescription, property.getName(), expression, property.getSqlType()), e);
}
if (sqlObjectValue == null) {
throw new TrinoException(errorCode, format("Invalid null value for %s '%s' from [%s]", propertyTypeDescription, property.getName(), expression));
}
try {
return property.decode(sqlObjectValue);
} catch (Exception e) {
throw new TrinoException(errorCode, format("Unable to set %s '%s' to [%s]: %s", propertyTypeDescription, property.getName(), expression, e.getMessage()), e);
}
}
use of io.trino.spi.block.BlockBuilder in project trino by trinodb.
the class ArrayAggregationStateSerializer method serialize.
@Override
public void serialize(ArrayAggregationState state, BlockBuilder out) {
if (state.isEmpty()) {
out.appendNull();
} else {
BlockBuilder entryBuilder = out.beginBlockEntry();
state.forEach((block, position) -> elementType.appendTo(block, position, entryBuilder));
out.closeEntry();
}
}
use of io.trino.spi.block.BlockBuilder in project trino by trinodb.
the class DoubleHistogramAggregation method output.
@OutputFunction("map(double,double)")
public static void output(@AggregationState State state, BlockBuilder out) {
if (state.get() == null) {
out.appendNull();
} else {
Map<Double, Double> value = state.get().getBuckets();
BlockBuilder entryBuilder = out.beginBlockEntry();
for (Map.Entry<Double, Double> entry : value.entrySet()) {
DoubleType.DOUBLE.writeDouble(entryBuilder, entry.getKey());
DoubleType.DOUBLE.writeDouble(entryBuilder, entry.getValue());
}
out.closeEntry();
}
}
Aggregations