Search in sources :

Example 1 with PageBuilder

use of io.prestosql.spi.PageBuilder in project hetu-core by openlookeng.

the class BenchmarkPageProcessor method handCoded.

@Benchmark
public Page handCoded() {
    PageBuilder pageBuilder = new PageBuilder(ImmutableList.of(DOUBLE));
    int count = Tpch1FilterAndProject.process(inputPage, 0, inputPage.getPositionCount(), pageBuilder);
    checkState(count == inputPage.getPositionCount());
    return pageBuilder.build();
}
Also used : PageBuilder(io.prestosql.spi.PageBuilder) Benchmark(org.openjdk.jmh.annotations.Benchmark)

Example 2 with PageBuilder

use of io.prestosql.spi.PageBuilder in project hetu-core by openlookeng.

the class InCodeGeneratorBenchmark method setup.

@Setup
public void setup() {
    Random random = new Random();
    RowExpression[] arguments = new RowExpression[1 + inListCount];
    switch(type) {
        case StandardTypes.BIGINT:
            prestoType = BIGINT;
            for (int i = 1; i <= inListCount; i++) {
                arguments[i] = constant((long) random.nextInt(), BIGINT);
            }
            break;
        case StandardTypes.DOUBLE:
            prestoType = DOUBLE;
            for (int i = 1; i <= inListCount; i++) {
                arguments[i] = constant(random.nextDouble(), DOUBLE);
            }
            break;
        case StandardTypes.VARCHAR:
            prestoType = VARCHAR;
            for (int i = 1; i <= inListCount; i++) {
                arguments[i] = constant(Slices.utf8Slice(Long.toString(random.nextLong())), VARCHAR);
            }
            break;
        default:
            throw new IllegalStateException();
    }
    arguments[0] = field(0, prestoType);
    RowExpression project = field(0, prestoType);
    PageBuilder pageBuilder = new PageBuilder(ImmutableList.of(prestoType));
    for (int i = 0; i < 10_000; i++) {
        pageBuilder.declarePosition();
        switch(type) {
            case StandardTypes.BIGINT:
                BIGINT.writeLong(pageBuilder.getBlockBuilder(0), random.nextInt());
                break;
            case StandardTypes.DOUBLE:
                DOUBLE.writeDouble(pageBuilder.getBlockBuilder(0), random.nextDouble());
                break;
            case StandardTypes.VARCHAR:
                VARCHAR.writeSlice(pageBuilder.getBlockBuilder(0), Slices.utf8Slice(Long.toString(random.nextLong())));
                break;
        }
    }
    inputPage = pageBuilder.build();
    RowExpression filter = new SpecialForm(IN, BOOLEAN, arguments);
    Metadata metadata = createTestMetadataManager();
    processor = new ExpressionCompiler(metadata, new PageFunctionCompiler(metadata, 0)).compilePageProcessor(Optional.of(filter), ImmutableList.of(project)).get();
}
Also used : Random(java.util.Random) Metadata(io.prestosql.metadata.Metadata) RowExpression(io.prestosql.spi.relation.RowExpression) PageBuilder(io.prestosql.spi.PageBuilder) SpecialForm(io.prestosql.spi.relation.SpecialForm) Setup(org.openjdk.jmh.annotations.Setup)

Example 3 with PageBuilder

use of io.prestosql.spi.PageBuilder in project hetu-core by openlookeng.

the class PageProcessorBenchmark method rowOriented.

@Benchmark
public Page rowOriented() {
    PageBuilder pageBuilder = new PageBuilder(types);
    cursorProcessor.process(null, yieldSignal, recordSet.cursor(), pageBuilder);
    return pageBuilder.build();
}
Also used : PageBuilder(io.prestosql.spi.PageBuilder) SequencePageBuilder(io.prestosql.SequencePageBuilder) Benchmark(org.openjdk.jmh.annotations.Benchmark)

Example 4 with PageBuilder

use of io.prestosql.spi.PageBuilder in project hetu-core by openlookeng.

the class PagesIndex method getSortedPages.

public Iterator<Page> getSortedPages() {
    return new AbstractIterator<Page>() {

        private int currentPosition;

        private final PageBuilder pageBuilder = new PageBuilder(types);

        private final int[] outputChannels = new int[types.size()];

        {
            Arrays.setAll(outputChannels, IntUnaryOperator.identity());
        }

        @Override
        public Page computeNext() {
            currentPosition = buildPage(currentPosition, outputChannels, pageBuilder);
            if (pageBuilder.isEmpty()) {
                return endOfData();
            }
            Page page = pageBuilder.build();
            pageBuilder.reset();
            return page;
        }
    };
}
Also used : Page(io.prestosql.spi.Page) AbstractIterator(com.google.common.collect.AbstractIterator) PageBuilder(io.prestosql.spi.PageBuilder)

Example 5 with PageBuilder

use of io.prestosql.spi.PageBuilder in project hetu-core by openlookeng.

the class TableDeleteOperator method getOutput.

@Override
public Page getOutput() {
    if (state == State.FINISHED || (sourceLayout.isPresent() && state != State.FINISHING)) {
        return null;
    }
    state = State.FINISHED;
    TableHandle tableHandleForDelete = tableHandle;
    if (sourceLayout.isPresent()) {
        // Replace the values from subqueries in filter predicates
        VariablesExtractor.extractUnique(filter.get()).stream().forEach(expr -> symbolExpressionMap.putIfAbsent(new Symbol(expr.getName()), expr));
        RowExpression rowExpression = RowExpressionVariableInliner.inlineVariables(node -> symbolExpressionMap.get(new Symbol(node.getName())), filter.get());
        // Create the tuple domain based on filter and values from source;
        RowExpressionDomainTranslator.ExtractionResult<VariableReferenceExpression> decomposedPredicate = (new RowExpressionDomainTranslator(metadata)).fromPredicate(session.toConnectorSession(), rowExpression, RowExpressionDomainTranslator.BASIC_COLUMN_EXTRACTOR);
        TupleDomain<ColumnHandle> tupleDomain = decomposedPredicate.getTupleDomain().transform(variableName -> assignments.get(new Symbol(variableName.getName())));
        Constraint constraint = new Constraint(tupleDomain);
        // Apply the constraint on the table handle
        Optional<TableHandle> tableHandleDelete = metadata.applyDelete(session, this.tableHandle, constraint);
        if (tableHandleDelete.isPresent()) {
            tableHandleForDelete = tableHandleDelete.get();
        }
    }
    OptionalLong rowsDeletedCount = metadata.executeDelete(session, tableHandleForDelete);
    // output page will only be constructed once,
    // so a new PageBuilder is constructed (instead of using PageBuilder.reset)
    PageBuilder page = new PageBuilder(1, TYPES);
    BlockBuilder rowsBuilder = page.getBlockBuilder(0);
    page.declarePosition();
    if (rowsDeletedCount.isPresent()) {
        BIGINT.writeLong(rowsBuilder, rowsDeletedCount.getAsLong());
    } else {
        rowsBuilder.appendNull();
    }
    return page.build();
}
Also used : ColumnHandle(io.prestosql.spi.connector.ColumnHandle) Constraint(io.prestosql.spi.connector.Constraint) Symbol(io.prestosql.spi.plan.Symbol) RowExpressionDomainTranslator(io.prestosql.sql.relational.RowExpressionDomainTranslator) RowExpression(io.prestosql.spi.relation.RowExpression) PageBuilder(io.prestosql.spi.PageBuilder) VariableReferenceExpression(io.prestosql.spi.relation.VariableReferenceExpression) OptionalLong(java.util.OptionalLong) TableHandle(io.prestosql.spi.metadata.TableHandle) BlockBuilder(io.prestosql.spi.block.BlockBuilder)

Aggregations

PageBuilder (io.prestosql.spi.PageBuilder)54 Page (io.prestosql.spi.Page)24 BlockBuilder (io.prestosql.spi.block.BlockBuilder)24 Type (io.prestosql.spi.type.Type)20 ImmutableList (com.google.common.collect.ImmutableList)14 Block (io.prestosql.spi.block.Block)11 Test (org.testng.annotations.Test)11 List (java.util.List)7 Slice (io.airlift.slice.Slice)6 Benchmark (org.openjdk.jmh.annotations.Benchmark)6 ArrayType (io.prestosql.spi.type.ArrayType)5 ArrayList (java.util.ArrayList)5 BlockAssertions.createLongsBlock (io.prestosql.block.BlockAssertions.createLongsBlock)4 INTEGER (io.prestosql.spi.type.IntegerType.INTEGER)4 Collectors.toList (java.util.stream.Collectors.toList)4 Slices (io.airlift.slice.Slices)3 BlockAssertions.createLongSequenceBlock (io.prestosql.block.BlockAssertions.createLongSequenceBlock)3 BlockAssertions.createStringSequenceBlock (io.prestosql.block.BlockAssertions.createStringSequenceBlock)3 GroupByHash.createGroupByHash (io.prestosql.operator.GroupByHash.createGroupByHash)3 UsedByGeneratedCode (io.prestosql.spi.annotation.UsedByGeneratedCode)3