use of io.trino.spi.block.BlockBuilder in project trino by trinodb.
the class QuerySystemTable method resourceGroupIdToBlock.
private static Block resourceGroupIdToBlock(ResourceGroupId resourceGroupId) {
requireNonNull(resourceGroupId, "resourceGroupId is null");
List<String> segments = resourceGroupId.getSegments();
BlockBuilder blockBuilder = createUnboundedVarcharType().createBlockBuilder(null, segments.size());
for (String segment : segments) {
createUnboundedVarcharType().writeSlice(blockBuilder, utf8Slice(segment));
}
return blockBuilder.build();
}
use of io.trino.spi.block.BlockBuilder in project trino by trinodb.
the class RuleStatsSystemTable method pageSource.
@Override
public ConnectorPageSource pageSource(ConnectorTransactionHandle transactionHandle, ConnectorSession session, TupleDomain<Integer> constraint) {
checkState(ruleStatsRecorder.isPresent(), "Rule stats system table can return results only on coordinator");
Map<Class<?>, RuleStats> ruleStats = ruleStatsRecorder.get().getStats();
int positionCount = ruleStats.size();
Map<String, BlockBuilder> blockBuilders = ruleStatsTable.getColumns().stream().collect(toImmutableMap(ColumnMetadata::getName, column -> column.getType().createBlockBuilder(null, positionCount)));
for (Map.Entry<Class<?>, RuleStats> entry : ruleStats.entrySet()) {
RuleStats stats = entry.getValue();
VARCHAR.writeString(blockBuilders.get("rule_name"), entry.getKey().getSimpleName());
BIGINT.writeLong(blockBuilders.get("invocations"), stats.getInvocations());
BIGINT.writeLong(blockBuilders.get("matches"), stats.getHits());
BIGINT.writeLong(blockBuilders.get("failures"), stats.getFailures());
DOUBLE.writeDouble(blockBuilders.get("average_time"), stats.getTime().getAvg());
BlockBuilder mapWriter = blockBuilders.get("time_distribution_percentiles").beginBlockEntry();
for (Map.Entry<Double, Double> percentile : stats.getTime().getPercentiles().entrySet()) {
DOUBLE.writeDouble(mapWriter, percentile.getKey());
DOUBLE.writeDouble(mapWriter, percentile.getValue());
}
blockBuilders.get("time_distribution_percentiles").closeEntry();
}
Block[] blocks = ruleStatsTable.getColumns().stream().map(column -> blockBuilders.get(column.getName()).build()).toArray(Block[]::new);
return new FixedPageSource(ImmutableList.of(new Page(positionCount, blocks)));
}
use of io.trino.spi.block.BlockBuilder in project trino by trinodb.
the class TransactionsSystemTable method createStringsBlock.
private static Block createStringsBlock(List<CatalogName> values) {
VarcharType varchar = createUnboundedVarcharType();
BlockBuilder builder = varchar.createBlockBuilder(null, values.size());
for (CatalogName value : values) {
if (value == null) {
builder.appendNull();
} else {
varchar.writeString(builder, value.getCatalogName());
}
}
return builder.build();
}
use of io.trino.spi.block.BlockBuilder in project trino by trinodb.
the class ArrayConcatFunction method concat.
@UsedByGeneratedCode
public static Block concat(Type elementType, Object state, Block[] blocks) {
int resultPositionCount = 0;
// fast path when there is at most one non empty block
Block nonEmptyBlock = null;
for (int i = 0; i < blocks.length; i++) {
resultPositionCount += blocks[i].getPositionCount();
if (blocks[i].getPositionCount() > 0) {
nonEmptyBlock = blocks[i];
}
}
if (nonEmptyBlock == null) {
return blocks[0];
}
if (resultPositionCount == nonEmptyBlock.getPositionCount()) {
return nonEmptyBlock;
}
PageBuilder pageBuilder = (PageBuilder) state;
if (pageBuilder.isFull()) {
pageBuilder.reset();
}
BlockBuilder blockBuilder = pageBuilder.getBlockBuilder(0);
for (int blockIndex = 0; blockIndex < blocks.length; blockIndex++) {
Block block = blocks[blockIndex];
for (int i = 0; i < block.getPositionCount(); i++) {
elementType.appendTo(block, i, blockBuilder);
}
}
pageBuilder.declarePositions(resultPositionCount);
return blockBuilder.getRegion(blockBuilder.getPositionCount() - resultPositionCount, resultPositionCount);
}
use of io.trino.spi.block.BlockBuilder in project trino by trinodb.
the class ArrayToArrayCast method filterObject.
@TypeParameter("F")
@TypeParameter("T")
@TypeParameterSpecialization(name = "T", nativeContainerType = Object.class)
@SqlType("array(T)")
public static Block filterObject(@TypeParameter("T") Type resultType, @CastDependency(fromType = "F", toType = "T", convention = @Convention(arguments = BLOCK_POSITION, result = NULLABLE_RETURN, session = true)) MethodHandle cast, ConnectorSession session, @SqlType("array(F)") Block array) throws Throwable {
int positionCount = array.getPositionCount();
BlockBuilder resultBuilder = resultType.createBlockBuilder(null, positionCount);
for (int position = 0; position < positionCount; position++) {
if (!array.isNull(position)) {
Object value = (Object) cast.invoke(session, array, position);
if (value != null) {
resultType.writeObject(resultBuilder, value);
continue;
}
}
resultBuilder.appendNull();
}
return resultBuilder.build();
}
Aggregations