Search in sources :

Example 1 with NO_MATCH

use of io.prestosql.sql.planner.assertions.MatchResult.NO_MATCH in project hetu-core by openlookeng.

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(String.valueOf(expression.getValue()));
        }
        return new GenericLiteral(expression.getType().toString(), String.valueOf(expression.getValue()));
    }).collect(toImmutableList())).collect(toImmutableList()))).orElse(true)) {
        return NO_MATCH;
    }
    return match(SymbolAliases.builder().putAll(Maps.transformValues(outputSymbolAliases, index -> toSymbolReference(valuesNode.getOutputSymbols().get(index)))).build());
}
Also used : Slice(io.airlift.slice.Slice) ConstantExpression(io.prestosql.spi.relation.ConstantExpression) OriginalExpressionUtils.isExpression(io.prestosql.sql.relational.OriginalExpressionUtils.isExpression) BooleanLiteral(io.prestosql.sql.tree.BooleanLiteral) Map(java.util.Map) Objects.requireNonNull(java.util.Objects.requireNonNull) Session(io.prestosql.Session) OriginalExpressionUtils.castToExpression(io.prestosql.sql.relational.OriginalExpressionUtils.castToExpression) NO_MATCH(io.prestosql.sql.planner.assertions.MatchResult.NO_MATCH) StatsProvider(io.prestosql.cost.StatsProvider) ImmutableMap(com.google.common.collect.ImmutableMap) ImmutableList.toImmutableList(com.google.common.collect.ImmutableList.toImmutableList) MatchResult.match(io.prestosql.sql.planner.assertions.MatchResult.match) PlanNode(io.prestosql.spi.plan.PlanNode) Maps(com.google.common.collect.Maps) Metadata(io.prestosql.metadata.Metadata) Preconditions.checkState(com.google.common.base.Preconditions.checkState) SymbolUtils.toSymbolReference(io.prestosql.sql.planner.SymbolUtils.toSymbolReference) ValuesNode(io.prestosql.spi.plan.ValuesNode) List(java.util.List) DoubleLiteral(io.prestosql.sql.tree.DoubleLiteral) GenericLiteral(io.prestosql.sql.tree.GenericLiteral) LongLiteral(io.prestosql.sql.tree.LongLiteral) StringLiteral(io.prestosql.sql.tree.StringLiteral) Optional(java.util.Optional) Expression(io.prestosql.sql.tree.Expression) MoreObjects.toStringHelper(com.google.common.base.MoreObjects.toStringHelper) ValuesNode(io.prestosql.spi.plan.ValuesNode) StringLiteral(io.prestosql.sql.tree.StringLiteral) LongLiteral(io.prestosql.sql.tree.LongLiteral) BooleanLiteral(io.prestosql.sql.tree.BooleanLiteral) Slice(io.airlift.slice.Slice) ConstantExpression(io.prestosql.spi.relation.ConstantExpression) DoubleLiteral(io.prestosql.sql.tree.DoubleLiteral) GenericLiteral(io.prestosql.sql.tree.GenericLiteral)

Example 2 with NO_MATCH

use of io.prestosql.sql.planner.assertions.MatchResult.NO_MATCH 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 3 with NO_MATCH

use of io.prestosql.sql.planner.assertions.MatchResult.NO_MATCH in project hetu-core by openlookeng.

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())).orElse(true)) {
        return NO_MATCH;
    }
    if (!specification.map(expectedSpecification -> expectedSpecification.getExpectedValue(symbolAliases).equals(windowNode.getSpecification())).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)).equals(windowNode.getHashSymbol())).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 : StatsProvider(io.prestosql.cost.StatsProvider) MatchResult.match(io.prestosql.sql.planner.assertions.MatchResult.match) Set(java.util.Set) PlanNode(io.prestosql.spi.plan.PlanNode) Metadata(io.prestosql.metadata.Metadata) SortOrder(io.prestosql.spi.block.SortOrder) Preconditions.checkState(com.google.common.base.Preconditions.checkState) FunctionHandle(io.prestosql.spi.function.FunctionHandle) List(java.util.List) FunctionCall(io.prestosql.sql.tree.FunctionCall) WindowNode(io.prestosql.spi.plan.WindowNode) Map(java.util.Map) Objects.requireNonNull(java.util.Objects.requireNonNull) Session(io.prestosql.Session) Optional(java.util.Optional) ImmutableSet.toImmutableSet(com.google.common.collect.ImmutableSet.toImmutableSet) PlanMatchPattern.node(io.prestosql.sql.planner.assertions.PlanMatchPattern.node) LinkedList(java.util.LinkedList) NO_MATCH(io.prestosql.sql.planner.assertions.MatchResult.NO_MATCH) MoreObjects.toStringHelper(com.google.common.base.MoreObjects.toStringHelper) WindowNode(io.prestosql.spi.plan.WindowNode)

Example 4 with NO_MATCH

use of io.prestosql.sql.planner.assertions.MatchResult.NO_MATCH in project hetu-core by openlookeng.

the class MarkDistinctMatcher 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());
    MarkDistinctNode markDistinctNode = (MarkDistinctNode) node;
    if (!markDistinctNode.getHashSymbol().equals(hashSymbol.map(alias -> alias.toSymbol(symbolAliases)))) {
        return NO_MATCH;
    }
    if (!ImmutableSet.copyOf(markDistinctNode.getDistinctSymbols()).equals(distinctSymbols.stream().map(alias -> alias.toSymbol(symbolAliases)).collect(toImmutableSet()))) {
        return NO_MATCH;
    }
    return match(markerSymbol.toString(), toSymbolReference(markDistinctNode.getMarkerSymbol()));
}
Also used : ImmutableSet(com.google.common.collect.ImmutableSet) StatsProvider(io.prestosql.cost.StatsProvider) MatchResult.match(io.prestosql.sql.planner.assertions.MatchResult.match) PlanNode(io.prestosql.spi.plan.PlanNode) Metadata(io.prestosql.metadata.Metadata) Preconditions.checkState(com.google.common.base.Preconditions.checkState) SymbolUtils.toSymbolReference(io.prestosql.sql.planner.SymbolUtils.toSymbolReference) List(java.util.List) ImmutableList(com.google.common.collect.ImmutableList) Objects.requireNonNull(java.util.Objects.requireNonNull) Session(io.prestosql.Session) Optional(java.util.Optional) ImmutableSet.toImmutableSet(com.google.common.collect.ImmutableSet.toImmutableSet) NO_MATCH(io.prestosql.sql.planner.assertions.MatchResult.NO_MATCH) MarkDistinctNode(io.prestosql.spi.plan.MarkDistinctNode) MoreObjects.toStringHelper(com.google.common.base.MoreObjects.toStringHelper) MarkDistinctNode(io.prestosql.spi.plan.MarkDistinctNode)

Example 5 with NO_MATCH

use of io.prestosql.sql.planner.assertions.MatchResult.NO_MATCH in project hetu-core by openlookeng.

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.isPresent()) {
        List<Symbol> expected = partitionBy.get().stream().map(alias -> alias.toSymbol(symbolAliases)).collect(toImmutableList());
        if (!expected.equals(rowNumberNode.getPartitionBy())) {
            return NO_MATCH;
        }
    }
    if (rowNumberSymbol.isPresent()) {
        Symbol expected = rowNumberSymbol.get().toSymbol(symbolAliases);
        if (!expected.equals(rowNumberNode.getRowNumberSymbol())) {
            return NO_MATCH;
        }
    }
    if (maxRowCountPerPartition.isPresent()) {
        if (!maxRowCountPerPartition.get().equals(rowNumberNode.getMaxRowCountPerPartition())) {
            return NO_MATCH;
        }
    }
    if (hashSymbol.isPresent()) {
        Optional<Symbol> expected = hashSymbol.get().map(alias -> alias.toSymbol(symbolAliases));
        if (!expected.equals(rowNumberNode.getHashSymbol())) {
            return NO_MATCH;
        }
    }
    return match();
}
Also used : Symbol(io.prestosql.spi.plan.Symbol) StatsProvider(io.prestosql.cost.StatsProvider) ImmutableList.toImmutableList(com.google.common.collect.ImmutableList.toImmutableList) MatchResult.match(io.prestosql.sql.planner.assertions.MatchResult.match) PlanNode(io.prestosql.spi.plan.PlanNode) Metadata(io.prestosql.metadata.Metadata) RowNumberNode(io.prestosql.sql.planner.plan.RowNumberNode) Preconditions.checkState(com.google.common.base.Preconditions.checkState) List(java.util.List) Objects.requireNonNull(java.util.Objects.requireNonNull) Session(io.prestosql.Session) Optional(java.util.Optional) PlanMatchPattern.node(io.prestosql.sql.planner.assertions.PlanMatchPattern.node) NO_MATCH(io.prestosql.sql.planner.assertions.MatchResult.NO_MATCH) MoreObjects.toStringHelper(com.google.common.base.MoreObjects.toStringHelper) Symbol(io.prestosql.spi.plan.Symbol) RowNumberNode(io.prestosql.sql.planner.plan.RowNumberNode)

Aggregations

MoreObjects.toStringHelper (com.google.common.base.MoreObjects.toStringHelper)8 Preconditions.checkState (com.google.common.base.Preconditions.checkState)8 Session (io.prestosql.Session)8 StatsProvider (io.prestosql.cost.StatsProvider)8 Metadata (io.prestosql.metadata.Metadata)8 PlanNode (io.prestosql.spi.plan.PlanNode)8 NO_MATCH (io.prestosql.sql.planner.assertions.MatchResult.NO_MATCH)8 List (java.util.List)8 MatchResult.match (io.prestosql.sql.planner.assertions.MatchResult.match)7 Optional (java.util.Optional)7 Objects.requireNonNull (java.util.Objects.requireNonNull)6 ImmutableList.toImmutableList (com.google.common.collect.ImmutableList.toImmutableList)5 ImmutableSet.toImmutableSet (com.google.common.collect.ImmutableSet.toImmutableSet)3 Symbol (io.prestosql.spi.plan.Symbol)3 SymbolUtils.toSymbolReference (io.prestosql.sql.planner.SymbolUtils.toSymbolReference)3 Map (java.util.Map)3 ImmutableSet (com.google.common.collect.ImmutableSet)2 PlanMatchPattern.node (io.prestosql.sql.planner.assertions.PlanMatchPattern.node)2 OriginalExpressionUtils.castToExpression (io.prestosql.sql.relational.OriginalExpressionUtils.castToExpression)2 OriginalExpressionUtils.isExpression (io.prestosql.sql.relational.OriginalExpressionUtils.isExpression)2