Search in sources :

Example 76 with PlanNode

use of com.facebook.presto.spi.plan.PlanNode in project presto by prestodb.

the class TopNRowNumberMatcher 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());
    TopNRowNumberNode topNRowNumberNode = (TopNRowNumberNode) node;
    if (!specification.map(expectedSpecification -> matchSpecification(topNRowNumberNode.getSpecification(), expectedSpecification.getExpectedValue(symbolAliases))).orElse(true)) {
        return NO_MATCH;
    }
    if (!rowNumberSymbol.map(expectedRowNumberSymbol -> expectedRowNumberSymbol.toSymbol(symbolAliases).getName().equals(topNRowNumberNode.getRowNumberVariable().getName())).orElse(true)) {
        return NO_MATCH;
    }
    if (!maxRowCountPerPartition.map(expectedMaxRowCountPerPartition -> expectedMaxRowCountPerPartition.equals(topNRowNumberNode.getMaxRowCountPerPartition())).orElse(true)) {
        return NO_MATCH;
    }
    if (!partial.map(expectedPartial -> expectedPartial.equals(topNRowNumberNode.isPartial())).orElse(true)) {
        return NO_MATCH;
    }
    if (!hashSymbol.map(expectedHashSymbol -> expectedHashSymbol.map(symbolAlias -> symbolAlias.toSymbol(symbolAliases)).map(Symbol::getName).equals(topNRowNumberNode.getHashVariable().map(VariableReferenceExpression::getName))).orElse(true)) {
        return NO_MATCH;
    }
    return match();
}
Also used : SpecificationProvider.matchSpecification(com.facebook.presto.sql.planner.assertions.SpecificationProvider.matchSpecification) SortOrder(com.facebook.presto.common.block.SortOrder) WindowNode(com.facebook.presto.sql.planner.plan.WindowNode) Session(com.facebook.presto.Session) StatsProvider(com.facebook.presto.cost.StatsProvider) VariableReferenceExpression(com.facebook.presto.spi.relation.VariableReferenceExpression) Preconditions.checkState(com.google.common.base.Preconditions.checkState) PlanNode(com.facebook.presto.spi.plan.PlanNode) List(java.util.List) Symbol(com.facebook.presto.sql.planner.Symbol) TopNRowNumberNode(com.facebook.presto.sql.planner.plan.TopNRowNumberNode) Map(java.util.Map) MatchResult.match(com.facebook.presto.sql.planner.assertions.MatchResult.match) Objects.requireNonNull(java.util.Objects.requireNonNull) Optional(java.util.Optional) NO_MATCH(com.facebook.presto.sql.planner.assertions.MatchResult.NO_MATCH) Metadata(com.facebook.presto.metadata.Metadata) PlanMatchPattern.node(com.facebook.presto.sql.planner.assertions.PlanMatchPattern.node) MoreObjects.toStringHelper(com.google.common.base.MoreObjects.toStringHelper) TopNRowNumberNode(com.facebook.presto.sql.planner.plan.TopNRowNumberNode) Symbol(com.facebook.presto.sql.planner.Symbol) VariableReferenceExpression(com.facebook.presto.spi.relation.VariableReferenceExpression)

Example 77 with PlanNode

use of com.facebook.presto.spi.plan.PlanNode in project presto by prestodb.

the class ValuesMatcher 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());
    ValuesNode valuesNode = (ValuesNode) node;
    if (!expectedRows.map(rows -> rows.equals(valuesNode.getRows().stream().map(rowExpressions -> rowExpressions.stream().map(rowExpression -> {
        if (isExpression(rowExpression)) {
            return castToExpression(rowExpression);
        }
        ConstantExpression expression = (ConstantExpression) rowExpression;
        if (expression.getType().getJavaType() == boolean.class) {
            return new BooleanLiteral(String.valueOf(expression.getValue()));
        }
        if (expression.getType().getJavaType() == long.class) {
            return new LongLiteral(String.valueOf(expression.getValue()));
        }
        if (expression.getType().getJavaType() == double.class) {
            return new DoubleLiteral(String.valueOf(expression.getValue()));
        }
        if (expression.getType().getJavaType() == Slice.class) {
            return new StringLiteral(((Slice) expression.getValue()).toStringUtf8());
        }
        return new GenericLiteral(expression.getType().toString(), String.valueOf(expression.getValue()));
    }).collect(toImmutableList())).collect(toImmutableSet()))).orElse(true)) {
        return NO_MATCH;
    }
    return match(SymbolAliases.builder().putAll(Maps.transformValues(outputSymbolAliases, index -> createSymbolReference(valuesNode.getOutputVariables().get(index)))).build());
}
Also used : Slice(io.airlift.slice.Slice) OriginalExpressionUtils.isExpression(com.facebook.presto.sql.relational.OriginalExpressionUtils.isExpression) ConstantExpression(com.facebook.presto.spi.relation.ConstantExpression) ValuesNode(com.facebook.presto.spi.plan.ValuesNode) StringLiteral(com.facebook.presto.sql.tree.StringLiteral) OriginalExpressionUtils.castToExpression(com.facebook.presto.sql.relational.OriginalExpressionUtils.castToExpression) DoubleLiteral(com.facebook.presto.sql.tree.DoubleLiteral) Map(java.util.Map) Objects.requireNonNull(java.util.Objects.requireNonNull) ImmutableSet.toImmutableSet(com.google.common.collect.ImmutableSet.toImmutableSet) ImmutableSet(com.google.common.collect.ImmutableSet) ImmutableMap(com.google.common.collect.ImmutableMap) Session(com.facebook.presto.Session) ImmutableList.toImmutableList(com.google.common.collect.ImmutableList.toImmutableList) StatsProvider(com.facebook.presto.cost.StatsProvider) Set(java.util.Set) Maps(com.google.common.collect.Maps) Preconditions.checkState(com.google.common.base.Preconditions.checkState) BooleanLiteral(com.facebook.presto.sql.tree.BooleanLiteral) PlanNode(com.facebook.presto.spi.plan.PlanNode) List(java.util.List) GenericLiteral(com.facebook.presto.sql.tree.GenericLiteral) Expression(com.facebook.presto.sql.tree.Expression) MatchResult.match(com.facebook.presto.sql.planner.assertions.MatchResult.match) LongLiteral(com.facebook.presto.sql.tree.LongLiteral) Optional(java.util.Optional) NO_MATCH(com.facebook.presto.sql.planner.assertions.MatchResult.NO_MATCH) Metadata(com.facebook.presto.metadata.Metadata) ExpressionTreeUtils.createSymbolReference(com.facebook.presto.sql.analyzer.ExpressionTreeUtils.createSymbolReference) MoreObjects.toStringHelper(com.google.common.base.MoreObjects.toStringHelper) ValuesNode(com.facebook.presto.spi.plan.ValuesNode) StringLiteral(com.facebook.presto.sql.tree.StringLiteral) LongLiteral(com.facebook.presto.sql.tree.LongLiteral) BooleanLiteral(com.facebook.presto.sql.tree.BooleanLiteral) Slice(io.airlift.slice.Slice) ConstantExpression(com.facebook.presto.spi.relation.ConstantExpression) DoubleLiteral(com.facebook.presto.sql.tree.DoubleLiteral) GenericLiteral(com.facebook.presto.sql.tree.GenericLiteral)

Example 78 with PlanNode

use of com.facebook.presto.spi.plan.PlanNode in project presto by prestodb.

the class TestEliminateCrossJoins method testJoinOrder.

@Test
public void testJoinOrder() {
    PlanNode plan = joinNode(joinNode(values(variable("a")), values(variable("b"))), values(variable("c")), variable("a"), variable("c"), variable("c"), variable("b"));
    JoinGraph joinGraph = getOnlyElement(JoinGraph.buildFrom(plan));
    assertEquals(getJoinOrder(joinGraph), ImmutableList.of(0, 2, 1));
}
Also used : PlanNode(com.facebook.presto.spi.plan.PlanNode) JoinGraph(com.facebook.presto.sql.planner.optimizations.joins.JoinGraph) Test(org.testng.annotations.Test) BaseRuleTest(com.facebook.presto.sql.planner.iterative.rule.test.BaseRuleTest)

Example 79 with PlanNode

use of com.facebook.presto.spi.plan.PlanNode in project presto by prestodb.

the class TestEliminateCrossJoins method testGiveUpOnNonIdentityProjections.

@Test
public void testGiveUpOnNonIdentityProjections() {
    PlanNode plan = joinNode(projectNode(joinNode(values(variable("a1")), values(variable("b"))), variable("a2"), new ArithmeticUnaryExpression(MINUS, new SymbolReference("a1"))), values(variable("c")), variable("a2"), variable("c"), variable("c"), variable("b"));
    assertEquals(JoinGraph.buildFrom(plan).size(), 2);
}
Also used : PlanNode(com.facebook.presto.spi.plan.PlanNode) SymbolReference(com.facebook.presto.sql.tree.SymbolReference) ArithmeticUnaryExpression(com.facebook.presto.sql.tree.ArithmeticUnaryExpression) Test(org.testng.annotations.Test) BaseRuleTest(com.facebook.presto.sql.planner.iterative.rule.test.BaseRuleTest)

Example 80 with PlanNode

use of com.facebook.presto.spi.plan.PlanNode in project presto by prestodb.

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(com.facebook.presto.spi.plan.PlanNode) Test(org.testng.annotations.Test)

Aggregations

PlanNode (com.facebook.presto.spi.plan.PlanNode)228 Test (org.testng.annotations.Test)114 VariableReferenceExpression (com.facebook.presto.spi.relation.VariableReferenceExpression)94 ImmutableList (com.google.common.collect.ImmutableList)56 RowExpression (com.facebook.presto.spi.relation.RowExpression)45 ImmutableMap (com.google.common.collect.ImmutableMap)44 PlanBuilder (com.facebook.presto.sql.planner.iterative.rule.test.PlanBuilder)42 TableScanNode (com.facebook.presto.spi.plan.TableScanNode)41 AggregationNode (com.facebook.presto.spi.plan.AggregationNode)40 ProjectNode (com.facebook.presto.spi.plan.ProjectNode)40 Map (java.util.Map)39 Optional (java.util.Optional)38 List (java.util.List)36 JoinNode (com.facebook.presto.sql.planner.plan.JoinNode)35 Set (java.util.Set)30 Assert.assertEquals (org.testng.Assert.assertEquals)23 ImmutableList.toImmutableList (com.google.common.collect.ImmutableList.toImmutableList)22 OrderingScheme (com.facebook.presto.spi.plan.OrderingScheme)20 Function (java.util.function.Function)20 Metadata (com.facebook.presto.metadata.Metadata)19