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);
}
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);
}
}
}
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;
}
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());
}
}
Aggregations