Search in sources :

Example 1 with LateralJoinPrel

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

the class ExcessiveExchangeIdentifier method visitLateral.

@Override
public Prel visitLateral(LateralJoinPrel prel, MajorFragmentStat s) throws RuntimeException {
    List<RelNode> children = Lists.newArrayList();
    s.add(prel);
    for (Prel p : prel) {
        s.add(p);
    }
    // Traverse the left side of the Lateral join first. Left side of the
    // Lateral shouldn't have any restrictions on Exchanges.
    children.add(((Prel) prel.getInput(0)).accept(this, s));
    // Save the outermost Lateral join so as to unset the flag later.
    if (topMostLateralJoin == null) {
        topMostLateralJoin = prel;
    }
    // Right side of the Lateral shouldn't have any Exchanges. Hence set the
    // flag so that visitExchange removes the exchanges.
    s.setRightSideOfLateral(true);
    children.add(((Prel) prel.getInput(1)).accept(this, s));
    if (topMostLateralJoin == prel) {
        topMostLateralJoin = null;
        s.setRightSideOfLateral(false);
    }
    if (children.equals(prel.getInputs())) {
        return prel;
    }
    return (Prel) prel.copy(prel.getTraitSet(), children);
}
Also used : RelNode(org.apache.calcite.rel.RelNode) LateralJoinPrel(org.apache.drill.exec.planner.physical.LateralJoinPrel) ExchangePrel(org.apache.drill.exec.planner.physical.ExchangePrel) ScanPrel(org.apache.drill.exec.planner.physical.ScanPrel) Prel(org.apache.drill.exec.planner.physical.Prel) SingleMergeExchangePrel(org.apache.drill.exec.planner.physical.SingleMergeExchangePrel) ProjectPrel(org.apache.drill.exec.planner.physical.ProjectPrel) ScreenPrel(org.apache.drill.exec.planner.physical.ScreenPrel) FilterPrel(org.apache.drill.exec.planner.physical.FilterPrel) UnnestPrel(org.apache.drill.exec.planner.physical.UnnestPrel) LimitPrel(org.apache.drill.exec.planner.physical.LimitPrel) HashToMergeExchangePrel(org.apache.drill.exec.planner.physical.HashToMergeExchangePrel)

Example 2 with LateralJoinPrel

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

the class NumberingRelWriter method explainInputs.

private void explainInputs(RelNode rel) {
    if (rel instanceof LateralJoinPrel) {
        this.explainInputs((LateralJoinPrel) rel);
    } else {
        List<RelNode> inputs = rel.getInputs();
        if (rel instanceof HashJoinPrel && ((HashJoinPrel) rel).isSwapped()) {
            HashJoinPrel joinPrel = (HashJoinPrel) rel;
            inputs = FlatLists.of(joinPrel.getRight(), joinPrel.getLeft());
        }
        for (RelNode input : inputs) {
            input.explain(this);
        }
    }
}
Also used : LateralJoinPrel(org.apache.drill.exec.planner.physical.LateralJoinPrel) RelNode(org.apache.calcite.rel.RelNode) HashJoinPrel(org.apache.drill.exec.planner.physical.HashJoinPrel)

Example 3 with LateralJoinPrel

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

the class AdjustOperatorsSchemaVisitor method visitUnnest.

@Override
public Prel visitUnnest(UnnestPrel prel, Void value) throws RuntimeException {
    Preconditions.checkArgument(registeredPrel != null && registeredPrel instanceof LateralJoinPrel);
    Preconditions.checkArgument(prel.getRowType().getFieldCount() == 1);
    RexBuilder builder = prel.getCluster().getRexBuilder();
    LateralJoinPrel lateralJoinPrel = (LateralJoinPrel) getRegisteredPrel();
    int correlationIndex = lateralJoinPrel.getRequiredColumns().nextSetBit(0);
    String correlationColumnName = lateralJoinPrel.getLeft().getRowType().getFieldNames().get(correlationIndex);
    RexNode corrRef = builder.makeCorrel(lateralJoinPrel.getLeft().getRowType(), lateralJoinPrel.getCorrelationId());
    RexNode fieldAccess = builder.makeFieldAccess(corrRef, correlationColumnName, false);
    List<String> fieldNames = new ArrayList<>();
    List<RelDataType> fieldTypes = new ArrayList<>();
    for (RelDataTypeField field : prel.getRowType().getFieldList()) {
        fieldNames.add(correlationColumnName);
        fieldTypes.add(field.getType());
    }
    UnnestPrel unnestPrel = new UnnestPrel(prel.getCluster(), prel.getTraitSet(), prel.getCluster().getTypeFactory().createStructType(fieldTypes, fieldNames), fieldAccess);
    return unnestPrel;
}
Also used : LateralJoinPrel(org.apache.drill.exec.planner.physical.LateralJoinPrel) RelDataTypeField(org.apache.calcite.rel.type.RelDataTypeField) ArrayList(java.util.ArrayList) RexBuilder(org.apache.calcite.rex.RexBuilder) RelDataType(org.apache.calcite.rel.type.RelDataType) UnnestPrel(org.apache.drill.exec.planner.physical.UnnestPrel) RexNode(org.apache.calcite.rex.RexNode)

Example 4 with LateralJoinPrel

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

the class LateralUnnestRowIDVisitor method visitLateral.

@Override
public Prel visitLateral(LateralJoinPrel prel, Boolean isRightOfLateral) throws RuntimeException {
    List<RelNode> children = Lists.newArrayList();
    children.add(((Prel) prel.getInput(0)).accept(this, isRightOfLateral));
    children.add(((Prel) prel.getInput(1)).accept(this, true));
    if (!isRightOfLateral) {
        return (Prel) prel.copy(prel.getTraitSet(), children);
    } else {
        // Adjust the column numbering due to an additional column "$drill_implicit_field$" is added to the inputs.
        Map<Integer, Integer> requiredColsMap = new HashMap<>();
        for (Integer corrColIndex : prel.getRequiredColumns()) {
            requiredColsMap.put(corrColIndex, corrColIndex + 1);
        }
        ImmutableBitSet requiredColumns = prel.getRequiredColumns().shift(1);
        CorrelationId corrId = prel.getCluster().createCorrel();
        RexCorrelVariable updatedCorrel = (RexCorrelVariable) prel.getCluster().getRexBuilder().makeCorrel(children.get(0).getRowType(), corrId);
        RelNode rightChild = children.get(1).accept(new CorrelateVarReplacer(new ProjectCorrelateTransposeRule.RexFieldAccessReplacer(prel.getCorrelationId(), updatedCorrel, prel.getCluster().getRexBuilder(), requiredColsMap)));
        return (Prel) prel.copy(prel.getTraitSet(), children.get(0), rightChild, corrId, requiredColumns, prel.getJoinType());
    }
}
Also used : RexCorrelVariable(org.apache.calcite.rex.RexCorrelVariable) RelNode(org.apache.calcite.rel.RelNode) ImmutableBitSet(org.apache.calcite.util.ImmutableBitSet) HashMap(java.util.HashMap) CorrelationId(org.apache.calcite.rel.core.CorrelationId) LateralJoinPrel(org.apache.drill.exec.planner.physical.LateralJoinPrel) Prel(org.apache.drill.exec.planner.physical.Prel) UnnestPrel(org.apache.drill.exec.planner.physical.UnnestPrel)

Aggregations

LateralJoinPrel (org.apache.drill.exec.planner.physical.LateralJoinPrel)4 RelNode (org.apache.calcite.rel.RelNode)3 UnnestPrel (org.apache.drill.exec.planner.physical.UnnestPrel)3 Prel (org.apache.drill.exec.planner.physical.Prel)2 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 CorrelationId (org.apache.calcite.rel.core.CorrelationId)1 RelDataType (org.apache.calcite.rel.type.RelDataType)1 RelDataTypeField (org.apache.calcite.rel.type.RelDataTypeField)1 RexBuilder (org.apache.calcite.rex.RexBuilder)1 RexCorrelVariable (org.apache.calcite.rex.RexCorrelVariable)1 RexNode (org.apache.calcite.rex.RexNode)1 ImmutableBitSet (org.apache.calcite.util.ImmutableBitSet)1 ExchangePrel (org.apache.drill.exec.planner.physical.ExchangePrel)1 FilterPrel (org.apache.drill.exec.planner.physical.FilterPrel)1 HashJoinPrel (org.apache.drill.exec.planner.physical.HashJoinPrel)1 HashToMergeExchangePrel (org.apache.drill.exec.planner.physical.HashToMergeExchangePrel)1 LimitPrel (org.apache.drill.exec.planner.physical.LimitPrel)1 ProjectPrel (org.apache.drill.exec.planner.physical.ProjectPrel)1 ScanPrel (org.apache.drill.exec.planner.physical.ScanPrel)1