handle column references that involve variables #74
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 support root column references we need to handle column references that involve variables. Currently we're using the built-in variable
$$ROOT
to reference the root collection (which is wrong, but we'll fix that in another PR, and the correct solution will also require a variable.) Before this PR our column references don't work with variable references like$$ROOT
due to the two different kinds of expressions that are found in MongoDB aggregation pipelines. Specifically there are,$match
aggregation stageThe code we had would create a match stage like this:
That doesn't work because
"$$ROOT.field"
is in a match query context which does not allow using$
to reference field names or variables. But there is a match query operator,$expr
, that switches to an aggregation expression context. So the correct solution looks like this:This PR updates the code for producing
$match
stages to use switch to aggregation expression context to handle cases like this. Specifically I introduced an enum,ColumnRef
, which signals cases where the reference needs to be in an aggregation expression context.Since we're now supporting both expression contexts it's now possible to handle binary and unary comparisons on field names that contain
$
or.
without erroring out. This PR does that by replacing uses ofsafe_name
(which can throw errors) in$match
stage building withColumnRef::from_comparison_target
(which does not throw errors).Supporting aggregation expression contexts was also a blocker for column-to-column binary comparisons. So I added that support to this PR. But those comparisons don't support relationship paths for the time being.
MDB-154