Search in sources :

Example 1 with InputPageProjection

use of io.prestosql.operator.project.InputPageProjection 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 2 with InputPageProjection

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

the class PageFunctionCompiler method compileProjectionInternal.

private Supplier<PageProjection> compileProjectionInternal(RowExpression projection, Optional<String> classNameSuffix) {
    requireNonNull(projection, "projection is null");
    if (projection instanceof InputReferenceExpression) {
        InputReferenceExpression input = (InputReferenceExpression) projection;
        InputPageProjection projectionFunction = new InputPageProjection(input.getField(), input.getType());
        return () -> projectionFunction;
    }
    if (projection instanceof ConstantExpression) {
        ConstantExpression constant = (ConstantExpression) projection;
        ConstantPageProjection projectionFunction = new ConstantPageProjection(constant.getValue(), constant.getType());
        return () -> projectionFunction;
    }
    PageFieldsToInputParametersRewriter.Result result = rewritePageFieldsToInputParameters(projection);
    CallSiteBinder callSiteBinder = new CallSiteBinder();
    // generate Work
    ClassDefinition pageProjectionWorkDefinition = definePageProjectWorkClass(result.getRewrittenExpression(), callSiteBinder, classNameSuffix);
    Class<?> pageProjectionWorkClass;
    try {
        pageProjectionWorkClass = defineClass(pageProjectionWorkDefinition, Work.class, callSiteBinder.getBindings(), getClass().getClassLoader());
    } catch (Exception e) {
        throw new PrestoException(COMPILER_ERROR, e);
    }
    return () -> new GeneratedPageProjection(result.getRewrittenExpression(), determinismEvaluator.isDeterministic(result.getRewrittenExpression()), result.getInputChannels(), constructorMethodHandle(pageProjectionWorkClass, BlockBuilder.class, ConnectorSession.class, Page.class, SelectedPositions.class));
}
Also used : InputReferenceExpression(io.prestosql.spi.relation.InputReferenceExpression) ConstantPageProjection(io.prestosql.operator.project.ConstantPageProjection) ConstantExpression(io.prestosql.spi.relation.ConstantExpression) PrestoException(io.prestosql.spi.PrestoException) GeneratedPageProjection(io.prestosql.operator.project.GeneratedPageProjection) Page(io.prestosql.spi.Page) ClassDefinition(io.airlift.bytecode.ClassDefinition) PrestoException(io.prestosql.spi.PrestoException) InputPageProjection(io.prestosql.operator.project.InputPageProjection) PageFieldsToInputParametersRewriter(io.prestosql.operator.project.PageFieldsToInputParametersRewriter) SelectedPositions(io.prestosql.operator.project.SelectedPositions) Work(io.prestosql.operator.Work) ConnectorSession(io.prestosql.spi.connector.ConnectorSession) BlockBuilder(io.prestosql.spi.block.BlockBuilder)

Aggregations

InputPageProjection (io.prestosql.operator.project.InputPageProjection)2 ImmutableList (com.google.common.collect.ImmutableList)1 ImmutableList.toImmutableList (com.google.common.collect.ImmutableList.toImmutableList)1 ImmutableMap (com.google.common.collect.ImmutableMap)1 ClassDefinition (io.airlift.bytecode.ClassDefinition)1 Work (io.prestosql.operator.Work)1 ConstantPageProjection (io.prestosql.operator.project.ConstantPageProjection)1 GeneratedPageProjection (io.prestosql.operator.project.GeneratedPageProjection)1 PageFieldsToInputParametersRewriter (io.prestosql.operator.project.PageFieldsToInputParametersRewriter)1 PageProcessor (io.prestosql.operator.project.PageProcessor)1 PageProjection (io.prestosql.operator.project.PageProjection)1 SelectedPositions (io.prestosql.operator.project.SelectedPositions)1 Page (io.prestosql.spi.Page)1 PrestoException (io.prestosql.spi.PrestoException)1 BlockBuilder (io.prestosql.spi.block.BlockBuilder)1 ConnectorSession (io.prestosql.spi.connector.ConnectorSession)1 Symbol (io.prestosql.spi.plan.Symbol)1 ConstantExpression (io.prestosql.spi.relation.ConstantExpression)1 InputReferenceExpression (io.prestosql.spi.relation.InputReferenceExpression)1 RowExpression (io.prestosql.spi.relation.RowExpression)1