Search in sources :

Example 1 with LogicalSemiJoin

use of org.apache.drill.common.logical.data.LogicalSemiJoin in project drill by apache.

the class DrillSemiJoinRel method implement.

@Override
public LogicalOperator implement(DrillImplementor implementor) {
    List<String> fields = new ArrayList<>();
    fields.addAll(getInput(0).getRowType().getFieldNames());
    fields.addAll(getInput(1).getRowType().getFieldNames());
    Preconditions.checkArgument(DrillJoinRel.isUnique(fields));
    final int leftCount = left.getRowType().getFieldCount();
    final List<String> leftFields = fields.subList(0, leftCount);
    final List<String> rightFields = fields.subList(leftCount, leftCount + right.getRowType().getFieldCount());
    final LogicalOperator leftOp = DrillJoinRel.implementInput(implementor, 0, 0, left, this, fields);
    final LogicalOperator rightOp = DrillJoinRel.implementInput(implementor, 1, leftCount, right, this, fields);
    Join.Builder builder = Join.builder();
    builder.type(joinType);
    builder.left(leftOp);
    builder.right(rightOp);
    List<JoinCondition> conditions = Lists.newArrayList();
    for (Pair<Integer, Integer> pair : Pair.zip(leftKeys, rightKeys)) {
        conditions.add(new JoinCondition(DrillJoinRel.EQUALITY_CONDITION, new FieldReference(leftFields.get(pair.left)), new FieldReference(rightFields.get(pair.right))));
    }
    return new LogicalSemiJoin(leftOp, rightOp, conditions, joinType);
}
Also used : FieldReference(org.apache.drill.common.expression.FieldReference) LogicalOperator(org.apache.drill.common.logical.data.LogicalOperator) ArrayList(java.util.ArrayList) Join(org.apache.drill.common.logical.data.Join) LogicalSemiJoin(org.apache.drill.common.logical.data.LogicalSemiJoin) LogicalSemiJoin(org.apache.drill.common.logical.data.LogicalSemiJoin) JoinCondition(org.apache.drill.common.logical.data.JoinCondition)

Aggregations

ArrayList (java.util.ArrayList)1 FieldReference (org.apache.drill.common.expression.FieldReference)1 Join (org.apache.drill.common.logical.data.Join)1 JoinCondition (org.apache.drill.common.logical.data.JoinCondition)1 LogicalOperator (org.apache.drill.common.logical.data.LogicalOperator)1 LogicalSemiJoin (org.apache.drill.common.logical.data.LogicalSemiJoin)1