Search in sources :

Example 1 with RowNumberNode

use of io.prestosql.sql.planner.plan.RowNumberNode in project hetu-core by openlookeng.

the class ImplementOffset method apply.

@Override
public Result apply(OffsetNode parent, Captures captures, Context context) {
    Symbol rowNumberSymbol = context.getSymbolAllocator().newSymbol("row_number", BIGINT);
    RowNumberNode rowNumberNode = new RowNumberNode(context.getIdAllocator().getNextId(), parent.getSource(), ImmutableList.of(), rowNumberSymbol, Optional.empty(), Optional.empty());
    FilterNode filterNode = new FilterNode(context.getIdAllocator().getNextId(), rowNumberNode, castToRowExpression(new ComparisonExpression(ComparisonExpression.Operator.GREATER_THAN, toSymbolReference(rowNumberSymbol), new GenericLiteral("BIGINT", Long.toString(parent.getCount())))));
    ProjectNode projectNode = new ProjectNode(context.getIdAllocator().getNextId(), filterNode, AssignmentUtils.identityAsSymbolReferences(parent.getOutputSymbols()));
    return Result.ofPlanNode(projectNode);
}
Also used : ComparisonExpression(io.prestosql.sql.tree.ComparisonExpression) Symbol(io.prestosql.spi.plan.Symbol) FilterNode(io.prestosql.spi.plan.FilterNode) RowNumberNode(io.prestosql.sql.planner.plan.RowNumberNode) ProjectNode(io.prestosql.spi.plan.ProjectNode) GenericLiteral(io.prestosql.sql.tree.GenericLiteral)

Example 2 with RowNumberNode

use of io.prestosql.sql.planner.plan.RowNumberNode 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

Symbol (io.prestosql.spi.plan.Symbol)2 RowNumberNode (io.prestosql.sql.planner.plan.RowNumberNode)2 MoreObjects.toStringHelper (com.google.common.base.MoreObjects.toStringHelper)1 Preconditions.checkState (com.google.common.base.Preconditions.checkState)1 ImmutableList.toImmutableList (com.google.common.collect.ImmutableList.toImmutableList)1 Session (io.prestosql.Session)1 StatsProvider (io.prestosql.cost.StatsProvider)1 Metadata (io.prestosql.metadata.Metadata)1 FilterNode (io.prestosql.spi.plan.FilterNode)1 PlanNode (io.prestosql.spi.plan.PlanNode)1 ProjectNode (io.prestosql.spi.plan.ProjectNode)1 NO_MATCH (io.prestosql.sql.planner.assertions.MatchResult.NO_MATCH)1 MatchResult.match (io.prestosql.sql.planner.assertions.MatchResult.match)1 PlanMatchPattern.node (io.prestosql.sql.planner.assertions.PlanMatchPattern.node)1 ComparisonExpression (io.prestosql.sql.tree.ComparisonExpression)1 GenericLiteral (io.prestosql.sql.tree.GenericLiteral)1 List (java.util.List)1 Objects.requireNonNull (java.util.Objects.requireNonNull)1 Optional (java.util.Optional)1