Skip to content

Generate cases for $merge, $out and $unwind's options - #4592

Open
evanchooly wants to merge 1 commit into
audits-capability-bindingsfrom
audits-write-generation
Open

evanchooly wants to merge 1 commit into
audits-capability-bindingsfrom
audits-write-generation

Conversation

@evanchooly

Copy link
Copy Markdown
Member

Stacked on #4590.

Problems

1. $merge and $out examples never generated. The generator had no binding for either stage, so every example ending in one was an UNBOUND gap (stage $merge has no binding). The read pairing from #4589 (a find after a write joins the write's scenario) had nothing to attach to.

2. $unwind's options couldn't generate. $unwind was bound positionally, so { $unwind: { path: "$genres", includeArrayIndex: "genreIndex" } } was a gap: a document literal has no binding.

3. Some MQL enum values could never compile. The generator upper-cased an enum value, so whenMatched: "keepExisting" became WhenMatched.KEEPEXISTING, not KEEP_EXISTING.

Changes

  • Shorthand for named bindings: dsl-bindings.json gains shorthand. A NAMED operator of one argument also takes that argument alone, so {$out: "coll"}, {$merge: "coll"} and {$unwind: "$x"} emit out("coll"), merge("coll") and unwind("$x"). DslBindings.verify rejects shorthand on anything but a one-argument named binding.
  • Varargs options: an option whose last parameter is an array takes one value or an array's items, e.g. $merge's on: ["_id", "region"] → .on("_id", "region").
  • Enum values: camelCase MQL values become upper snake case, for Morphia's enums and the driver's (com.mongodb.): keepExisting → KEEP_EXISTING.
  • New bindings: $merge (into, plus on, whenMatched and whenNotMatched) and $out (coll). $unwind moves to NAMED with includeArrayIndex and preserveNullAndEmptyArrays.
  • $merge key order: $merge joins the named-argument operators in both comparison implementations (FormEquivalence and core's FormRules). The server ignores its key order, and Morphia writes a fixed one.
  • New gaps, for cases that would otherwise generate a failing test:
    • a stage naming another database ({ $out: { db: "reporting", coll: ... } }), which OperatorCaseRunner refuses because both behavior runs would share it;
    • a shorthand operator spelled as a document with no options ({ $merge: { into: "t" } }), which Morphia writes as the short form. $unwind is the exception, since the existing UNWIND_PATH rule covers it;
    • a one-item array for a varargs option (on: ["_id"]), which MergeCodec writes as on: "_id".

Result

Five new generated cases, integrated under Critter and then reflection (457 tests each, all passing):

  • $merge: "Merge Results from Multiple Collections" and "Only Insert New Data";
  • $out: "Output to Same Database";
  • $unwind: includeArrayIndex and preserveNullAndEmptyArrays.

The $merge and $out examples query the movies sample dataset, which the tests don't load, so only their serialization is checked.

Decisions for review

  • The seeded $merge examples with paired reads still don't generate. "Summarize Ratings", "Update/Replace Data" and "Use the Pipeline to Customize the Merge" are blocked by a compound $group _id, a date literal and $dateToString, not by $merge. Those are expression-binding work, so I left them for a separate step.
  • Pipeline updates stay unbound. The only example, $currentDate's aggregation alternative, also needs a document literal, so adding pipeline-update emission would generate nothing yet.
  • I removed the $out db option from the binding rather than keeping an option that every use would make a gap.
  • Binding keepExisting exposed a core bug: MergeCodec wrote keep_existing, which the server rejects. The fix is Write $merge's keepExisting as the server spells it #4591, off master. No generated case here uses keepExisting; only the offline generator test does.

Codex review: round 1 found the three failing-test spellings above, now gaps or rules with regression tests; round 2 was clean. The audits suite passes: 443 tests, 0 failures, 4 skipped.

Self-reviewed only.

Bind $merge and $out as named stages with a shorthand for their one-argument
spelling, and $unwind as a named stage so its options generate. Options whose
last parameter is an array spread an array's items, and enum values convert
camel case to the driver's constants. Stages naming another database, and
spellings Morphia writes otherwise, are gaps.

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