Skip to content

Generate $lookup, comparison and boolean expressions, $replaceWith and $sortArray - #4599

Open
evanchooly wants to merge 1 commit into
audits-window-fieldsfrom
audits-lookup
Open

evanchooly wants to merge 1 commit into
audits-window-fieldsfrom
audits-lookup

Conversation

@evanchooly

Copy link
Copy Markdown
Member

Stacked on #4598. Self-reviewed only.

What this solves

Three $lookup subquery examples, two $sortArray examples, and examples that use comparison or boolean expressions were gaps, though Morphia writes them all. For example, $lookup: { from: "stock", let: { name: "$item" }, pipeline: [ { $match: { $expr: { $and: [ { $eq: [ "$sku", "$$name" ] }, … ] } } } ], as: "stock" } stopped at "stage $lookup has no binding". Once that was bound, it stopped again at "$and has no binding".

7 cases now generate (503 → 510):

  • the three $lookup subquery examples;
  • two $sortArray;
  • one $unsetField;
  • one $filter limit example.

Integration: 522 tests under Critter, then reflection, 0 failures. Audits suite: 447 tests, 0 failures, 4 skipped. No committed case changed.

How

  • $lookup: a named stage, lookup(from), with localField, foreignField, as, let and pipeline options.
    • An option of a name and a value takes a document, one call per field: .let("a", x).let("b", y).
    • A Stage[] parameter takes a subpipeline's stages.
  • Expressions: $cmp, $gt, $gte, $lt, $lte, $ne, $and, $or, $arrayToObject and $sortArray. $sortArray's sortBy document becomes Sort varargs.
  • Stage: $replaceWith.
  • Named-argument operators: $setField and $unsetField bind, and join that list in both rule ports.
  • Always-array factories: $and and $or write an ExpressionList, an array even for one argument. So a one-item array is exact for them and a bare operand is a gap, as for $concatArrays.

Gaps, each mirroring Morphia's behavior

  • $lookup:
    • let without a pipeline, since LookupCodec writes let only beside one;
    • a document inside a variable's array.
  • Nulls:
    • a null operand to $cmp, $gt, $gte, $lt or $lte, whose factories build a List.of;
    • a null $setField/$unsetField argument, which their codecs drop.
  • $setField: an expression as its input, which SetFieldExpressionCodec writes without opening its document.
  • Sorts: a $ key in a sort document ($natural), and an empty sort document.

Decisions for review

  • Two possible core bugs: an expression as $setField's input fails to encode. So does a document inside an array in a DocumentExpression, as in $lookup's let here and document literals in Generate document literals, compound group ids, $cond and $concatArrays #4597. Both are only gaps here; they may deserve core issues.
  • One reviewed exclusion: $replaceWith's "Pivot Sales by Quarter" groups without sorting, and the driver's run and Morphia's returned the groups in different orders. That's the second case to fail only on order (after $meta's text score in Generate find projections #4596). I recommend a separate PR that compares results unordered when a find or pipeline doesn't sort.
  • Still waiting: $setField's two remaining examples need $literal, whose operand may itself be an array. That needs its own form.

Review

Codex ran three local rounds, finding three, three and one issues. Each is now a gap with a regression case in GeneratorTest. The design doc and the progress log are updated.

This branch has not been deployed

No deployments
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.

1 participant