Search in sources :

Example 21 with PageBuilder

use of io.trino.spi.PageBuilder in project trino by trinodb.

the class BenchmarkGroupByHash method groupByHashPreCompute.

@Benchmark
@OperationsPerInvocation(POSITIONS)
public Object groupByHashPreCompute(BenchmarkData data) {
    GroupByHash groupByHash = new MultiChannelGroupByHash(data.getTypes(), data.getChannels(), data.getHashChannel(), EXPECTED_SIZE, false, getJoinCompiler(), TYPE_OPERATOR_FACTORY, NOOP);
    addInputPagesToHash(groupByHash, data.getPages());
    ImmutableList.Builder<Page> pages = ImmutableList.builder();
    PageBuilder pageBuilder = new PageBuilder(groupByHash.getTypes());
    for (int groupId = 0; groupId < groupByHash.getGroupCount(); groupId++) {
        pageBuilder.declarePosition();
        groupByHash.appendValuesTo(groupId, pageBuilder, 0);
        if (pageBuilder.isFull()) {
            pages.add(pageBuilder.build());
            pageBuilder.reset();
        }
    }
    pages.add(pageBuilder.build());
    return pageBuilder.build();
}
Also used : ImmutableList(com.google.common.collect.ImmutableList) Page(io.trino.spi.Page) PageBuilder(io.trino.spi.PageBuilder) Benchmark(org.openjdk.jmh.annotations.Benchmark) OperationsPerInvocation(org.openjdk.jmh.annotations.OperationsPerInvocation)

Example 22 with PageBuilder

use of io.trino.spi.PageBuilder in project trino by trinodb.

the class TestRealHistogramAggregation method makeInput.

private static Page makeInput(int numberOfBuckets) {
    PageBuilder builder = new PageBuilder(ImmutableList.of(BIGINT, REAL, DOUBLE));
    for (int i = 0; i < 100; i++) {
        builder.declarePosition();
        BIGINT.writeLong(builder.getBlockBuilder(0), numberOfBuckets);
        // value
        REAL.writeLong(builder.getBlockBuilder(1), i);
        // weight
        DOUBLE.writeDouble(builder.getBlockBuilder(2), 1);
    }
    return builder.build();
}
Also used : PageBuilder(io.trino.spi.PageBuilder)

Example 23 with PageBuilder

use of io.trino.spi.PageBuilder in project trino by trinodb.

the class CheckpointWriter method write.

public void write(ConnectorSession session, CheckpointEntries entries, Path targetPath) {
    RowType metadataEntryType = checkpointSchemaManager.getMetadataEntryType();
    RowType protocolEntryType = checkpointSchemaManager.getProtocolEntryType();
    RowType txnEntryType = checkpointSchemaManager.getTxnEntryType();
    RowType addEntryType = checkpointSchemaManager.getAddEntryType(entries.getMetadataEntry());
    RowType removeEntryType = checkpointSchemaManager.getRemoveEntryType();
    List<String> columnNames = ImmutableList.of("metaData", "protocol", "txn", "add", "remove");
    List<Type> columnTypes = ImmutableList.of(metadataEntryType, protocolEntryType, txnEntryType, addEntryType, removeEntryType);
    Properties schema = buildSchemaProperties(columnNames, columnTypes);
    Configuration conf = hdfsEnvironment.getConfiguration(new HdfsEnvironment.HdfsContext(session), targetPath);
    configureCompression(conf, SNAPPY);
    JobConf jobConf = toJobConf(conf);
    RecordFileWriter writer = new RecordFileWriter(targetPath, columnNames, fromHiveStorageFormat(PARQUET), schema, PARQUET.getEstimatedWriterMemoryUsage(), jobConf, typeManager, DateTimeZone.UTC, session);
    PageBuilder pageBuilder = new PageBuilder(columnTypes);
    writeMetadataEntry(pageBuilder, metadataEntryType, entries.getMetadataEntry());
    writeProtocolEntry(pageBuilder, protocolEntryType, entries.getProtocolEntry());
    for (TransactionEntry transactionEntry : entries.getTransactionEntries()) {
        writeTransactionEntry(pageBuilder, txnEntryType, transactionEntry);
    }
    for (AddFileEntry addFileEntry : entries.getAddFileEntries()) {
        writeAddFileEntry(pageBuilder, addEntryType, addFileEntry);
    }
    for (RemoveFileEntry removeFileEntry : entries.getRemoveFileEntries()) {
        writeRemoveFileEntry(pageBuilder, removeEntryType, removeFileEntry);
    }
    // Not writing commit infos for now. DB does not keep them in the checkpoints by default
    writer.appendRows(pageBuilder.build());
    writer.commit();
}
Also used : Configuration(org.apache.hadoop.conf.Configuration) RowType(io.trino.spi.type.RowType) PageBuilder(io.trino.spi.PageBuilder) Properties(java.util.Properties) HdfsEnvironment(io.trino.plugin.hive.HdfsEnvironment) Type(io.trino.spi.type.Type) TimestampType(io.trino.spi.type.TimestampType) HiveType(io.trino.plugin.hive.HiveType) RowType(io.trino.spi.type.RowType) MapType(io.trino.spi.type.MapType) ArrayType(io.trino.spi.type.ArrayType) RecordFileWriter(io.trino.plugin.hive.RecordFileWriter) AddFileEntry(io.trino.plugin.deltalake.transactionlog.AddFileEntry) RemoveFileEntry(io.trino.plugin.deltalake.transactionlog.RemoveFileEntry) ConfigurationUtils.toJobConf(io.trino.plugin.hive.util.ConfigurationUtils.toJobConf) JobConf(org.apache.hadoop.mapred.JobConf) TransactionEntry(io.trino.plugin.deltalake.transactionlog.TransactionEntry)

Example 24 with PageBuilder

use of io.trino.spi.PageBuilder in project trino by trinodb.

the class BenchmarkHashBuildAndJoinOperators method partitionPages.

private static Page[] partitionPages(Page page, List<Type> types, int partitionCount, PartitionFunction partitionGenerator) {
    PageBuilder[] builders = new PageBuilder[partitionCount];
    for (int i = 0; i < partitionCount; i++) {
        builders[i] = new PageBuilder(types);
    }
    for (int i = 0; i < page.getPositionCount(); i++) {
        int partition = partitionGenerator.getPartition(page, i);
        appendRow(builders[partition], types, page, i);
    }
    return Arrays.stream(builders).map(PageBuilder::build).toArray(Page[]::new);
}
Also used : PageBuilder(io.trino.spi.PageBuilder)

Example 25 with PageBuilder

use of io.trino.spi.PageBuilder in project trino by trinodb.

the class TestTypedSet method testGetElementPositionWithProvidedNonEmptyBlockBuilder.

@Test
public void testGetElementPositionWithProvidedNonEmptyBlockBuilder() {
    int elementCount = 100;
    // Set initialTypedSetEntryCount to a small number to trigger rehash()
    int initialTypedSetEntryCount = 10;
    PageBuilder pageBuilder = new PageBuilder(ImmutableList.of(BIGINT));
    BlockBuilder firstBlockBuilder = pageBuilder.getBlockBuilder(0);
    for (int i = 0; i < elementCount; i++) {
        BIGINT.writeLong(firstBlockBuilder, i);
    }
    pageBuilder.declarePositions(elementCount);
    // The secondBlockBuilder should already have elementCount rows.
    BlockBuilder secondBlockBuilder = pageBuilder.getBlockBuilder(0);
    TypedSet typedSet = createDistinctTypedSet(BIGINT, initialTypedSetEntryCount, secondBlockBuilder);
    BlockBuilder externalBlockBuilder = BIGINT.createFixedSizeBlockBuilder(elementCount);
    for (int i = 0; i < elementCount; i++) {
        if (i % 10 == 0) {
            externalBlockBuilder.appendNull();
        } else {
            BIGINT.writeLong(externalBlockBuilder, i);
        }
        typedSet.add(externalBlockBuilder, i);
    }
    assertEquals(typedSet.size(), secondBlockBuilder.getPositionCount() - elementCount);
    assertEquals(typedSet.size(), elementCount - elementCount / 10 + 1);
    for (int i = 0; i < typedSet.size(); i++) {
        int expectedPositionInSecondBlockBuilder = i + elementCount;
        assertEquals(typedSet.positionOf(secondBlockBuilder, expectedPositionInSecondBlockBuilder), expectedPositionInSecondBlockBuilder);
    }
}
Also used : PageBuilder(io.trino.spi.PageBuilder) BlockBuilder(io.trino.spi.block.BlockBuilder) Test(org.testng.annotations.Test)

Aggregations

PageBuilder (io.trino.spi.PageBuilder)58 BlockBuilder (io.trino.spi.block.BlockBuilder)24 Page (io.trino.spi.Page)23 Type (io.trino.spi.type.Type)22 ImmutableList (com.google.common.collect.ImmutableList)14 Block (io.trino.spi.block.Block)11 Test (org.testng.annotations.Test)10 List (java.util.List)8 Slice (io.airlift.slice.Slice)6 ArrayType (io.trino.spi.type.ArrayType)6 INTEGER (io.trino.spi.type.IntegerType.INTEGER)5 Slices (io.airlift.slice.Slices)4 UsedByGeneratedCode (io.trino.annotation.UsedByGeneratedCode)4 DictionaryBlock (io.trino.spi.block.DictionaryBlock)4 RunLengthEncodedBlock (io.trino.spi.block.RunLengthEncodedBlock)4 BIGINT (io.trino.spi.type.BigintType.BIGINT)4 DOUBLE (io.trino.spi.type.DoubleType.DOUBLE)4 MapType (io.trino.spi.type.MapType)4 VarcharType.createUnboundedVarcharType (io.trino.spi.type.VarcharType.createUnboundedVarcharType)4 RowType (io.trino.spi.type.RowType)3