Search in sources :

Example 26 with NodeRef

use of io.trino.sql.tree.NodeRef in project trino by trinodb.

the class PartialTranslator method extractPartialTranslations.

/**
 * Produces {@link ConnectorExpression} translations for disjoint components in the {@param inputExpression} in a
 * top-down manner. i.e. if an expression node is translatable, we do not consider its children.
 */
public static Map<NodeRef<Expression>, ConnectorExpression> extractPartialTranslations(Expression inputExpression, Session session, TypeAnalyzer typeAnalyzer, TypeProvider typeProvider, PlannerContext plannerContext) {
    requireNonNull(inputExpression, "inputExpression is null");
    requireNonNull(session, "session is null");
    requireNonNull(typeAnalyzer, "typeAnalyzer is null");
    requireNonNull(typeProvider, "typeProvider is null");
    Map<NodeRef<Expression>, ConnectorExpression> partialTranslations = new HashMap<>();
    new Visitor(session, typeAnalyzer.getTypes(session, typeProvider, inputExpression), partialTranslations, plannerContext).process(inputExpression);
    return ImmutableMap.copyOf(partialTranslations);
}
Also used : NodeRef(io.trino.sql.tree.NodeRef) AstVisitor(io.trino.sql.tree.AstVisitor) HashMap(java.util.HashMap) ConnectorExpression(io.trino.spi.expression.ConnectorExpression)

Example 27 with NodeRef

use of io.trino.sql.tree.NodeRef 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

NodeRef (io.trino.sql.tree.NodeRef)27 Type (io.trino.spi.type.Type)19 Expression (io.trino.sql.tree.Expression)18 List (java.util.List)9 Map (java.util.Map)9 Objects.requireNonNull (java.util.Objects.requireNonNull)9 ImmutableList.toImmutableList (com.google.common.collect.ImmutableList.toImmutableList)8 ImmutableMap (com.google.common.collect.ImmutableMap)8 Optional (java.util.Optional)8 ImmutableList (com.google.common.collect.ImmutableList)7 Session (io.trino.Session)7 PlannerContext (io.trino.sql.PlannerContext)7 ExpressionInterpreter (io.trino.sql.planner.ExpressionInterpreter)7 HashMap (java.util.HashMap)7 DecimalType.createDecimalType (io.trino.spi.type.DecimalType.createDecimalType)6 TrinoException (io.trino.spi.TrinoException)5 Parameter (io.trino.sql.tree.Parameter)5 LinkedHashMap (java.util.LinkedHashMap)5 Set (java.util.Set)5 Verify.verify (com.google.common.base.Verify.verify)4