Search in sources :

Example 21 with PlanNode

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

the class JoinMatcher method detailMatches.

@Override
public MatchResult detailMatches(PlanNode node, StatsProvider stats, Session session, Metadata metadata, SymbolAliases symbolAliases) {
    checkState(shapeMatches(node), "Plan testing framework error: shapeMatches returned false in detailMatches in %s", this.getClass().getName());
    JoinNode joinNode = (JoinNode) node;
    if (joinNode.getCriteria().size() != equiCriteria.size()) {
        return NO_MATCH;
    }
    if (filter.isPresent()) {
        if (!joinNode.getFilter().isPresent()) {
            return NO_MATCH;
        }
        RowExpression expression = joinNode.getFilter().get();
        if (isExpression(expression)) {
            if (!new ExpressionVerifier(symbolAliases).process(castToExpression(expression), filter.get())) {
                return NO_MATCH;
            }
        } else {
            if (!new RowExpressionVerifier(symbolAliases, metadata, session, node.getOutputSymbols()).process(filter.get(), expression)) {
                return NO_MATCH;
            }
        }
    } else {
        if (joinNode.getFilter().isPresent()) {
            return NO_MATCH;
        }
    }
    if (distributionType.isPresent() && !distributionType.equals(joinNode.getDistributionType())) {
        return NO_MATCH;
    }
    if (spillable.isPresent() && !spillable.equals(joinNode.isSpillable())) {
        return NO_MATCH;
    }
    /*
         * Have to use order-independent comparison; there are no guarantees what order
         * the equi criteria will have after planning and optimizing.
         */
    Set<JoinNode.EquiJoinClause> actual = ImmutableSet.copyOf(joinNode.getCriteria());
    Set<JoinNode.EquiJoinClause> expected = equiCriteria.stream().map(maker -> maker.getExpectedValue(symbolAliases)).collect(toImmutableSet());
    if (!expected.equals(actual)) {
        return NO_MATCH;
    }
    if (dynamicFilter.isPresent() && !dynamicFilter.get().match(joinNode, symbolAliases).isMatch()) {
        return NO_MATCH;
    }
    return MatchResult.match();
}
Also used : ImmutableSet(com.google.common.collect.ImmutableSet) StatsProvider(io.prestosql.cost.StatsProvider) Set(java.util.Set) PlanNode(io.prestosql.spi.plan.PlanNode) Metadata(io.prestosql.metadata.Metadata) Preconditions.checkState(com.google.common.base.Preconditions.checkState) OriginalExpressionUtils.isExpression(io.prestosql.sql.relational.OriginalExpressionUtils.isExpression) List(java.util.List) DistributionType(io.prestosql.spi.plan.JoinNode.DistributionType) Objects.requireNonNull(java.util.Objects.requireNonNull) Session(io.prestosql.Session) RowExpression(io.prestosql.spi.relation.RowExpression) Optional(java.util.Optional) ImmutableSet.toImmutableSet(com.google.common.collect.ImmutableSet.toImmutableSet) OriginalExpressionUtils.castToExpression(io.prestosql.sql.relational.OriginalExpressionUtils.castToExpression) NO_MATCH(io.prestosql.sql.planner.assertions.MatchResult.NO_MATCH) Expression(io.prestosql.sql.tree.Expression) JoinNode(io.prestosql.spi.plan.JoinNode) MoreObjects.toStringHelper(com.google.common.base.MoreObjects.toStringHelper) JoinNode(io.prestosql.spi.plan.JoinNode) RowExpression(io.prestosql.spi.relation.RowExpression)

Example 22 with PlanNode

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

the class TestPruneWindowColumns method buildProjectedWindow.

private static PlanNode buildProjectedWindow(PlanBuilder p, Predicate<Symbol> projectionFilter, Predicate<Symbol> sourceFilter) {
    Symbol orderKey = p.symbol("orderKey");
    Symbol partitionKey = p.symbol("partitionKey");
    Symbol hash = p.symbol("hash");
    Symbol startValue1 = p.symbol("startValue1");
    Symbol startValue2 = p.symbol("startValue2");
    Symbol endValue1 = p.symbol("endValue1");
    Symbol endValue2 = p.symbol("endValue2");
    Symbol input1 = p.symbol("input1");
    Symbol input2 = p.symbol("input2");
    Symbol unused = p.symbol("unused");
    Symbol output1 = p.symbol("output1");
    Symbol output2 = p.symbol("output2");
    List<Symbol> inputs = ImmutableList.of(orderKey, partitionKey, hash, startValue1, startValue2, endValue1, endValue2, input1, input2, unused);
    List<Symbol> outputs = ImmutableList.<Symbol>builder().addAll(inputs).add(output1, output2).build();
    return p.project(Assignments.copyOf(outputs.stream().filter(projectionFilter).collect(Collectors.toMap(v -> v, v -> p.variable(v.getName(), BIGINT)))), p.window(new WindowNode.Specification(ImmutableList.of(partitionKey), Optional.of(new OrderingScheme(ImmutableList.of(orderKey), ImmutableMap.of(orderKey, SortOrder.ASC_NULLS_FIRST)))), ImmutableMap.of(output1, new WindowNode.Function(call(FUNCTION_NAME, FUNCTION_HANDLE, BIGINT, ImmutableList.of(p.variable(input1.getName()))), ImmutableList.of(p.variable(input1.getName())), new WindowNode.Frame(WindowFrameType.RANGE, UNBOUNDED_PRECEDING, Optional.of(startValue1), CURRENT_ROW, Optional.of(endValue1), Optional.of(startValue1.getName()), Optional.of(endValue2.getName()))), output2, new WindowNode.Function(call(FUNCTION_NAME, FUNCTION_HANDLE, BIGINT, ImmutableList.of(p.variable(input2.getName()))), ImmutableList.of(p.variable(input2.getName())), new WindowNode.Frame(WindowFrameType.RANGE, UNBOUNDED_PRECEDING, Optional.of(startValue2), CURRENT_ROW, Optional.of(endValue2), Optional.of(startValue2.getName()), Optional.of(endValue2.getName())))), hash, p.values(inputs.stream().filter(sourceFilter).collect(toImmutableList()), ImmutableList.of())));
}
Also used : BaseRuleTest(io.prestosql.sql.planner.iterative.rule.test.BaseRuleTest) UNBOUNDED_PRECEDING(io.prestosql.spi.sql.expression.Types.FrameBoundType.UNBOUNDED_PRECEDING) Test(org.testng.annotations.Test) SortOrder(io.prestosql.spi.block.SortOrder) Predicates.alwaysTrue(com.google.common.base.Predicates.alwaysTrue) PlanMatchPattern.values(io.prestosql.sql.planner.assertions.PlanMatchPattern.values) PlanMatchPattern.windowFrame(io.prestosql.sql.planner.assertions.PlanMatchPattern.windowFrame) ImmutableList(com.google.common.collect.ImmutableList) Expressions.call(io.prestosql.sql.relational.Expressions.call) OrderingScheme(io.prestosql.spi.plan.OrderingScheme) PlanMatchPattern.functionCall(io.prestosql.sql.planner.assertions.PlanMatchPattern.functionCall) ExpectedValueProvider(io.prestosql.sql.planner.assertions.ExpectedValueProvider) BIGINT(io.prestosql.spi.type.BigintType.BIGINT) PlanMatchPattern.expression(io.prestosql.sql.planner.assertions.PlanMatchPattern.expression) PlanMatchPattern.window(io.prestosql.sql.planner.assertions.PlanMatchPattern.window) Symbol(io.prestosql.spi.plan.Symbol) ImmutableSet(com.google.common.collect.ImmutableSet) TypeSignatureProvider.fromTypes(io.prestosql.sql.analyzer.TypeSignatureProvider.fromTypes) WindowFrameType(io.prestosql.spi.sql.expression.Types.WindowFrameType) ImmutableMap(com.google.common.collect.ImmutableMap) Assignments(io.prestosql.spi.plan.Assignments) PlanMatchPattern.strictProject(io.prestosql.sql.planner.assertions.PlanMatchPattern.strictProject) Predicate(java.util.function.Predicate) MetadataManager.createTestMetadataManager(io.prestosql.metadata.MetadataManager.createTestMetadataManager) PlanMatchPattern(io.prestosql.sql.planner.assertions.PlanMatchPattern) ImmutableList.toImmutableList(com.google.common.collect.ImmutableList.toImmutableList) Set(java.util.Set) PlanNode(io.prestosql.spi.plan.PlanNode) Maps(com.google.common.collect.Maps) Collectors(java.util.stream.Collectors) Sets(com.google.common.collect.Sets) FunctionHandle(io.prestosql.spi.function.FunctionHandle) List(java.util.List) WindowNode(io.prestosql.spi.plan.WindowNode) Optional(java.util.Optional) PlanBuilder(io.prestosql.sql.planner.iterative.rule.test.PlanBuilder) CURRENT_ROW(io.prestosql.spi.sql.expression.Types.FrameBoundType.CURRENT_ROW) OrderingScheme(io.prestosql.spi.plan.OrderingScheme) WindowNode(io.prestosql.spi.plan.WindowNode) PlanMatchPattern.windowFrame(io.prestosql.sql.planner.assertions.PlanMatchPattern.windowFrame) Symbol(io.prestosql.spi.plan.Symbol)

Example 23 with PlanNode

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

the class TestMemo method testInsertNode.

/*
       From: X -> Z
       To:   X -> Y -> Z
     */
@Test
public void testInsertNode() {
    PlanNode z = node();
    PlanNode x = node(z);
    Memo memo = new Memo(idAllocator, x);
    assertEquals(memo.getGroupCount(), 2);
    int zGroup = getChildGroup(memo, memo.getRootGroup());
    PlanNode y = node(memo.getNode(zGroup));
    memo.replace(zGroup, y, "rule");
    assertEquals(memo.getGroupCount(), 3);
    assertMatchesStructure(memo.extract(), node(x.getId(), node(y.getId(), node(z.getId()))));
}
Also used : PlanNode(io.prestosql.spi.plan.PlanNode) Test(org.testng.annotations.Test)

Example 24 with PlanNode

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

the class TestMemo method testMultipleReferences.

/*
      From: X -> Y -> Z
      To:   X --> Y1' --> Z
              \-> Y2' -/
     */
@Test
public void testMultipleReferences() {
    PlanNode z = node();
    PlanNode y = node(z);
    PlanNode x = node(y);
    Memo memo = new Memo(idAllocator, x);
    assertEquals(memo.getGroupCount(), 3);
    int yGroup = getChildGroup(memo, memo.getRootGroup());
    PlanNode rewrittenZ = memo.getNode(yGroup).getSources().get(0);
    PlanNode y1 = node(rewrittenZ);
    PlanNode y2 = node(rewrittenZ);
    PlanNode newX = node(y1, y2);
    memo.replace(memo.getRootGroup(), newX, "rule");
    assertEquals(memo.getGroupCount(), 4);
    assertMatchesStructure(memo.extract(), node(newX.getId(), node(y1.getId(), node(z.getId())), node(y2.getId(), node(z.getId()))));
}
Also used : PlanNode(io.prestosql.spi.plan.PlanNode) Test(org.testng.annotations.Test)

Example 25 with PlanNode

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

the class TestMemo method getChildGroup.

private int getChildGroup(Memo memo, int group) {
    PlanNode node = memo.getNode(group);
    GroupReference child = (GroupReference) node.getSources().get(0);
    return child.getGroupId();
}
Also used : PlanNode(io.prestosql.spi.plan.PlanNode) GroupReference(io.prestosql.spi.plan.GroupReference)

Aggregations

PlanNode (io.prestosql.spi.plan.PlanNode)241 Test (org.testng.annotations.Test)100 Symbol (io.prestosql.spi.plan.Symbol)98 RowExpression (io.prestosql.spi.relation.RowExpression)52 ImmutableList (com.google.common.collect.ImmutableList)49 ProjectNode (io.prestosql.spi.plan.ProjectNode)46 Expression (io.prestosql.sql.tree.Expression)46 TableScanNode (io.prestosql.spi.plan.TableScanNode)45 JoinNode (io.prestosql.spi.plan.JoinNode)42 Optional (java.util.Optional)42 OriginalExpressionUtils.castToRowExpression (io.prestosql.sql.relational.OriginalExpressionUtils.castToRowExpression)41 FilterNode (io.prestosql.spi.plan.FilterNode)39 CallExpression (io.prestosql.spi.relation.CallExpression)39 ImmutableMap (com.google.common.collect.ImmutableMap)38 List (java.util.List)38 Map (java.util.Map)36 AggregationNode (io.prestosql.spi.plan.AggregationNode)35 BasePlanTest (io.prestosql.sql.planner.assertions.BasePlanTest)34 Assignments (io.prestosql.spi.plan.Assignments)33 ComparisonExpression (io.prestosql.sql.tree.ComparisonExpression)32