这是indexloc提供的服务,不要输入任何密码
Skip to content

support root collection column references #75

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

Merged
merged 18 commits into from
Jun 12, 2024

Conversation

hallettj
Copy link
Collaborator

@hallettj hallettj commented Jun 12, 2024

Supports root collection column references correctly. We were using $$ROOT which just refers to the current collection. Root references actually reference the collection of the nearest query up the tree in the query request. The query plan that we produce from a query request is structured differently, and has Query values in positions where the request doesn't. So this PR introduces a "scope" concept in the query plan to capture the intended reference scopes from the request.

A couple of notes here on how the MongoDB expressions are evaluated:

The special variable $$ROOT refers to the "current document" being processed by the pipeline. When we look up a relation we use a $lookup stage which has it's own pipeline. If we reference $$ROOT inside if the $lookup pipeline then it resolves to documents in the related collection - the one we are looking up.

On the other hand the $lookup stage also accepts a let map to bind variables. When we reference $$ROOT in a variable assignment in this let map it references the collection we are joining from, not the collection we are joining to. And then the variable bound in the let map is in scope in the $lookup pipeline.

MDB-6

@hallettj hallettj requested review from codedmart and dmoverton June 12, 2024 02:51
@hallettj hallettj self-assigned this Jun 12, 2024
// TODO: This selection illustrates that we end up looking up the relationship twice (once
// with the key `class_students`, and then with the key `class_students_0`). This is
// because the queries on the two relationships have different scope names. The query would
// work with just one lookup. Can we do that optimization?
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we create a ticket for this TODO as well please.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Collaborator

@codedmart codedmart left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

@hallettj hallettj merged commit d102c24 into main Jun 12, 2024
1 check passed
@hallettj hallettj deleted the jesse/root-column-references branch June 12, 2024 23:10
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

Successfully merging this pull request may close these issues.

2 participants