Search in sources :

Example 1 with LimitPrel

use of org.apache.drill.exec.planner.physical.LimitPrel in project drill by apache.

the class AbstractIndexPlanGenerator method getSortNode.

public static RelNode getSortNode(IndexCallContext indexContext, RelNode newRel, boolean donotGenerateSort, boolean isSingleton, boolean isExchangeRequired) {
    OrderedRel rel = indexContext.getSort();
    DrillDistributionTrait hashDistribution = new DrillDistributionTrait(DrillDistributionTrait.DistributionType.HASH_DISTRIBUTED, ImmutableList.copyOf(indexContext.getDistributionFields()));
    if (toRemoveSort(indexContext.getCollation(), newRel.getTraitSet().getTrait(RelCollationTraitDef.INSTANCE))) {
        // we are going to remove sort
        logger.debug("Not generating SortPrel since we have the required collation");
        if (IndexPlanUtils.generateLimit(rel)) {
            newRel = new LimitPrel(newRel.getCluster(), newRel.getTraitSet().plus(indexContext.getCollation()).plus(Prel.DRILL_PHYSICAL), newRel, IndexPlanUtils.getOffset(rel), IndexPlanUtils.getFetch(rel));
        }
        RelTraitSet traits = newRel.getTraitSet().plus(indexContext.getCollation()).plus(Prel.DRILL_PHYSICAL);
        newRel = Prule.convert(newRel, traits);
        newRel = getExchange(newRel.getCluster(), isSingleton, isExchangeRequired, traits, hashDistribution, indexContext, newRel);
    } else {
        if (donotGenerateSort) {
            logger.debug("Not generating SortPrel and index plan, since just picking index for full index scan is not beneficial.");
            return null;
        }
        RelTraitSet traits = newRel.getTraitSet().plus(indexContext.getCollation()).plus(Prel.DRILL_PHYSICAL);
        newRel = getSortOrTopN(indexContext, rel, newRel, Prule.convert(newRel, newRel.getTraitSet().replace(Prel.DRILL_PHYSICAL)));
        newRel = getExchange(newRel.getCluster(), isSingleton, isExchangeRequired, traits, hashDistribution, indexContext, newRel);
    }
    return newRel;
}
Also used : OrderedRel(org.apache.drill.exec.planner.common.OrderedRel) RelTraitSet(org.apache.calcite.plan.RelTraitSet) LimitPrel(org.apache.drill.exec.planner.physical.LimitPrel) DrillDistributionTrait(org.apache.drill.exec.planner.physical.DrillDistributionTrait)

Example 2 with LimitPrel

use of org.apache.drill.exec.planner.physical.LimitPrel in project drill by apache.

the class MapRDBPushLimitIntoScan method doPushLimitIntoRowKeyJoin.

protected void doPushLimitIntoRowKeyJoin(RelOptRuleCall call, LimitPrel limit, final ProjectPrel project, RowKeyJoinPrel join) {
    final RelNode newChild;
    try {
        RelNode left = join.getLeft();
        RelNode right = join.getRight();
        final RelNode limitOnLeft = new LimitPrel(left.getCluster(), left.getTraitSet(), left, limit.getOffset(), limit.getFetch());
        RowKeyJoinPrel newJoin = new RowKeyJoinPrel(join.getCluster(), join.getTraitSet(), limitOnLeft, right, join.getCondition(), join.getJoinType());
        if (project != null) {
            final ProjectPrel newProject = new ProjectPrel(project.getCluster(), project.getTraitSet(), newJoin, project.getProjects(), project.getRowType());
            newChild = newProject;
        } else {
            newChild = newJoin;
        }
        call.transformTo(newChild);
        logger.debug("pushLimitIntoRowKeyJoin: Pushed limit on left side of Join " + join.toString());
    } catch (Exception e) {
        logger.warn("pushLimitIntoRowKeyJoin: Exception while trying limit pushdown!", e);
    }
}
Also used : ProjectPrel(org.apache.drill.exec.planner.physical.ProjectPrel) RelNode(org.apache.calcite.rel.RelNode) RowKeyJoinPrel(org.apache.drill.exec.planner.physical.RowKeyJoinPrel) LimitPrel(org.apache.drill.exec.planner.physical.LimitPrel)

Aggregations

LimitPrel (org.apache.drill.exec.planner.physical.LimitPrel)2 RelTraitSet (org.apache.calcite.plan.RelTraitSet)1 RelNode (org.apache.calcite.rel.RelNode)1 OrderedRel (org.apache.drill.exec.planner.common.OrderedRel)1 DrillDistributionTrait (org.apache.drill.exec.planner.physical.DrillDistributionTrait)1 ProjectPrel (org.apache.drill.exec.planner.physical.ProjectPrel)1 RowKeyJoinPrel (org.apache.drill.exec.planner.physical.RowKeyJoinPrel)1