Search in sources :

Example 6 with LimitNode

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

the class PushLimitThroughOffset method apply.

@Override
public Result apply(LimitNode parent, Captures captures, Context context) {
    OffsetNode child = captures.get(CHILD);
    long count;
    try {
        count = addExact(parent.getCount(), child.getCount());
    } catch (ArithmeticException e) {
        return Result.empty();
    }
    return Result.ofPlanNode(child.replaceChildren(ImmutableList.of(new LimitNode(parent.getId(), child.getSource(), count, parent.getTiesResolvingScheme(), parent.isPartial()))));
}
Also used : LimitNode(io.prestosql.spi.plan.LimitNode) OffsetNode(io.prestosql.sql.planner.plan.OffsetNode)

Example 7 with LimitNode

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

the class TransformExistsApplyToLateralNode method rewriteToNonDefaultAggregation.

private Optional<PlanNode> rewriteToNonDefaultAggregation(ApplyNode applyNode, Context context) {
    checkState(applyNode.getSubquery().getOutputSymbols().isEmpty(), "Expected subquery output symbols to be pruned");
    Symbol exists = getOnlyElement(applyNode.getSubqueryAssignments().getSymbols());
    Symbol subqueryTrue = context.getSymbolAllocator().newSymbol("subqueryTrue", BOOLEAN);
    Assignments.Builder assignments = Assignments.builder();
    assignments.putAll(AssignmentUtils.identityAsSymbolReferences(applyNode.getInput().getOutputSymbols()));
    assignments.put(exists, castToRowExpression(new CoalesceExpression(ImmutableList.of(toSymbolReference(subqueryTrue), BooleanLiteral.FALSE_LITERAL))));
    PlanNode subquery = new ProjectNode(context.getIdAllocator().getNextId(), new LimitNode(context.getIdAllocator().getNextId(), applyNode.getSubquery(), 1L, false), Assignments.of(subqueryTrue, castToRowExpression(TRUE_LITERAL)));
    PlanNodeDecorrelator decorrelator = new PlanNodeDecorrelator(context.getIdAllocator(), context.getLookup());
    if (!decorrelator.decorrelateFilters(subquery, applyNode.getCorrelation()).isPresent()) {
        return Optional.empty();
    }
    return Optional.of(new ProjectNode(context.getIdAllocator().getNextId(), new LateralJoinNode(applyNode.getId(), applyNode.getInput(), subquery, applyNode.getCorrelation(), LEFT, TRUE_LITERAL, applyNode.getOriginSubquery()), assignments.build()));
}
Also used : PlanNodeDecorrelator(io.prestosql.sql.planner.optimizations.PlanNodeDecorrelator) PlanNode(io.prestosql.spi.plan.PlanNode) LateralJoinNode(io.prestosql.sql.planner.plan.LateralJoinNode) LimitNode(io.prestosql.spi.plan.LimitNode) Symbol(io.prestosql.spi.plan.Symbol) Assignments(io.prestosql.spi.plan.Assignments) ProjectNode(io.prestosql.spi.plan.ProjectNode) CoalesceExpression(io.prestosql.sql.tree.CoalesceExpression)

Example 8 with LimitNode

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

the class PushLimitThroughOuterJoin method apply.

@Override
public Result apply(LimitNode parent, Captures captures, Context context) {
    JoinNode joinNode = captures.get(CHILD);
    PlanNode left = joinNode.getLeft();
    PlanNode right = joinNode.getRight();
    if (joinNode.getType() == LEFT && !isAtMost(left, context.getLookup(), parent.getCount())) {
        return Result.ofPlanNode(parent.replaceChildren(ImmutableList.of(joinNode.replaceChildren(ImmutableList.of(new LimitNode(context.getIdAllocator().getNextId(), left, parent.getCount(), true), right)))));
    }
    if (joinNode.getType() == RIGHT && !isAtMost(right, context.getLookup(), parent.getCount())) {
        return Result.ofPlanNode(parent.replaceChildren(ImmutableList.of(joinNode.replaceChildren(ImmutableList.of(left, new LimitNode(context.getIdAllocator().getNextId(), right, parent.getCount(), true))))));
    }
    return Result.empty();
}
Also used : PlanNode(io.prestosql.spi.plan.PlanNode) LimitNode(io.prestosql.spi.plan.LimitNode) JoinNode(io.prestosql.spi.plan.JoinNode)

Example 9 with LimitNode

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

the class TestEffectivePredicateExtractor method testLimit.

@Test
public void testLimit() {
    PlanNode node = new LimitNode(newId(), filter(baseTableScan, and(equals(AE, BE), equals(BE, CE), lessThan(CE, bigintLiteral(10)))), 1, false);
    Expression effectivePredicate = effectivePredicateExtractor.extract(SESSION, node, TypeProvider.empty(), typeAnalyzer);
    // Pass through
    assertEquals(normalizeConjuncts(effectivePredicate), normalizeConjunctsSet(equals(AE, BE), equals(BE, CE), lessThan(CE, bigintLiteral(10))));
}
Also used : PlanNode(io.prestosql.spi.plan.PlanNode) LimitNode(io.prestosql.spi.plan.LimitNode) CallExpression(io.prestosql.spi.relation.CallExpression) OriginalExpressionUtils.castToRowExpression(io.prestosql.sql.relational.OriginalExpressionUtils.castToRowExpression) InListExpression(io.prestosql.sql.tree.InListExpression) ComparisonExpression(io.prestosql.sql.tree.ComparisonExpression) RowExpression(io.prestosql.spi.relation.RowExpression) Expression(io.prestosql.sql.tree.Expression) Test(org.testng.annotations.Test)

Example 10 with LimitNode

use of io.prestosql.spi.plan.LimitNode in project boostkit-bigdata by kunpengcompute.

the class TestHiveLimitPushdown method testLimitPushdown.

@Test
public void testLimitPushdown() {
    int count = 5;
    HiveLimitPushdown optimizer = new HiveLimitPushdown(simulationHiveTransactionManager());
    TableScanNode tableScanNode = buildTableScanNode();
    LimitNode limitNode = buildPartialLimitNode(tableScanNode, count);
    PlanNode node = optimizer.optimize(limitNode, OFFLOAD_SESSION, COLUMN_TYPE_MAP, SYMBOL_ALLOCATOR, ID_ALLOCATOR);
    matchLimitOffload(node, count);
}
Also used : PlanNode(io.prestosql.spi.plan.PlanNode) TableScanNode(io.prestosql.spi.plan.TableScanNode) TestHivePushdownUtil.buildTableScanNode(io.prestosql.plugin.hive.rule.TestHivePushdownUtil.buildTableScanNode) TestHivePushdownUtil.buildPartialLimitNode(io.prestosql.plugin.hive.rule.TestHivePushdownUtil.buildPartialLimitNode) LimitNode(io.prestosql.spi.plan.LimitNode) Test(org.testng.annotations.Test)

Aggregations

LimitNode (io.prestosql.spi.plan.LimitNode)10 PlanNode (io.prestosql.spi.plan.PlanNode)7 Symbol (io.prestosql.spi.plan.Symbol)4 TableScanNode (io.prestosql.spi.plan.TableScanNode)3 Test (org.testng.annotations.Test)3 PlanNodeId (io.prestosql.spi.plan.PlanNodeId)2 ProjectNode (io.prestosql.spi.plan.ProjectNode)2 Type (io.prestosql.spi.type.Type)2 Expression (io.prestosql.sql.tree.Expression)2 ImmutableList (com.google.common.collect.ImmutableList)1 ImmutableMap (com.google.common.collect.ImmutableMap)1 TestHivePushdownUtil.buildPartialLimitNode (io.prestosql.plugin.hive.rule.TestHivePushdownUtil.buildPartialLimitNode)1 TestHivePushdownUtil.buildTableScanNode (io.prestosql.plugin.hive.rule.TestHivePushdownUtil.buildTableScanNode)1 PrestoException (io.prestosql.spi.PrestoException)1 ColumnHandle (io.prestosql.spi.connector.ColumnHandle)1 Assignments (io.prestosql.spi.plan.Assignments)1 FilterNode (io.prestosql.spi.plan.FilterNode)1 JoinNode (io.prestosql.spi.plan.JoinNode)1 PlanNodeIdAllocator (io.prestosql.spi.plan.PlanNodeIdAllocator)1 UnionNode (io.prestosql.spi.plan.UnionNode)1