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();
}
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();
}
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();
}
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);
}
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);
}
}
Aggregations