Search in sources :

Example 96 with Symbol

use of io.prestosql.spi.plan.Symbol in project hetu-core by openlookeng.

the class SubqueryPlanner method planQuantifiedApplyNode.

private PlanBuilder planQuantifiedApplyNode(PlanBuilder inputSubPlan, QuantifiedComparisonExpression quantifiedComparison, boolean correlationAllowed) {
    PlanBuilder subPlan = inputSubPlan;
    subPlan = subPlan.appendProjections(ImmutableList.of(quantifiedComparison.getValue()), planSymbolAllocator, idAllocator);
    checkState(quantifiedComparison.getSubquery() instanceof SubqueryExpression);
    SubqueryExpression quantifiedSubquery = (SubqueryExpression) quantifiedComparison.getSubquery();
    SubqueryExpression uncoercedQuantifiedSubquery = uncoercedSubquery(quantifiedSubquery);
    PlanBuilder subqueryPlan = createPlanBuilder(uncoercedQuantifiedSubquery);
    subqueryPlan = subqueryPlan.appendProjections(ImmutableList.of(quantifiedSubquery), planSymbolAllocator, idAllocator);
    QuantifiedComparisonExpression coercedQuantifiedComparison = new QuantifiedComparisonExpression(quantifiedComparison.getOperator(), quantifiedComparison.getQuantifier(), toSymbolReference(subPlan.translate(quantifiedComparison.getValue())), toSymbolReference(subqueryPlan.translate(quantifiedSubquery)));
    Symbol coercedQuantifiedComparisonSymbol = planSymbolAllocator.newSymbol(coercedQuantifiedComparison, BOOLEAN);
    subPlan.getTranslations().put(quantifiedComparison, coercedQuantifiedComparisonSymbol);
    return appendApplyNode(subPlan, quantifiedComparison.getSubquery(), subqueryPlan.getRoot(), Assignments.of(coercedQuantifiedComparisonSymbol, castToRowExpression(coercedQuantifiedComparison)), correlationAllowed);
}
Also used : Symbol(io.prestosql.spi.plan.Symbol) QuantifiedComparisonExpression(io.prestosql.sql.tree.QuantifiedComparisonExpression) SubqueryExpression(io.prestosql.sql.tree.SubqueryExpression)

Example 97 with Symbol

use of io.prestosql.spi.plan.Symbol in project hetu-core by openlookeng.

the class SubqueryPlanner method appendScalarSubqueryApplyNode.

private PlanBuilder appendScalarSubqueryApplyNode(PlanBuilder subPlan, SubqueryExpression scalarSubquery, boolean correlationAllowed) {
    if (subPlan.canTranslate(scalarSubquery)) {
        // given subquery is already appended
        return subPlan;
    }
    List<Expression> coercions = coercionsFor(scalarSubquery);
    SubqueryExpression uncoercedScalarSubquery = uncoercedSubquery(scalarSubquery);
    PlanBuilder subqueryPlan = createPlanBuilder(uncoercedScalarSubquery);
    subqueryPlan = subqueryPlan.withNewRoot(new EnforceSingleRowNode(idAllocator.getNextId(), subqueryPlan.getRoot()));
    subqueryPlan = subqueryPlan.appendProjections(coercions, planSymbolAllocator, idAllocator);
    Symbol uncoercedScalarSubquerySymbol = subqueryPlan.translate(uncoercedScalarSubquery);
    subPlan.getTranslations().put(uncoercedScalarSubquery, uncoercedScalarSubquerySymbol);
    for (Expression coercion : coercions) {
        Symbol coercionSymbol = subqueryPlan.translate(coercion);
        subPlan.getTranslations().put(coercion, coercionSymbol);
    }
    // The subquery's EnforceSingleRowNode always produces a row, so the join is effectively INNER
    return appendLateralJoin(subPlan, subqueryPlan, scalarSubquery.getQuery(), correlationAllowed, LateralJoinNode.Type.INNER, TRUE_LITERAL);
}
Also used : OriginalExpressionUtils.castToRowExpression(io.prestosql.sql.relational.OriginalExpressionUtils.castToRowExpression) OriginalExpressionUtils.castToExpression(io.prestosql.sql.relational.OriginalExpressionUtils.castToExpression) SubqueryExpression(io.prestosql.sql.tree.SubqueryExpression) ExpressionNodeInliner.replaceExpression(io.prestosql.sql.planner.ExpressionNodeInliner.replaceExpression) DereferenceExpression(io.prestosql.sql.tree.DereferenceExpression) NotExpression(io.prestosql.sql.tree.NotExpression) QuantifiedComparisonExpression(io.prestosql.sql.tree.QuantifiedComparisonExpression) RowExpression(io.prestosql.spi.relation.RowExpression) Expression(io.prestosql.sql.tree.Expression) Symbol(io.prestosql.spi.plan.Symbol) EnforceSingleRowNode(io.prestosql.sql.planner.plan.EnforceSingleRowNode) SubqueryExpression(io.prestosql.sql.tree.SubqueryExpression)

Example 98 with Symbol

use of io.prestosql.spi.plan.Symbol in project hetu-core by openlookeng.

the class SubqueryPlanner method appendInPredicateApplyNode.

private PlanBuilder appendInPredicateApplyNode(PlanBuilder inputSubPlan, InPredicate inPredicate, boolean correlationAllowed, Node node) {
    PlanBuilder subPlan = inputSubPlan;
    if (subPlan.canTranslate(inPredicate)) {
        // given subquery is already appended
        return subPlan;
    }
    subPlan = handleSubqueries(subPlan, inPredicate.getValue(), node);
    subPlan = subPlan.appendProjections(ImmutableList.of(inPredicate.getValue()), planSymbolAllocator, idAllocator);
    checkState(inPredicate.getValueList() instanceof SubqueryExpression);
    SubqueryExpression valueListSubquery = (SubqueryExpression) inPredicate.getValueList();
    SubqueryExpression uncoercedValueListSubquery = uncoercedSubquery(valueListSubquery);
    PlanBuilder subqueryPlan = createPlanBuilder(uncoercedValueListSubquery);
    subqueryPlan = subqueryPlan.appendProjections(ImmutableList.of(valueListSubquery), planSymbolAllocator, idAllocator);
    SymbolReference valueList = toSymbolReference(subqueryPlan.translate(valueListSubquery));
    Symbol rewrittenValue = subPlan.translate(inPredicate.getValue());
    InPredicate inPredicateSubqueryExpression = new InPredicate(toSymbolReference(rewrittenValue), valueList);
    Symbol inPredicateSubquerySymbol = planSymbolAllocator.newSymbol(inPredicateSubqueryExpression, BOOLEAN);
    subPlan.getTranslations().put(inPredicate, inPredicateSubquerySymbol);
    return appendApplyNode(subPlan, inPredicate, subqueryPlan.getRoot(), Assignments.of(inPredicateSubquerySymbol, castToRowExpression(inPredicateSubqueryExpression)), correlationAllowed);
}
Also used : SymbolUtils.toSymbolReference(io.prestosql.sql.planner.SymbolUtils.toSymbolReference) SymbolReference(io.prestosql.sql.tree.SymbolReference) Symbol(io.prestosql.spi.plan.Symbol) InPredicate(io.prestosql.sql.tree.InPredicate) SubqueryExpression(io.prestosql.sql.tree.SubqueryExpression)

Example 99 with Symbol

use of io.prestosql.spi.plan.Symbol in project hetu-core by openlookeng.

the class SubqueryPlanner method appendExistSubqueryApplyNode.

/**
 * Exists is modeled as:
 * <pre>
 *     - Project($0 > 0)
 *       - Aggregation(COUNT(*))
 *         - Limit(1)
 *           -- subquery
 * </pre>
 */
private PlanBuilder appendExistSubqueryApplyNode(PlanBuilder subPlan, ExistsPredicate existsPredicate, boolean correlationAllowed) {
    if (subPlan.canTranslate(existsPredicate)) {
        // given subquery is already appended
        return subPlan;
    }
    PlanBuilder subqueryPlan = createPlanBuilder(existsPredicate.getSubquery());
    PlanNode subqueryPlanRoot = subqueryPlan.getRoot();
    if (isAggregationWithEmptyGroupBy(subqueryPlanRoot)) {
        subPlan.getTranslations().put(existsPredicate, TRUE_LITERAL);
        return subPlan;
    }
    // add an explicit projection that removes all columns
    PlanNode subqueryNode = new ProjectNode(idAllocator.getNextId(), subqueryPlan.getRoot(), Assignments.of());
    Symbol exists = planSymbolAllocator.newSymbol("exists", BOOLEAN);
    subPlan.getTranslations().put(existsPredicate, exists);
    ExistsPredicate rewrittenExistsPredicate = new ExistsPredicate(TRUE_LITERAL);
    return appendApplyNode(subPlan, existsPredicate.getSubquery(), subqueryNode, Assignments.of(exists, castToRowExpression(rewrittenExistsPredicate)), correlationAllowed);
}
Also used : PlanNode(io.prestosql.spi.plan.PlanNode) Symbol(io.prestosql.spi.plan.Symbol) ExistsPredicate(io.prestosql.sql.tree.ExistsPredicate) ProjectNode(io.prestosql.spi.plan.ProjectNode)

Example 100 with Symbol

use of io.prestosql.spi.plan.Symbol in project hetu-core by openlookeng.

the class LocalDynamicFilter method create.

public static Optional<LocalDynamicFilter> create(JoinNode planNode, int partitionCount, Session session, TaskId taskId, StateStoreProvider stateStoreProvider) {
    Set<String> joinDynamicFilters = planNode.getDynamicFilters().keySet();
    // Mapping from probe-side dynamic filters' IDs to their matching probe symbols.
    Multimap<String, Symbol> localProbeSymbols = MultimapBuilder.treeKeys().arrayListValues().build();
    PlanNode buildNode;
    DynamicFilter.Type localType = DynamicFilter.Type.LOCAL;
    List<FilterNode> filterNodes = findFilterNodeInStage(planNode);
    if (filterNodes.isEmpty()) {
        buildNode = planNode.getRight();
        mapProbeSymbolsFromCriteria(planNode.getDynamicFilters(), localProbeSymbols, planNode.getCriteria());
        localType = DynamicFilter.Type.GLOBAL;
    } else {
        buildNode = planNode.getRight();
        for (FilterNode filterNode : filterNodes) {
            mapProbeSymbols(filterNode.getPredicate(), joinDynamicFilters, localProbeSymbols);
        }
    }
    final List<Symbol> buildSideSymbols = buildNode.getOutputSymbols();
    Map<String, Integer> localBuildChannels = planNode.getDynamicFilters().entrySet().stream().filter(entry -> localProbeSymbols.containsKey(entry.getKey())).collect(toMap(// Dynamic filter ID
    entry -> entry.getKey(), // Build-side channel index
    entry -> {
        Symbol buildSymbol = entry.getValue();
        int buildChannelIndex = buildSideSymbols.indexOf(buildSymbol);
        verify(buildChannelIndex >= 0);
        return buildChannelIndex;
    }));
    if (localBuildChannels.isEmpty()) {
        return Optional.empty();
    }
    return Optional.of(new LocalDynamicFilter(localProbeSymbols, localBuildChannels, partitionCount, localType, session, taskId, stateStoreProvider));
}
Also used : DynamicFilter(io.prestosql.spi.dynamicfilter.DynamicFilter) MultimapBuilder(com.google.common.collect.MultimapBuilder) StateStore(io.prestosql.spi.statestore.StateStore) DynamicFilterUtils.findFilterNodeInStage(io.prestosql.utils.DynamicFilterUtils.findFilterNodeInStage) SettableFuture(com.google.common.util.concurrent.SettableFuture) FilterNode(io.prestosql.spi.plan.FilterNode) Collectors.toMap(java.util.stream.Collectors.toMap) PARTIALPREFIX(io.prestosql.utils.DynamicFilterUtils.PARTIALPREFIX) Map(java.util.Map) DynamicFilterSourceOperator(io.prestosql.operator.DynamicFilterSourceOperator) SystemSessionProperties.getDynamicFilteringDataType(io.prestosql.SystemSessionProperties.getDynamicFilteringDataType) ImmutableMap(com.google.common.collect.ImmutableMap) SystemSessionProperties.getDynamicFilteringBloomFilterFpp(io.prestosql.SystemSessionProperties.getDynamicFilteringBloomFilterFpp) Set(java.util.Set) DynamicFilters(io.prestosql.sql.DynamicFilters) PlanNode(io.prestosql.spi.plan.PlanNode) StateSet(io.prestosql.spi.statestore.StateSet) DynamicFilterUtils.getDynamicFilterDataType(io.prestosql.utils.DynamicFilterUtils.getDynamicFilterDataType) StandardCharsets(java.nio.charset.StandardCharsets) List(java.util.List) Optional(java.util.Optional) TaskId(io.prestosql.execution.TaskId) ListenableFuture(com.google.common.util.concurrent.ListenableFuture) Slice(io.airlift.slice.Slice) Logger(io.airlift.log.Logger) DynamicFilters.extractDynamicFilters(io.prestosql.sql.DynamicFilters.extractDynamicFilters) HashMap(java.util.HashMap) Multimap(com.google.common.collect.Multimap) SemiJoinNode(io.prestosql.sql.planner.plan.SemiJoinNode) TASKSPREFIX(io.prestosql.utils.DynamicFilterUtils.TASKSPREFIX) HashSet(java.util.HashSet) BloomFilter(io.prestosql.spi.util.BloomFilter) Verify.verify(com.google.common.base.Verify.verify) Objects.requireNonNull(java.util.Objects.requireNonNull) Session(io.prestosql.Session) BloomFilterDynamicFilter(io.prestosql.spi.dynamicfilter.BloomFilterDynamicFilter) ImmutableMultimap(com.google.common.collect.ImmutableMultimap) JoinNode(io.prestosql.spi.plan.JoinNode) Symbol(io.prestosql.spi.plan.Symbol) Descriptor(io.prestosql.sql.DynamicFilters.Descriptor) TupleDomain(io.prestosql.spi.predicate.TupleDomain) BLOOM_FILTER(io.prestosql.spi.dynamicfilter.DynamicFilter.DataType.BLOOM_FILTER) VariableReferenceExpression(io.prestosql.spi.relation.VariableReferenceExpression) Consumer(java.util.function.Consumer) DynamicFilterUtils.createKey(io.prestosql.utils.DynamicFilterUtils.createKey) StateStoreProvider(io.prestosql.statestore.StateStoreProvider) RowExpression(io.prestosql.spi.relation.RowExpression) FeaturesConfig(io.prestosql.sql.analyzer.FeaturesConfig) BloomFilterDynamicFilter.convertBloomFilterToByteArray(io.prestosql.spi.dynamicfilter.BloomFilterDynamicFilter.convertBloomFilterToByteArray) SET(io.prestosql.spi.statestore.StateCollection.Type.SET) DynamicFilter(io.prestosql.spi.dynamicfilter.DynamicFilter) BloomFilterDynamicFilter(io.prestosql.spi.dynamicfilter.BloomFilterDynamicFilter) Symbol(io.prestosql.spi.plan.Symbol) FilterNode(io.prestosql.spi.plan.FilterNode) PlanNode(io.prestosql.spi.plan.PlanNode)

Aggregations

Symbol (io.prestosql.spi.plan.Symbol)352 Test (org.testng.annotations.Test)116 ImmutableList (com.google.common.collect.ImmutableList)115 PlanNode (io.prestosql.spi.plan.PlanNode)110 ImmutableMap (com.google.common.collect.ImmutableMap)104 RowExpression (io.prestosql.spi.relation.RowExpression)101 Optional (java.util.Optional)92 Map (java.util.Map)85 Expression (io.prestosql.sql.tree.Expression)79 ProjectNode (io.prestosql.spi.plan.ProjectNode)75 Type (io.prestosql.spi.type.Type)72 JoinNode (io.prestosql.spi.plan.JoinNode)69 List (java.util.List)69 Assignments (io.prestosql.spi.plan.Assignments)65 ColumnHandle (io.prestosql.spi.connector.ColumnHandle)63 AggregationNode (io.prestosql.spi.plan.AggregationNode)60 ImmutableList.toImmutableList (com.google.common.collect.ImmutableList.toImmutableList)57 VariableReferenceExpression (io.prestosql.spi.relation.VariableReferenceExpression)57 HashMap (java.util.HashMap)57 TableScanNode (io.prestosql.spi.plan.TableScanNode)56