Skip to content

Generate find projections - #4596

Open
evanchooly wants to merge 1 commit into
audits-query-bindingsfrom
audits-find-projections
Open

evanchooly wants to merge 1 commit into
audits-query-bindingsfrom
audits-find-projections

Conversation

@evanchooly

Copy link
Copy Markdown
Member

Stacked on #4595. Self-reviewed only.

What this solves

Every find whose page documents a projection was a gap: "a documented projection is not generated yet". That was the largest remaining reason in gaps.json (17 examples). For example, db.movies.find( { "imdb.rating": { $type: "string" }, year: 2013 }, { _id: 0, title: 1, year: 1, "imdb.rating": 1 } ) was skipped, though Morphia can write that projection, and its filter already bound after #4595.

10 cases now generate (477 → 487): four $text, three $type, two $ne and one $in.

Integration: 499 tests under Critter, then reflection, 0 failures. Audits suite: 444 tests, 0 failures, 4 skipped.

How

A find's documented projection becomes the FindOptions passed to runner.find, which already compares Morphia's mapped projection with the page's. Before the result comparisons, the runner also runs the documented projection through the driver.

  • Flags: 0, 1, true and false become .projection().include(...) and .projection().exclude(...).
    • Projection.map writes inclusions, then exclusions. The only reorder that can happen is a lone _id: 0 moving after the inclusions, which PROJECT_ID_FIRST already equates.
    • true/false take PROJECTION_FLAGS.
  • $meta: a projection that is only {f: {$meta: k}} becomes project(Meta.k("f")), for the keywords Meta has a factory for (textScore, indexKey, searchScore, searchHighlights).
  • Gaps:
    • $slice, $elemMatch and expression values;
    • $meta beside other fields, which Projection rejects;
    • inclusions beside exclusions other than _id;
    • flags written as Int64 or Double, which Projection.map writes as Int32.

Decisions for review

  • Two $meta finds are reviewed exclusions. Serialization and behavior pass for both:
    • textScore: the find has no sort, and two matches tie on score. The page prints one order and the server returns another.
    • indexKey in a find: the seed documents have no _id, so the server generates ObjectIds. The page prints those from its own run.
  • Order-sensitive comparison: generated scenarios always compare results in order (ordered = true). A find or pipeline without a sort could compare them unordered instead, which would be more correct for cases like the textScore one. That would change every generated scenario, so I left it for a separate change if you want it.

Review

Codex, two local rounds. Round 1 found the Int64 and Double flag case, which is now a gap with a regression case. Round 2 was clean.

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