Source:
void translate(final LogicalJoin join, final TranslatorContext context) { validateJoinQuery(join); boolean isTablePosOnRight = isTable(join.getRight()); List<Integer> streamKeyIds = new LinkedList<>(); List<Integer> tableKeyIds = new LinkedList<>(); populateStreamAndTableKeyIds(((RexCall) join.getCondition()).getOperands(), join, isTablePosOnRight, streamKeyIds, tableKeyIds); JsonSerdeV2<SamzaSqlCompositeKey> keySerde = new JsonSerdeV2<>(SamzaSqlCompositeKey.class); JsonSerdeV2<SamzaSqlRelMessage> relMsgSerde = new JsonSerdeV2<>(SamzaSqlRelMessage.class); Table table = loadLocalTable(isTablePosOnRight, tableKeyIds, keySerde, relMsgSerde, join, context); MessageStream<SamzaSqlRelMessage> inputStream = isTablePosOnRight ? context.getMessageStream(join.getLeft().getId()) : context.getMessageStream(join.getRight().getId()); List<String> streamFieldNames = (isTablePosOnRight ? join.getLeft() : join.getRight()).getRowType().getFieldNames(); List<String> tableFieldNames = (isTablePosOnRight ? join.getRight() : join.getLeft()).getRowType().getFieldNames(); SamzaSqlRelMessageJoinFunction joinFn = new SamzaSqlRelMessageJoinFunction(join.getJoinType(), isTablePosOnRight, streamKeyIds, streamFieldNames, tableFieldNames); MessageStream<SamzaSqlRelMessage> outputStream = inputStream .partitionBy(m -> createSamzaSqlCompositeKey(m, streamKeyIds), m -> m, KVSerde.of(keySerde, relMsgSerde), "stream_" + joinId) .map(KV::getValue) .join(table, joinFn); context.registerMessageStream(join.getId(), outputStream); }

Target:
void translate(final LogicalJoin join, final TranslatorContext context) { validateJoinQuery(join); boolean isTablePosOnRight = isTable(join.getRight()); List<Integer> streamKeyIds = new LinkedList<>(); List<Integer> tableKeyIds = new LinkedList<>(); populateStreamAndTableKeyIds(((RexCall) join.getCondition()).getOperands(), join, isTablePosOnRight, streamKeyIds, tableKeyIds); JsonSerdeV2<SamzaSqlCompositeKey> keySerde = new JsonSerdeV2<>(SamzaSqlCompositeKey.class); JsonSerdeV2<SamzaSqlRelMessage> relMsgSerde = new JsonSerdeV2<>(SamzaSqlRelMessage.class); Table table = loadLocalTable(isTablePosOnRight, tableKeyIds, keySerde, relMsgSerde, join, context); MessageStream<SamzaSqlRelMessage> inputStream = isTablePosOnRight ? context.getMessageStream(join.getLeft().getId()) : context.getMessageStream(join.getRight().getId()); List<String> streamFieldNames = (isTablePosOnRight ? join.getLeft() : join.getRight()).getRowType().getFieldNames(); List<String> tableFieldNames = (isTablePosOnRight ? join.getRight() : join.getLeft()).getRowType().getFieldNames(); Validate.isTrue(streamKeyIds.size() == tableKeyIds.size()); log.info("Joining on the following Stream and Table field(s): "); for (int i = 0; i < streamKeyIds.size(); i++) { log.info(streamFieldNames.get(streamKeyIds.get(i)) + " with " + tableFieldNames.get(tableKeyIds.get(i))); } SamzaSqlRelMessageJoinFunction joinFn = new SamzaSqlRelMessageJoinFunction(join.getJoinType(), isTablePosOnRight, streamKeyIds, streamFieldNames, tableFieldNames); MessageStream<SamzaSqlRelMessage> outputStream = inputStream .partitionBy(m -> createSamzaSqlCompositeKey(m, streamKeyIds), m -> m, KVSerde.of(keySerde, relMsgSerde), "stream_" + joinId) .map(KV::getValue) .join(table, joinFn); context.registerMessageStream(join.getId(), outputStream); }