Skip to content

Generate $match, $group and $sort pipelines and sample-dataset cases - #4572

Open
evanchooly wants to merge 1 commit into
audits-ranked-sortbyfrom
audits-match-filters
Open

evanchooly wants to merge 1 commit into
audits-ranked-sortbyfrom
audits-match-filters

Conversation

@evanchooly

Copy link
Copy Markdown
Member

Step 5 of the operator-audit plan: bindings for the gaps the weekly job files. Stacked on #4571, the Morphia fix this work found.

Problem

After #4570, the inventory showed 115 unowned examples, but the generator produced only one case. The gaps:

  • No query filters. 29 expression examples were blocked on stage $match has no binding. $match takes a query document, which the generator couldn't emit as Morphia Filters.
  • No $group, $sort or accumulators. Behind $match were $group (17), the ranked and n-valued accumulators ($top, $bottomN, $firstN, $maxN, ...), $sort and $unwind.
  • Sample datasets. All 29 of those examples query MongoDB's sample_mflix dataset and seed nothing. The runner can't load that dataset, so even with bindings their results can't be checked.

Change

Binding forms (DslBindings, verified against core's API as before):

Form MQL Emitted
FILTERS ($match) {genres: "Short", year: {$gte: 2010, $lte: 2012}} match(eq("genres", "Short"), gte("year", 2010), lte("year", 2012))
FIELD (new FILTER position) {$in: [...]}, {$exists: true} in("rated", List.of(...)), exists("imdb.rating")
GROUP {_id: "$year", best: {...}} group(id("$year")).field("best", ...)
SORT {_id: 1, n: -1} sort().ascending("_id").descending("n")

New bindings:

  • Filters: $eq, $ne, $gt, $gte, $lt, $lte, $in, $exists.
  • Stages: $match, $group, $sort, $unwind.
  • Accumulators and expressions: $top, $bottom, $topN, $bottomN, $firstN, $lastN, $maxN, $minN, $map, $convert.
  • Array literals: a [] entry binding them to ArrayExpressions.array, which is how the handwritten tests spell $top's output. Morphia's wrap rejects a plain List.

The emitter also writes Iterable arguments as List.of(...) and a sort document as Sort varargs (descending("imdb.rating"), ascending("title")).

Declared rules. Morphia writes an implicit equality as {$eq: v}, and splits several operators on one field into one filter each. A generated scenario declares exactly the rules its spelling needs, EQ_SHORTHAND and FIELD_OPERATORS_AND, the same reviewed rules converted cases use.

Sample-dataset cases.

  • generation-review.json gains sampleDatasets (movies → sample_mflix).
  • An example that seeds no data and queries one of those collections gets dataset: "sample_mflix" and skipped.results with the reason, so only its serialization is checked: Morphia must still build exactly the documented pipeline.
  • OperatorCaseRunner accepts a dataset only alongside that skip.

Result

  • 10 newly generated cases: $top ×2, $bottom ×2, $topN, $bottomN, $firstN, $maxN and $minN. They were integrated under both mappers in a clean worktree, then promoted. The manifest now lists 11 generated cases.
  • Integration found a real Morphia bug: with two sort keys, $topN/$bottomN wrote sortBy as an array. That's fixed separately in Encode a ranked accumulator's sortBy as one document #4571.
  • Remaining gaps the weekly job will file: $serializeEJSON, $deserializeEJSON, $toObject, $toArray, $hexHash, $percentile, $limit, $type, a compound $group _id, two $convert options, and $reduce's valueAs.

Decisions for review

  • Serialization-only cases for sample datasets. Loading sample_mflix into the test server would be a large fixture for little gain. The alternative is leaving these examples unchecked. The scenario names the dataset and the skip, so nothing passes quietly.
  • Rules declared by the generator, rather than added to every generated scenario: a rule appears only when the emitted spelling needs it.
  • $type stays a gap. Morphia's Type constants are named by BSON type number (INTEGER_32), not by MQL alias (int), so it needs a reviewed alias map rather than the upper-casing that ConvertType happens to match.

Verification

  • GeneratorTest.sampleDatasetExamplesCheckTheirSerialization runs the committed catalog over a page and checks:
    • the generated Java for filters, $group, $top with two sort keys, and $sort;
    • the scenario's dataset, its skip and its rules;
    • three gaps: a compound _id, $exists: false and $type.
  • Audits suite: 456 pass under Critter, then reflection.
  • Core operator tests: 689 pass under both mappers.

Self-reviewed only: the independent reviewers are out of quota until 2026-11-26.

The generator binds query filters ($match with $eq, $ne, $gt, $gte, $lt,
$lte, $in and $exists), $group, $sort, $unwind, the ranked and
n-valued accumulators, $map and $convert, and array literals. Generated
scenarios declare the form rules their spelling needs. An example that
seeds nothing and queries a reviewed sample collection names its dataset
and skips its results checks, so only its serialization is checked; the
runner accepts a dataset only with that skip.

Ten documented examples are now generated, integrated under both mappers
and promoted.

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