Search in sources :

Example 1 with StatsProvider

use of com.facebook.presto.cost.StatsProvider 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 2 with StatsProvider

use of com.facebook.presto.cost.StatsProvider 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 3 with StatsProvider

use of com.facebook.presto.cost.StatsProvider in project presto by prestodb.

the class TableWriterMatcher 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());
    TableWriterNode tableWriterNode = (TableWriterNode) node;
    if (!tableWriterNode.getColumnNames().equals(columnNames)) {
        return NO_MATCH;
    }
    if (!columns.stream().map(s -> Symbol.from(symbolAliases.get(s))).collect(toImmutableList()).equals(tableWriterNode.getColumns().stream().map(VariableReferenceExpression::getName).map(Symbol::new).collect(toImmutableList()))) {
        return NO_MATCH;
    }
    return match();
}
Also used : Session(com.facebook.presto.Session) ImmutableList.toImmutableList(com.google.common.collect.ImmutableList.toImmutableList) StatsProvider(com.facebook.presto.cost.StatsProvider) VariableReferenceExpression(com.facebook.presto.spi.relation.VariableReferenceExpression) TableWriterNode(com.facebook.presto.sql.planner.plan.TableWriterNode) 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) MatchResult.match(com.facebook.presto.sql.planner.assertions.MatchResult.match) NO_MATCH(com.facebook.presto.sql.planner.assertions.MatchResult.NO_MATCH) Metadata(com.facebook.presto.metadata.Metadata) MoreObjects.toStringHelper(com.google.common.base.MoreObjects.toStringHelper) VariableReferenceExpression(com.facebook.presto.spi.relation.VariableReferenceExpression) TableWriterNode(com.facebook.presto.sql.planner.plan.TableWriterNode)

Example 4 with StatsProvider

use of com.facebook.presto.cost.StatsProvider in project presto by prestodb.

the class WindowMatcher 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());
    WindowNode windowNode = (WindowNode) node;
    if (!prePartitionedInputs.map(expectedInputs -> expectedInputs.stream().map(alias -> alias.toSymbol(symbolAliases)).collect(toImmutableSet()).equals(windowNode.getPrePartitionedInputs().stream().map(VariableReferenceExpression::getName).map(Symbol::new).collect(toImmutableSet()))).orElse(true)) {
        return NO_MATCH;
    }
    if (!specification.map(expectedSpecification -> matchSpecification(windowNode.getSpecification(), expectedSpecification.getExpectedValue(symbolAliases))).orElse(true)) {
        return NO_MATCH;
    }
    if (!preSortedOrderPrefix.map(Integer.valueOf(windowNode.getPreSortedOrderPrefix())::equals).orElse(true)) {
        return NO_MATCH;
    }
    if (!hashSymbol.map(expectedHashSymbol -> expectedHashSymbol.map(alias -> alias.toSymbol(symbolAliases)).map(Symbol::getName).equals(windowNode.getHashVariable().map(VariableReferenceExpression::getName))).orElse(true)) {
        return NO_MATCH;
    }
    /*
         * Window functions produce a symbol (the result of the function call) that we might
         * want to bind to an alias so we can reference it further up the tree. As such,
         * they need to be matched with an Alias matcher so we can bind the symbol if desired.
         */
    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) Set(java.util.Set) 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) Map(java.util.Map) MatchResult.match(com.facebook.presto.sql.planner.assertions.MatchResult.match) Objects.requireNonNull(java.util.Objects.requireNonNull) FunctionHandle(com.facebook.presto.spi.function.FunctionHandle) Optional(java.util.Optional) ImmutableSet.toImmutableSet(com.google.common.collect.ImmutableSet.toImmutableSet) NO_MATCH(com.facebook.presto.sql.planner.assertions.MatchResult.NO_MATCH) LinkedList(java.util.LinkedList) Metadata(com.facebook.presto.metadata.Metadata) FunctionCall(com.facebook.presto.sql.tree.FunctionCall) PlanMatchPattern.node(com.facebook.presto.sql.planner.assertions.PlanMatchPattern.node) MoreObjects.toStringHelper(com.google.common.base.MoreObjects.toStringHelper) WindowNode(com.facebook.presto.sql.planner.plan.WindowNode) VariableReferenceExpression(com.facebook.presto.spi.relation.VariableReferenceExpression) Symbol(com.facebook.presto.sql.planner.Symbol)

Example 5 with StatsProvider

use of com.facebook.presto.cost.StatsProvider in project presto by prestodb.

the class RowNumberMatcher 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());
    RowNumberNode rowNumberNode = (RowNumberNode) node;
    if (!partitionBy.map(expectedPartitionBy -> expectedPartitionBy.stream().map(alias -> alias.toSymbol(symbolAliases)).map(Symbol::getName).collect(toImmutableList()).equals(rowNumberNode.getPartitionBy().stream().map(VariableReferenceExpression::getName).collect(toImmutableList()))).orElse(true)) {
        return NO_MATCH;
    }
    if (!maxRowCountPerPartition.map(expectedMaxRowCountPerPartition -> expectedMaxRowCountPerPartition.equals(rowNumberNode.getMaxRowCountPerPartition())).orElse(true)) {
        return NO_MATCH;
    }
    if (!rowNumberSymbol.map(expectedRowNumberSymbol -> expectedRowNumberSymbol.toSymbol(symbolAliases).getName().equals(rowNumberNode.getRowNumberVariable().getName())).orElse(true)) {
        return NO_MATCH;
    }
    if (!hashSymbol.map(expectedHashSymbol -> expectedHashSymbol.map(symbolAlias -> symbolAlias.toSymbol(symbolAliases)).map(Symbol::getName).equals(rowNumberNode.getHashVariable().map(VariableReferenceExpression::getName))).orElse(true)) {
        return NO_MATCH;
    }
    return match();
}
Also used : RowNumberNode(com.facebook.presto.sql.planner.plan.RowNumberNode) Session(com.facebook.presto.Session) ImmutableList.toImmutableList(com.google.common.collect.ImmutableList.toImmutableList) 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) 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) Symbol(com.facebook.presto.sql.planner.Symbol) VariableReferenceExpression(com.facebook.presto.spi.relation.VariableReferenceExpression) RowNumberNode(com.facebook.presto.sql.planner.plan.RowNumberNode)

Aggregations

StatsProvider (com.facebook.presto.cost.StatsProvider)16 Metadata (com.facebook.presto.metadata.Metadata)8 PlanNode (com.facebook.presto.spi.plan.PlanNode)8 List (java.util.List)8 Session (com.facebook.presto.Session)7 NO_MATCH (com.facebook.presto.sql.planner.assertions.MatchResult.NO_MATCH)7 MoreObjects.toStringHelper (com.google.common.base.MoreObjects.toStringHelper)7 Preconditions.checkState (com.google.common.base.Preconditions.checkState)7 Objects.requireNonNull (java.util.Objects.requireNonNull)7 Optional (java.util.Optional)7 VariableReferenceExpression (com.facebook.presto.spi.relation.VariableReferenceExpression)6 MatchResult.match (com.facebook.presto.sql.planner.assertions.MatchResult.match)6 CachingStatsProvider (com.facebook.presto.cost.CachingStatsProvider)5 Symbol (com.facebook.presto.sql.planner.Symbol)5 CachingCostProvider (com.facebook.presto.cost.CachingCostProvider)4 CostProvider (com.facebook.presto.cost.CostProvider)4 ImmutableSet.toImmutableSet (com.google.common.collect.ImmutableSet.toImmutableSet)4 PlanMatchPattern.node (com.facebook.presto.sql.planner.assertions.PlanMatchPattern.node)3 JoinNode (com.facebook.presto.sql.planner.plan.JoinNode)3 ImmutableList.toImmutableList (com.google.common.collect.ImmutableList.toImmutableList)3