-
Notifications
You must be signed in to change notification settings - Fork 1
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
fix complex filtering expressions involving variables or field names that require escaping #111
Merged
hallettj
merged 17 commits into
main
from
jessehallett/eng-1020-nested-expressions-do-not-work-if-they-require-switch-to
Oct 4, 2024
Merged
fix complex filtering expressions involving variables or field names that require escaping #111
hallettj
merged 17 commits into
main
from
jessehallett/eng-1020-nested-expressions-do-not-work-if-they-require-switch-to
Oct 4, 2024
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
…not-work-if-they-require-switch-to
codedmart
approved these changes
Oct 4, 2024
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍
hallettj
deleted the
jessehallett/eng-1020-nested-expressions-do-not-work-if-they-require-switch-to
branch
October 4, 2024 22:50
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
To filter results we use MongoDB's
$match
aggregation stage. This stage uses a shorthand "query document" syntax that looks generally like this:Query documents have some limitations:
.
) since that is interpreted as a nested field path.There is more general MongoDB expression language, "aggregation expressions" that does not have these shortcomings. A
$match
stage can opt in to comparing using an aggregation expression instead of a query document using this syntax:This switch must be made at the top-level of the
$match
argument so this is all-or-nothing.The previous expression generation code made the switch to an aggregation expression in cases where it was necessary. But it did not correctly handle cases where an NDC expression that must be translated to an aggregation expression is embedded in a larger expression. In other words it did not handle complex expressions corrrectly.
This change fixes the problem by splitting expression generation into two independent functions.
make_query_document
builds the shorthand query document, but aborts if that is not possible for a given expressionmake_aggregation_expression
builds aggregation expressions - this is the fallback ifmake_query_document
failsAlong the way I implemented column-to-column comparisons in cases where the left operand (the target) is a column in a relation. But I left the case where the right operand is in a relation unimplemented. We probably don't need that anyway: NDC is moving away from allowing relationship paths in
ColumnTarget
, and is moving to explicit "exists" operations instead.Fixes ENG-1020, ENG-942