Skip to content

Generate $setWindowFields and $year - #4598

Open
evanchooly wants to merge 1 commit into
audits-document-literalsfrom
audits-window-fields
Open

evanchooly wants to merge 1 commit into
audits-document-literalsfrom
audits-window-fields

Conversation

@evanchooly

Copy link
Copy Markdown
Member

Stacked on #4597. Self-reviewed only.

What this solves

Every $setWindowFields example was a gap ("stage $setWindowFields has no binding"), though Morphia's SetWindowFields builder writes them all. For example:

{ $setWindowFields: { partitionBy: { $year: "$released" }, sortBy: { released: 1 },
    output: { cumulativeRuntimeForYear: { $sum: "$runtime", window: { documents: [ "unbounded", "current" ] } } } } }

is setWindowFields().partitionBy(year("$released")).sortBy(ascending("released")).output(output("cumulativeRuntimeForYear").operator(sum("$runtime")).window().documents("unbounded", "current")).

All six documented examples now generate (497 → 503). They query the movies sample dataset, which the tests don't load, so only their serialization is checked.

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

How

  • The stage: $setWindowFields binds as a named stage with no arguments. partitionBy, sortBy and output are its options.
  • Outputs: output's SetWindowFields.Output[] parameter gets a type-driven conversion, as Sort[] already has. Each output field becomes output(name).operator(op), plus .window().documents(l, u) or .window().range(l, u[, unit]), where the unit is a TimeUnit constant.
  • Gaps:
    • an output with zero or several operators;
    • a key other than the operator and window;
    • a window before its operator, or a unit before its range (SetWindowFieldsCodec's order);
    • a bound other than a string or Int32.
  • $year: binds year(Object), which four of the examples partition by.
  • Key order: $setWindowFields joins the named-argument operators in both rule ports.

A generator gap fixed along the way

One-item argument arrays were emitted bare with no declared rule. For example, {$year: ["$released"]} became year("$released"), which writes {$year: "$released"}. Now:

  • One-argument operators: a one-item array declares SINGLE_ARGUMENT_ARRAY when that rule lists the operator. $year is added to the list in both ports. For any other one-argument operator, it's a gap.
  • Varargs factories: a one-item array is a gap ({$sum: ["$a"]}), because sum("$a") writes the argument bare. The exceptions are array and concatArrays, which always write an array.

The candidate check showed neither guard removes a committed case.

Decisions for review

  • Builder calls named in the generator: the Output/Window calls (output, operator, window, documents, range) are named in CaseGenerator, not in dsl-bindings.json, the way Sort's directions are. Binding verification doesn't check them, but integration's compile does.

Review

Codex ran three local rounds: round 1 found the one-argument array case, round 2 the varargs one, and round 3 was clean. Each fix has 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