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