Search in sources :

Example 11 with JoinCondition

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

the class TestHashJoinOutcome method testHashJoinOutcomes.

/**
 *  Run the Hash Join where one side has an uninitialized container (the 2nd one)
 * @param uninitializedSide Which side (right or left) is the uninitialized
 * @param specialOutcome What outcome the uninitialized container has
 * @param expectedOutcome what result outcome is expected
 */
private void testHashJoinOutcomes(UninitializedSide uninitializedSide, RecordBatch.IterOutcome specialOutcome, RecordBatch.IterOutcome expectedOutcome) {
    inputOutcomesLeft.add(RecordBatch.IterOutcome.OK_NEW_SCHEMA);
    inputOutcomesLeft.add(uninitializedSide.isRight ? RecordBatch.IterOutcome.OK : specialOutcome);
    inputOutcomesRight.add(RecordBatch.IterOutcome.OK_NEW_SCHEMA);
    inputOutcomesRight.add(uninitializedSide.isRight ? specialOutcome : RecordBatch.IterOutcome.OK);
    final MockRecordBatch mockInputBatchRight = new MockRecordBatch(operatorFixture.getFragmentContext(), opContext, uninitializedSide.isRight ? uninitialized2ndInputContainersRight : inputContainerRight, inputOutcomesRight, batchSchemaRight);
    final MockRecordBatch mockInputBatchLeft = new MockRecordBatch(operatorFixture.getFragmentContext(), opContext, uninitializedSide.isRight ? inputContainerLeft : uninitialized2ndInputContainersLeft, inputOutcomesLeft, batchSchemaLeft);
    List<JoinCondition> conditions = Lists.newArrayList();
    conditions.add(new JoinCondition(SqlKind.EQUALS.toString(), FieldReference.getWithQuotedRef("leftcol"), FieldReference.getWithQuotedRef("rightcol")));
    HashJoinPOP hjConf = new HashJoinPOP(null, null, conditions, JoinRelType.INNER);
    HashJoinBatch hjBatch = new HashJoinBatch(hjConf, operatorFixture.getFragmentContext(), mockInputBatchLeft, mockInputBatchRight);
    RecordBatch.IterOutcome gotOutcome = hjBatch.next();
    assertSame(gotOutcome, RecordBatch.IterOutcome.OK_NEW_SCHEMA);
    gotOutcome = hjBatch.next();
    // verify returned outcome
    assertSame(gotOutcome, expectedOutcome);
}
Also used : MockRecordBatch(org.apache.drill.exec.physical.impl.MockRecordBatch) RecordBatch(org.apache.drill.exec.record.RecordBatch) HashJoinPOP(org.apache.drill.exec.physical.config.HashJoinPOP) MockRecordBatch(org.apache.drill.exec.physical.impl.MockRecordBatch) JoinCondition(org.apache.drill.common.logical.data.JoinCondition)

Example 12 with JoinCondition

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

the class DrillJoinRel method getJoinCondition.

protected static RexNode getJoinCondition(Join join, ConversionContext context) throws InvalidRelException {
    Pair<RelNode, RelNode> inputs = getJoinInputs(join, context);
    List<RexNode> joinConditions = new ArrayList<RexNode>();
    // right fields appear after the LHS fields.
    final int rightInputOffset = inputs.left.getRowType().getFieldCount();
    for (JoinCondition condition : join.getConditions()) {
        RelDataTypeField leftField = inputs.left.getRowType().getField(ExprHelper.getFieldName(condition.getLeft()), true, false);
        RelDataTypeField rightField = inputs.right.getRowType().getField(ExprHelper.getFieldName(condition.getRight()), true, false);
        joinConditions.add(context.getRexBuilder().makeCall(SqlStdOperatorTable.EQUALS, context.getRexBuilder().makeInputRef(leftField.getType(), leftField.getIndex()), context.getRexBuilder().makeInputRef(rightField.getType(), rightInputOffset + rightField.getIndex())));
    }
    RexNode rexCondition = RexUtil.composeConjunction(context.getRexBuilder(), joinConditions, false);
    return rexCondition;
}
Also used : RelDataTypeField(org.apache.calcite.rel.type.RelDataTypeField) RelNode(org.apache.calcite.rel.RelNode) ArrayList(java.util.ArrayList) RexNode(org.apache.calcite.rex.RexNode) JoinCondition(org.apache.drill.common.logical.data.JoinCondition)

Example 13 with JoinCondition

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

the class MergeJoinPrel method getPhysicalOperator.

@Override
public PhysicalOperator getPhysicalOperator(PhysicalPlanCreator creator) throws IOException {
    final List<String> fields = getRowType().getFieldNames();
    assert isUnique(fields);
    final int leftCount = left.getRowType().getFieldCount();
    final List<String> leftFields = fields.subList(0, leftCount);
    final List<String> rightFields = fields.subList(leftCount, fields.size());
    PhysicalOperator leftPop = ((Prel) left).getPhysicalOperator(creator);
    PhysicalOperator rightPop = ((Prel) right).getPhysicalOperator(creator);
    JoinRelType jtype = this.getJoinType();
    List<JoinCondition> conditions = Lists.newArrayList();
    buildJoinConditions(conditions, leftFields, rightFields, leftKeys, rightKeys);
    MergeJoinPOP mjoin = new MergeJoinPOP(leftPop, rightPop, conditions, jtype);
    return creator.addMetadata(this, mjoin);
}
Also used : JoinRelType(org.apache.calcite.rel.core.JoinRelType) MergeJoinPOP(org.apache.drill.exec.physical.config.MergeJoinPOP) PhysicalOperator(org.apache.drill.exec.physical.base.PhysicalOperator) JoinCondition(org.apache.drill.common.logical.data.JoinCondition)

Example 14 with JoinCondition

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

the class JoinPrel method buildJoinConditions.

/**
 * Build the list of join conditions for this join.
 * A join condition is built only for equality and IS NOT DISTINCT FROM comparisons. The difference is:
 * null == null is FALSE whereas null IS NOT DISTINCT FROM null is TRUE
 * For a use case of the IS NOT DISTINCT FROM comparison, see
 * {@link org.apache.calcite.rel.rules.AggregateRemoveRule}
 * @param conditions populated list of join conditions
 * @param leftFields join fields from the left input
 * @param rightFields join fields from the right input
 */
protected void buildJoinConditions(List<JoinCondition> conditions, List<String> leftFields, List<String> rightFields, List<Integer> leftKeys, List<Integer> rightKeys) {
    List<RexNode> conjuncts = RelOptUtil.conjunctions(this.getCondition());
    short i = 0;
    for (Pair<Integer, Integer> pair : Pair.zip(leftKeys, rightKeys)) {
        final RexNode conditionExpr = conjuncts.get(i++);
        SqlKind kind = conditionExpr.getKind();
        if (kind != SqlKind.EQUALS && kind != SqlKind.IS_NOT_DISTINCT_FROM) {
            throw UserException.unsupportedError().message("Unsupported comparator in join condition %s", conditionExpr).build(logger);
        }
        conditions.add(new JoinCondition(kind.toString(), FieldReference.getWithQuotedRef(leftFields.get(pair.left)), FieldReference.getWithQuotedRef(rightFields.get(pair.right))));
    }
}
Also used : SqlKind(org.apache.calcite.sql.SqlKind) RexNode(org.apache.calcite.rex.RexNode) JoinCondition(org.apache.drill.common.logical.data.JoinCondition)

Aggregations

JoinCondition (org.apache.drill.common.logical.data.JoinCondition)14 JoinRelType (org.apache.calcite.rel.core.JoinRelType)5 PhysicalOperator (org.apache.drill.exec.physical.base.PhysicalOperator)5 HashJoinPOP (org.apache.drill.exec.physical.config.HashJoinPOP)5 ArrayList (java.util.ArrayList)4 RexNode (org.apache.calcite.rex.RexNode)4 JClass (com.sun.codemodel.JClass)2 JVar (com.sun.codemodel.JVar)2 RelNode (org.apache.calcite.rel.RelNode)2 RelDataTypeField (org.apache.calcite.rel.type.RelDataTypeField)2 SqlKind (org.apache.calcite.sql.SqlKind)2 ErrorCollector (org.apache.drill.common.expression.ErrorCollector)2 ErrorCollectorImpl (org.apache.drill.common.expression.ErrorCollectorImpl)2 LogicalExpression (org.apache.drill.common.expression.LogicalExpression)2 MajorType (org.apache.drill.common.types.TypeProtos.MajorType)2 MergeJoinPOP (org.apache.drill.exec.physical.config.MergeJoinPOP)2 MockRecordBatch (org.apache.drill.exec.physical.impl.MockRecordBatch)2 RecordBatch (org.apache.drill.exec.record.RecordBatch)2 TypedFieldId (org.apache.drill.exec.record.TypedFieldId)2 OperatorTest (org.apache.drill.categories.OperatorTest)1