Search in sources :

Example 1 with PageProjection

use of io.trino.operator.project.PageProjection in project trino by trinodb.

the class TestPageFunctionCompiler method testGeneratedClassName.

@Test
public void testGeneratedClassName() {
    PageFunctionCompiler functionCompiler = FUNCTION_RESOLUTION.getPageFunctionCompiler();
    String planNodeId = "7";
    String stageId = "20170707_223500_67496_zguwn.2";
    String classSuffix = stageId + "_" + planNodeId;
    Supplier<PageProjection> projectionSupplier = functionCompiler.compileProjection(ADD_10_EXPRESSION, Optional.of(classSuffix));
    PageProjection projection = projectionSupplier.get();
    Work<Block> work = projection.project(SESSION, new DriverYieldSignal(), createLongBlockPage(0), SelectedPositions.positionsRange(0, 1));
    // class name should look like PageProjectionOutput_20170707_223500_67496_zguwn_2_7_XX
    assertTrue(work.getClass().getSimpleName().startsWith("PageProjectionWork_" + stageId.replace('.', '_') + "_" + planNodeId));
}
Also used : PageProjection(io.trino.operator.project.PageProjection) Block(io.trino.spi.block.Block) DriverYieldSignal(io.trino.operator.DriverYieldSignal) Test(org.testng.annotations.Test)

Example 2 with PageProjection

use of io.trino.operator.project.PageProjection in project trino by trinodb.

the class HandTpchQuery6 method createOperatorFactories.

@Override
protected List<? extends OperatorFactory> createOperatorFactories() {
    // select sum(extendedprice * discount) as revenue
    // from lineitem
    // where shipdate >= '1994-01-01'
    // and shipdate < '1995-01-01'
    // and discount >= 0.05
    // and discount <= 0.07
    // and quantity < 24;
    OperatorFactory tableScanOperator = createTableScanOperator(0, new PlanNodeId("test"), "lineitem", "extendedprice", "discount", "shipdate", "quantity");
    Supplier<PageProjection> projection = new PageFunctionCompiler(localQueryRunner.getFunctionManager(), 0).compileProjection(field(0, BIGINT), Optional.empty());
    OperatorFactory tpchQuery6Operator = FilterAndProjectOperator.createOperatorFactory(1, new PlanNodeId("test"), () -> new PageProcessor(Optional.of(new TpchQuery6Filter()), ImmutableList.of(projection.get())), ImmutableList.of(DOUBLE), DataSize.ofBytes(0), 0);
    AggregationOperatorFactory aggregationOperator = new AggregationOperatorFactory(2, new PlanNodeId("test"), ImmutableList.of(doubleSum.bind(ImmutableList.of(0))));
    return ImmutableList.of(tableScanOperator, tpchQuery6Operator, aggregationOperator);
}
Also used : PlanNodeId(io.trino.sql.planner.plan.PlanNodeId) PageProjection(io.trino.operator.project.PageProjection) PageFunctionCompiler(io.trino.sql.gen.PageFunctionCompiler) PageProcessor(io.trino.operator.project.PageProcessor) AggregationOperatorFactory(io.trino.operator.AggregationOperator.AggregationOperatorFactory) OperatorFactory(io.trino.operator.OperatorFactory) AggregationOperatorFactory(io.trino.operator.AggregationOperator.AggregationOperatorFactory)

Example 3 with PageProjection

use of io.trino.operator.project.PageProjection in project trino by trinodb.

the class TestPageFunctionCompiler method testFailureDoesNotCorruptFutureResults.

@Test
public void testFailureDoesNotCorruptFutureResults() {
    PageFunctionCompiler functionCompiler = FUNCTION_RESOLUTION.getPageFunctionCompiler();
    Supplier<PageProjection> projectionSupplier = functionCompiler.compileProjection(ADD_10_EXPRESSION, Optional.empty());
    PageProjection projection = projectionSupplier.get();
    // process good page and verify we got the expected number of result rows
    Page goodPage = createLongBlockPage(0, 1, 2, 3, 4, 5, 6, 7, 8, 9);
    Block goodResult = project(projection, goodPage, SelectedPositions.positionsRange(0, goodPage.getPositionCount()));
    assertEquals(goodPage.getPositionCount(), goodResult.getPositionCount());
    // addition will throw due to integer overflow
    Page badPage = createLongBlockPage(0, 1, 2, 3, 4, Long.MAX_VALUE);
    assertTrinoExceptionThrownBy(() -> project(projection, badPage, SelectedPositions.positionsRange(0, 100))).hasErrorCode(NUMERIC_VALUE_OUT_OF_RANGE);
    // running the good page should still work
    // if block builder in generated code was not reset properly, we could get junk results after the failure
    goodResult = project(projection, goodPage, SelectedPositions.positionsRange(0, goodPage.getPositionCount()));
    assertEquals(goodPage.getPositionCount(), goodResult.getPositionCount());
}
Also used : PageProjection(io.trino.operator.project.PageProjection) Block(io.trino.spi.block.Block) Page(io.trino.spi.Page) Test(org.testng.annotations.Test)

Example 4 with PageProjection

use of io.trino.operator.project.PageProjection in project trino by trinodb.

the class ExpressionCompiler method compilePageProcessor.

private Supplier<PageProcessor> compilePageProcessor(Optional<RowExpression> filter, List<? extends RowExpression> projections, Optional<String> classNameSuffix, OptionalInt initialBatchSize) {
    Optional<Supplier<PageFilter>> filterFunctionSupplier = filter.map(expression -> pageFunctionCompiler.compileFilter(expression, classNameSuffix));
    List<Supplier<PageProjection>> pageProjectionSuppliers = projections.stream().map(projection -> pageFunctionCompiler.compileProjection(projection, classNameSuffix)).collect(toImmutableList());
    return () -> {
        Optional<PageFilter> filterFunction = filterFunctionSupplier.map(Supplier::get);
        List<PageProjection> pageProjections = pageProjectionSuppliers.stream().map(Supplier::get).collect(toImmutableList());
        return new PageProcessor(filterFunction, pageProjections, initialBatchSize);
    };
}
Also used : CacheStatsMBean(io.airlift.jmx.CacheStatsMBean) ParameterizedType.type(io.airlift.bytecode.ParameterizedType.type) Nested(org.weakref.jmx.Nested) BOOLEAN(io.trino.spi.type.BooleanType.BOOLEAN) OptionalInt(java.util.OptionalInt) Supplier(java.util.function.Supplier) Access.a(io.airlift.bytecode.Access.a) NonEvictableLoadingCache(io.trino.collect.cache.NonEvictableLoadingCache) PageFilter(io.trino.operator.project.PageFilter) Inject(javax.inject.Inject) ImmutableList(com.google.common.collect.ImmutableList) Managed(org.weakref.jmx.Managed) CursorProcessor(io.trino.operator.project.CursorProcessor) Objects.requireNonNull(java.util.Objects.requireNonNull) PageProcessor(io.trino.operator.project.PageProcessor) CompilerUtils.makeClassName(io.trino.util.CompilerUtils.makeClassName) FINAL(io.airlift.bytecode.Access.FINAL) ImmutableList.toImmutableList(com.google.common.collect.ImmutableList.toImmutableList) BytecodeUtils.invoke(io.trino.sql.gen.BytecodeUtils.invoke) Expressions.constant(io.trino.sql.relational.Expressions.constant) TrinoException(io.trino.spi.TrinoException) PageProjection(io.trino.operator.project.PageProjection) FunctionManager(io.trino.metadata.FunctionManager) CompilerUtils.defineClass(io.trino.util.CompilerUtils.defineClass) CacheLoader(com.google.common.cache.CacheLoader) Objects(java.util.Objects) SafeCaches.buildNonEvictableCache(io.trino.collect.cache.SafeCaches.buildNonEvictableCache) COMPILER_ERROR(io.trino.spi.StandardErrorCode.COMPILER_ERROR) CompilationException(io.airlift.bytecode.CompilationException) List(java.util.List) RowExpression(io.trino.sql.relational.RowExpression) PUBLIC(io.airlift.bytecode.Access.PUBLIC) Optional(java.util.Optional) VisibleForTesting(com.google.common.annotations.VisibleForTesting) CacheBuilder(com.google.common.cache.CacheBuilder) ClassDefinition(io.airlift.bytecode.ClassDefinition) MoreObjects.toStringHelper(com.google.common.base.MoreObjects.toStringHelper) PageProcessor(io.trino.operator.project.PageProcessor) Optional(java.util.Optional) Supplier(java.util.function.Supplier) ImmutableList(com.google.common.collect.ImmutableList) ImmutableList.toImmutableList(com.google.common.collect.ImmutableList.toImmutableList) List(java.util.List)

Example 5 with PageProjection

use of io.trino.operator.project.PageProjection in project trino by trinodb.

the class AbstractOperatorBenchmark method createHashProjectOperator.

protected final OperatorFactory createHashProjectOperator(int operatorId, PlanNodeId planNodeId, List<Type> types) {
    SymbolAllocator symbolAllocator = new SymbolAllocator();
    ImmutableMap.Builder<Symbol, Integer> symbolToInputMapping = ImmutableMap.builder();
    ImmutableList.Builder<PageProjection> projections = ImmutableList.builder();
    for (int channel = 0; channel < types.size(); channel++) {
        Symbol symbol = symbolAllocator.newSymbol("h" + channel, types.get(channel));
        symbolToInputMapping.put(symbol, channel);
        projections.add(new InputPageProjection(channel, types.get(channel)));
    }
    Map<Symbol, Type> symbolTypes = symbolAllocator.getTypes().allTypes();
    Optional<Expression> hashExpression = HashGenerationOptimizer.getHashExpression(session, localQueryRunner.getMetadata(), symbolAllocator, ImmutableList.copyOf(symbolTypes.keySet()));
    verify(hashExpression.isPresent());
    Map<NodeRef<Expression>, Type> expressionTypes = createTestingTypeAnalyzer(localQueryRunner.getPlannerContext()).getTypes(session, TypeProvider.copyOf(symbolTypes), hashExpression.get());
    RowExpression translated = translate(hashExpression.get(), expressionTypes, symbolToInputMapping.buildOrThrow(), localQueryRunner.getMetadata(), localQueryRunner.getFunctionManager(), session, false);
    PageFunctionCompiler functionCompiler = new PageFunctionCompiler(localQueryRunner.getFunctionManager(), 0);
    projections.add(functionCompiler.compileProjection(translated, Optional.empty()).get());
    return FilterAndProjectOperator.createOperatorFactory(operatorId, planNodeId, () -> new PageProcessor(Optional.empty(), projections.build()), ImmutableList.copyOf(Iterables.concat(types, ImmutableList.of(BIGINT))), getFilterAndProjectMinOutputPageSize(session), getFilterAndProjectMinOutputPageRowCount(session));
}
Also used : SymbolAllocator(io.trino.sql.planner.SymbolAllocator) PageFunctionCompiler(io.trino.sql.gen.PageFunctionCompiler) Symbol(io.trino.sql.planner.Symbol) ImmutableList.toImmutableList(com.google.common.collect.ImmutableList.toImmutableList) ImmutableList(com.google.common.collect.ImmutableList) RowExpression(io.trino.sql.relational.RowExpression) ImmutableMap(com.google.common.collect.ImmutableMap) PageProjection(io.trino.operator.project.PageProjection) InputPageProjection(io.trino.operator.project.InputPageProjection) NodeRef(io.trino.sql.tree.NodeRef) Type(io.trino.spi.type.Type) InputPageProjection(io.trino.operator.project.InputPageProjection) PageProcessor(io.trino.operator.project.PageProcessor) Expression(io.trino.sql.tree.Expression) RowExpression(io.trino.sql.relational.RowExpression)

Aggregations

PageProjection (io.trino.operator.project.PageProjection)5 PageProcessor (io.trino.operator.project.PageProcessor)3 ImmutableList (com.google.common.collect.ImmutableList)2 ImmutableList.toImmutableList (com.google.common.collect.ImmutableList.toImmutableList)2 Block (io.trino.spi.block.Block)2 PageFunctionCompiler (io.trino.sql.gen.PageFunctionCompiler)2 RowExpression (io.trino.sql.relational.RowExpression)2 VisibleForTesting (com.google.common.annotations.VisibleForTesting)1 MoreObjects.toStringHelper (com.google.common.base.MoreObjects.toStringHelper)1 CacheBuilder (com.google.common.cache.CacheBuilder)1 CacheLoader (com.google.common.cache.CacheLoader)1 ImmutableMap (com.google.common.collect.ImmutableMap)1 FINAL (io.airlift.bytecode.Access.FINAL)1 PUBLIC (io.airlift.bytecode.Access.PUBLIC)1 Access.a (io.airlift.bytecode.Access.a)1 ClassDefinition (io.airlift.bytecode.ClassDefinition)1 CompilationException (io.airlift.bytecode.CompilationException)1 ParameterizedType.type (io.airlift.bytecode.ParameterizedType.type)1 CacheStatsMBean (io.airlift.jmx.CacheStatsMBean)1 NonEvictableLoadingCache (io.trino.collect.cache.NonEvictableLoadingCache)1