JVar incomingLeftRecordBatch, JVar incomingRightRecordBatch, ErrorCollector collector) throws ClassTransformationException {
cg.setMappingSet(compareMapping);
for (JoinCondition condition : conditions) {
final LogicalExpression leftFieldExpr = condition.getLeft();
final LogicalExpression rightFieldExpr = condition.getRight();
// materialize value vector readers from join expression
LogicalExpression materializedLeftExpr;
if (worker == null || status.isLeftPositionAllowed()) {
materializedLeftExpr = ExpressionTreeMaterializer.materialize(leftFieldExpr, left, collector, context.getFunctionRegistry());
} else {
materializedLeftExpr = new TypedNullConstant(Types.optional(MinorType.INT));
}
if (collector.hasErrors())
throw new ClassTransformationException(String.format(
"Failure while trying to materialize incoming left field. Errors:\n %s.", collector.toErrorString()));
LogicalExpression materializedRightExpr;
if (worker == null || status.isRightPositionAllowed()) {
materializedRightExpr = ExpressionTreeMaterializer.materialize(rightFieldExpr, right, collector, context.getFunctionRegistry());
} else {
materializedRightExpr = new TypedNullConstant(Types.optional(MinorType.INT));
}
if (collector.hasErrors())
throw new ClassTransformationException(String.format(
"Failure while trying to materialize incoming right field. Errors:\n %s.", collector.toErrorString()));
// generate compare()
////////////////////////
cg.setMappingSet(compareMapping);
cg.getSetupBlock().assign(JExpr._this().ref(incomingRecordBatch), JExpr._this().ref(incomingLeftRecordBatch));
ClassGenerator.HoldingContainer compareLeftExprHolder = cg.addExpr(materializedLeftExpr, false);
cg.setMappingSet(compareRightMapping);
cg.getSetupBlock().assign(JExpr._this().ref(incomingRecordBatch), JExpr._this().ref(incomingRightRecordBatch));
ClassGenerator.HoldingContainer compareRightExprHolder = cg.addExpr(materializedRightExpr, false);
if (compareLeftExprHolder.isOptional() && compareRightExprHolder.isOptional()) {
// handle null == null
cg.getEvalBlock()._if(compareLeftExprHolder.getIsSet().eq(JExpr.lit(0))
.cand(compareRightExprHolder.getIsSet().eq(JExpr.lit(0))))
._then()
._return(JExpr.lit(0));
// handle null == !null
cg.getEvalBlock()._if(compareLeftExprHolder.getIsSet().eq(JExpr.lit(0))
.cor(compareRightExprHolder.getIsSet().eq(JExpr.lit(0))))
._then()
._return(JExpr.lit(1));
} else if (compareLeftExprHolder.isOptional()) {
// handle null == required (null is less than any value)
cg.getEvalBlock()._if(compareLeftExprHolder.getIsSet().eq(JExpr.lit(0)))
._then()
._return(JExpr.lit(-1));
} else if (compareRightExprHolder.isOptional()) {
// handle required == null (null is less than any value)
cg.getEvalBlock()._if(compareRightExprHolder.getIsSet().eq(JExpr.lit(0)))
._then()
._return(JExpr.lit(1));
}
LogicalExpression fh = FunctionGenerationHelper.getComparator(compareLeftExprHolder,
compareRightExprHolder,
context.getFunctionRegistry());
HoldingContainer out = cg.addExpr(fh, false);
//If not 0, it means not equal. We return this out value.