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

Implement client side in memory joins #280

Open
efirs opened this issue Apr 24, 2023 · 0 comments
Open

Implement client side in memory joins #280

efirs opened this issue Apr 24, 2023 · 0 comments

Comments

@efirs
Copy link
Collaborator

efirs commented Apr 24, 2023

To simplify explanation the proposal below uses this specific example models:

type User struct {
  ID uuid.UUID `json:"id"`
  Name string `json:"name"`
}

type Order struct {
  ID uuid.UUID 
  UserID uuid.UUID `json:"user_id"` // references User's ID field
  Quantity int
}

The API would allow to join two tables based on field equality:

userOrders, err := tigris.GetJoin[User, Order](db, "id", "user_id")

Now results can be read by:

it, err := userOrders.Read(ctx, filter.Eq("name"))

where filter is applied to the left table.

Results could be iterated as:

var user User
var orders []Order

for it.Next(&user, &orders) {
  fmt.Printf("user=%v orders=%v\n", user, orders)
}

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("user_id", {value of id field}), ....).

Result from the first query is put in the map with ID 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, this approach is not effective for very large results.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant