Search in sources :

Example 1 with PageProjection

use of io.prestosql.operator.project.PageProjection in project hetu-core by openlookeng.

the class TestPageFunctionCompiler method testFailureDoesNotCorruptFutureResults.

@Test
public void testFailureDoesNotCorruptFutureResults() {
    PageFunctionCompiler functionCompiler = new PageFunctionCompiler(createTestMetadataManager(), 0);
    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);
    assertPrestoExceptionThrownBy(() -> 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.prestosql.operator.project.PageProjection) Block(io.prestosql.spi.block.Block) Page(io.prestosql.spi.Page) Test(org.testng.annotations.Test)

Example 2 with PageProjection

use of io.prestosql.operator.project.PageProjection in project hetu-core by openlookeng.

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.getMetadata(), 0).compileProjection(field(0, BIGINT), Optional.empty());
    FilterAndProjectOperator.FilterAndProjectOperatorFactory tpchQuery6Operator = new FilterAndProjectOperator.FilterAndProjectOperatorFactory(1, new PlanNodeId("test"), () -> new PageProcessor(Optional.of(new TpchQuery6Filter()), ImmutableList.of(projection.get())), ImmutableList.of(DOUBLE), new DataSize(0, BYTE), 0);
    AggregationOperatorFactory aggregationOperator = new AggregationOperatorFactory(2, new PlanNodeId("test"), Step.SINGLE, ImmutableList.of(doubleSum.bind(ImmutableList.of(0), Optional.empty())), false);
    return ImmutableList.of(tableScanOperator, tpchQuery6Operator, aggregationOperator);
}
Also used : PlanNodeId(io.prestosql.spi.plan.PlanNodeId) PageProjection(io.prestosql.operator.project.PageProjection) PageFunctionCompiler(io.prestosql.sql.gen.PageFunctionCompiler) PageProcessor(io.prestosql.operator.project.PageProcessor) OperatorFactory(io.prestosql.operator.OperatorFactory) AggregationOperatorFactory(io.prestosql.operator.AggregationOperator.AggregationOperatorFactory) AggregationOperatorFactory(io.prestosql.operator.AggregationOperator.AggregationOperatorFactory) DataSize(io.airlift.units.DataSize) FilterAndProjectOperator(io.prestosql.operator.FilterAndProjectOperator)

Example 3 with PageProjection

use of io.prestosql.operator.project.PageProjection in project hetu-core by openlookeng.

the class AbstractOperatorBenchmark method createHashProjectOperator.

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

Example 4 with PageProjection

use of io.prestosql.operator.project.PageProjection in project hetu-core by openlookeng.

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 : PageFilter(io.prestosql.operator.project.PageFilter) ParameterizedType.type(io.airlift.bytecode.ParameterizedType.type) Nested(org.weakref.jmx.Nested) LoadingCache(com.google.common.cache.LoadingCache) BytecodeUtils.invoke(io.prestosql.sql.gen.BytecodeUtils.invoke) OptionalInt(java.util.OptionalInt) Supplier(java.util.function.Supplier) CompilerUtils.makeClassName(io.prestosql.util.CompilerUtils.makeClassName) Access.a(io.airlift.bytecode.Access.a) Inject(javax.inject.Inject) ImmutableList(com.google.common.collect.ImmutableList) Managed(org.weakref.jmx.Managed) CompilerUtils.defineClass(io.prestosql.util.CompilerUtils.defineClass) Objects.requireNonNull(java.util.Objects.requireNonNull) BOOLEAN(io.prestosql.spi.type.BooleanType.BOOLEAN) PageProjection(io.prestosql.operator.project.PageProjection) FINAL(io.airlift.bytecode.Access.FINAL) PrestoException(io.prestosql.spi.PrestoException) Expressions.constant(io.prestosql.sql.relational.Expressions.constant) ImmutableList.toImmutableList(com.google.common.collect.ImmutableList.toImmutableList) Metadata(io.prestosql.metadata.Metadata) CacheLoader(com.google.common.cache.CacheLoader) Objects(java.util.Objects) CompilationException(io.airlift.bytecode.CompilationException) PageProcessor(io.prestosql.operator.project.PageProcessor) List(java.util.List) PUBLIC(io.airlift.bytecode.Access.PUBLIC) RowExpression(io.prestosql.spi.relation.RowExpression) COMPILER_ERROR(io.prestosql.spi.StandardErrorCode.COMPILER_ERROR) Optional(java.util.Optional) VisibleForTesting(com.google.common.annotations.VisibleForTesting) CacheBuilder(com.google.common.cache.CacheBuilder) ClassDefinition(io.airlift.bytecode.ClassDefinition) CursorProcessor(io.prestosql.operator.project.CursorProcessor) MoreObjects.toStringHelper(com.google.common.base.MoreObjects.toStringHelper) PageProcessor(io.prestosql.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.prestosql.operator.project.PageProjection in project hetu-core by openlookeng.

the class TestPageFunctionCompiler method testGeneratedClassName.

@Test
public void testGeneratedClassName() {
    PageFunctionCompiler functionCompiler = new PageFunctionCompiler(createTestMetadataManager(), 0);
    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.prestosql.operator.project.PageProjection) Block(io.prestosql.spi.block.Block) DriverYieldSignal(io.prestosql.operator.DriverYieldSignal) Test(org.testng.annotations.Test)

Aggregations

PageProjection (io.prestosql.operator.project.PageProjection)5 PageProcessor (io.prestosql.operator.project.PageProcessor)3 ImmutableList (com.google.common.collect.ImmutableList)2 ImmutableList.toImmutableList (com.google.common.collect.ImmutableList.toImmutableList)2 Block (io.prestosql.spi.block.Block)2 RowExpression (io.prestosql.spi.relation.RowExpression)2 PageFunctionCompiler (io.prestosql.sql.gen.PageFunctionCompiler)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 LoadingCache (com.google.common.cache.LoadingCache)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 DataSize (io.airlift.units.DataSize)1