Merging code for TopKRankJoin