Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Client side in-memory joins #320

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open

Client side in-memory joins #320

wants to merge 1 commit into from

Commits on Jun 6, 2023

  1. feat: Client side in-memory joins

    API:
    
    First, join object need to be created, which specifies collections and
    join condition:
    ```
    join := tigris.GetJoin[LeftCollModel, RightCollModel](db, "{left field}", "{right field}", [options])
    ```
    This creates a join between LeftCollModel and RightCollModel on
    equality of `{left field}` to `{right field}`.
    
    Created object then can be used to issue one or multiple read requests:
    
    ```
    it, err := join.Read(ctx, filter.Eq("Field1", 1))
    ```
    
    filter condition of read API is applied to the left table.
    Iterator then returns of the rows matching the condition along with the
    corresponding rows from the right table, which satisfies the join
    condition.
    
    var l LeftCollModel
    var r []*RightCollModel
    
    for it.Next(&l, &r) {
      fmt.Printf("l=%v r=%v\n", l, r)
    }
    
    By default the documents which doesn't have matching documents in the right
    table returned in the results. These results can be skipped by providing
    `&JoinOptions{Type: tigris.InnerJoin}` option to GetJoin API.
    
    It is not required for the left field values or right field values to be unique.
    
    The value of the array fields are matched as is by default, by using
    `&JoinOptions{ArrayUnroll: true}` option individual array items can be
    matched in the right table.
    
    Implementation details:
    
    First request is issued to the left table with filter provided to Read API.
    Result is read into memory and request is prepared for the right table.
    Which will have the following filter `filter.Or(filter.Eq("{right field}", {left field value fetched by left query}), ...)`.
    
    Result from the first query is put in the map with {left field} value as the key,
    while reading the result from second query we append it to the corresponding map bucket.
    
    So as merge is done in the memory joins should be used for relatively small
    result sets only.
    efirs committed Jun 6, 2023
    Configuration menu
    Copy the full SHA
    ff7f73f View commit details
    Browse the repository at this point in the history