-
Type:
Task
-
Resolution: Unresolved
-
Priority:
Minor - P4
-
None
-
Affects Version/s: None
-
Component/s: None
-
None
-
Query Optimization
-
None
-
None
-
None
-
None
-
None
-
None
-
None
We currently do not type computed fields like:
{$set: {a: {$add: [...]}}
{$set: {a: {$toLower: "$b"}} etc.
Suggested solution
The general practice in the dependency graph has been to compute the metadata of fields when we process the stage declaring the field, and to do additional type narrowing, using applicable $match stages, between the declaration site and the call site.
I think we can continue that pattern. We already process per-expression dependencies at processExpressionDependencies
Depending on how accurate we want types to be, and if we want to pay the extra performance cost we could:
- just call getOutputType(expression, input=anyType) passing unknown types for the dependent paths
- OR use getDocumentType to infer the types of all dependent paths and call getOutputType with the more refined input, for a more refined output type
Then we can cache the type using setType.
Priority
Since we plan to type logical aggregation expression in SPM-3491, there will be no tangible impact of this ticket on the project goals, other than for unusual cases like {$set: {a: {$not: ..}}}, where we can decide 'a' must be boolean.
However this will be groundwork for future projects/tickets to that might want to add have type information for computed fields.