Class RightChunkedLeftJoin

java.lang.Object
org.elasticsearch.compute.operator.lookup.RightChunkedLeftJoin
All Implemented Interfaces:
Closeable, AutoCloseable, org.elasticsearch.core.Releasable

public class RightChunkedLeftJoin extends Object implements org.elasticsearch.core.Releasable
Performs a LEFT JOIN where many "right hand" pages are joined against a "left hand" Page. Each row on the "left hand" page is output at least once whether it appears in the "right hand" or not. And more than once if it appears in the "right hand" pages more than once.

The "right hand" page contains a non-decreasing positions column that controls which position in the "left hand" page the row in the "right hand" page. This'll make more sense with a picture:


 "left hand"                 "right hand"
 | lhdata |             | positions | r1 | r2 |
 ----------             -----------------------
 |    l00 |             |         0 |  1 |  2 |
 |    l01 |             |         1 |  2 |  3 |
 |    l02 |             |         1 |  3 |  3 |
 |    ... |             |         3 |  9 |  9 |
 |    l99 |
 

Joins to:


 | lhdata  |  r1  |  r2  |
 -------------------------
 |     l00 |    1 |    2 |
 |     l01 |    2 |    3 |
 |     l01 |    3 |    3 |   <1>
 |     l02 | null | null |   <2>
 |     l03 |    9 |    9 |
 
  1. l01 is duplicated because it's positions appears twice in the right hand page.
  2. l02's row is filled with nulls because it's position does not appear in the right hand page.

This supports joining many "right hand" pages against the same "left hand" so long as the first value of the next positions column is the same or greater than the last value of the previous positions column. Large gaps are fine. Starting with the same number as you ended on is fine. This looks like:


 "left hand"                 "right hand"
 | lhdata |             | positions | r1 | r2 |
 ----------             -----------------------
 |    l00 |                    page 1
 |    l01 |             |         0 |  1 |  2 |
 |    l02 |             |         1 |  3 |  3 |
 |    l03 |                    page 2
 |    l04 |             |         1 |  9 |  9 |
 |    l05 |             |         2 |  9 |  9 |
 |    l06 |                    page 3
 |    ... |             |         5 | 10 | 10 |
 |    l99 |             |         7 | 11 | 11 |
 

Which makes:


 | lhdata  |  r1  |  r2  |
 -------------------------
         page 1
 |     l00 |    1 |    2 |
 |     l01 |    3 |    3 |
         page 2
 |     l01 |    9 |    9 |
 |     l02 |    9 |    9 |
         page 3
 |     l03 | null | null |
 |     l04 | null | null |
 |     l05 |   10 |   10 |
 |     l06 | null | null |
 |     l07 |   11 |   11 |
 

Note that the output pages are sized by the "right hand" pages with nulls inserted.

Finally, after all "right hand" pages have been joined this will produce all remaining "left hand" rows joined against null. Another picture:


 "left hand"                 "right hand"
 | lhdata |             | positions | r1 | r2 |
 ----------             -----------------------
 |    l00 |                    last page
 |    l01 |             |        96 |  1 |  2 |
 |    ... |             |        97 |  1 |  2 |
 |    l99 |
 

Which makes:


 | lhdata  |  r1  |  r2  |
 -------------------------
     last matching page
 |     l96 |    1 |    2 |
 |     l97 |    2 |    3 |
    trailing nulls page
 |     l98 | null | null |
 |     l99 | null | null |
 
  • Constructor Details

    • RightChunkedLeftJoin

      public RightChunkedLeftJoin(Page leftHand, int mergedElementCounts)
  • Method Details

    • join

      public Page join(Page rightHand)
    • noMoreRightHandPages

      public Optional<Page> noMoreRightHandPages()
    • releaseOnAnyThread

      public void releaseOnAnyThread()
      Release this on any thread, rather than just the thread that built it.
    • close

      public void close()
      Specified by:
      close in interface AutoCloseable
      Specified by:
      close in interface Closeable
      Specified by:
      close in interface org.elasticsearch.core.Releasable