Search in sources :

Example 1 with InputPageProjection

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

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) {
        if (Throwables.getRootCause(e) instanceof MethodTooLargeException) {
            throw new TrinoException(COMPILER_ERROR, "Query exceeded maximum columns. Please reduce the number of columns referenced and re-run the query.", e);
        }
        throw new TrinoException(COMPILER_ERROR, e);
    }
    return () -> new GeneratedPageProjection(result.getRewrittenExpression(), isDeterministic(result.getRewrittenExpression()), result.getInputChannels(), constructorMethodHandle(pageProjectionWorkClass, BlockBuilder.class, ConnectorSession.class, Page.class, SelectedPositions.class));
}
Also used : InputReferenceExpression(io.trino.sql.relational.InputReferenceExpression) ConstantPageProjection(io.trino.operator.project.ConstantPageProjection) ConstantExpression(io.trino.sql.relational.ConstantExpression) GeneratedPageProjection(io.trino.operator.project.GeneratedPageProjection) Page(io.trino.spi.Page) ClassDefinition(io.airlift.bytecode.ClassDefinition) TrinoException(io.trino.spi.TrinoException) MethodTooLargeException(org.objectweb.asm.MethodTooLargeException) InputPageProjection(io.trino.operator.project.InputPageProjection) PageFieldsToInputParametersRewriter(io.trino.operator.project.PageFieldsToInputParametersRewriter) MethodTooLargeException(org.objectweb.asm.MethodTooLargeException) SelectedPositions(io.trino.operator.project.SelectedPositions) Work(io.trino.operator.Work) TrinoException(io.trino.spi.TrinoException) ConnectorSession(io.trino.spi.connector.ConnectorSession) BlockBuilder(io.trino.spi.block.BlockBuilder)

Example 2 with InputPageProjection

use of io.trino.operator.project.InputPageProjection 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

InputPageProjection (io.trino.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.trino.operator.Work)1 ConstantPageProjection (io.trino.operator.project.ConstantPageProjection)1 GeneratedPageProjection (io.trino.operator.project.GeneratedPageProjection)1 PageFieldsToInputParametersRewriter (io.trino.operator.project.PageFieldsToInputParametersRewriter)1 PageProcessor (io.trino.operator.project.PageProcessor)1 PageProjection (io.trino.operator.project.PageProjection)1 SelectedPositions (io.trino.operator.project.SelectedPositions)1 Page (io.trino.spi.Page)1 TrinoException (io.trino.spi.TrinoException)1 BlockBuilder (io.trino.spi.block.BlockBuilder)1 ConnectorSession (io.trino.spi.connector.ConnectorSession)1 Type (io.trino.spi.type.Type)1 PageFunctionCompiler (io.trino.sql.gen.PageFunctionCompiler)1 Symbol (io.trino.sql.planner.Symbol)1 SymbolAllocator (io.trino.sql.planner.SymbolAllocator)1