Internals of Merge-Join and Merge-Left-Join

This document gives the user guide and describes the structure of Merge-Join and Merge-Left-Join, implemented as mergeJoin function and mergeLeftJoin function respectively.

User guide

When calling the mergeJoin/mergeLeftJoin function, users need to set the key type and payload type. Only one key stream and one payload stream is given for an input table. If multiple key columns or multiple payload columns are required, please use the combineCol to combine columns.

The user needs to push input tables into the related streams. Users also need to configure the function to merge ascend/descend tables by setting the isascend parameter to true/false.

Caution

The left table should not contain duplicated keys.

The left and right result tables are pushed out in separate stream. If required, please use the combineCol to combine left and right table into one stream.

Important

The mergeLeftJoin function has a isnull_strm output stream to mark if the result right table is null (The current left key does not exist in the right table).

Structure

Use the merge join of ascend tables as an example:
Merge Join Structure

Every clock cycle, compare the keys from left and right tables:

  • If the keys are not the same, pull the stream with a smaller key and no output.
  • If the keys are the same, pull the right stream and push the keys and payloads to the output stream.