Skip to content

Bind more expression operators and spread named varargs - #4601

Open
evanchooly wants to merge 1 commit into
audits-unordered-resultsfrom
audits-more-expressions
Open

evanchooly wants to merge 1 commit into
audits-unordered-resultsfrom
audits-more-expressions

Conversation

@evanchooly

Copy link
Copy Markdown
Member

Stacked on #4600. Self-reviewed only.

What this does

Group 2 of the generator gaps: examples where Morphia has the API but the generator had no binding. 21 expression operators bind, and 14 more documented examples generate (511 to 525). Integration passes with 537 tests under each mapper.

New bindings: $allElementsTrue, $anyElementTrue, $arrayElemAt (elementAt), $binarySize, $bsonSize, $divide, $literal, $ltrim, $not, $range, $rtrim, $setIntersection, $size, $stdDevPop, $stdDevSamp, $strLenCP, $subtract, $trim, $tsIncrement, $type and $zip.

Generator changes, each with the case it fixes

  • Named varargs spread. {$zip: {inputs: ["$a", "$b"]}} had no form, because zip(Object...) takes its inputs as varargs. A named argument whose parameter is the factory's Object varargs now spreads its array, giving zip("$a", "$b"). An empty array and a lone null, which Java reads as the varargs array itself, are gaps.
  • One-argument operators whose factories always write an array. not(x), allElementsTrue(x) and anyElementTrue(x) write [x], while pages often write {$not: x}. These now join the always-array set: a one-item array is exact, and a bare operand gets SINGLE_ARGUMENT_ARRAY. That rule now lists all three, in both FormEquivalence.kt and FormRules.java.
  • Expressions where Morphia takes a Java value. {$trim: {chars: {$literal: "x"}}} generated chars(literal("x")), which doesn't compile because chars(String) takes only a string. {$convert: {to: {$literal: "string"}}} hits the same problem with ConvertType. An operator is now generated only where the parameter takes an expression (Object, Expression, or a DSL type built from operators); anywhere else it is a gap.
  • Other new gaps:
    • A $literal operand holding a $ key: the generator would translate it as an operator, and encoding fails.
    • A null operand to $arrayElemAt, $divide or $subtract, whose factories build a List.of.
  • $trim, $ltrim and $rtrim join the named-argument operators, because the server reads input and chars in either order.

Reviewed exclusions (page errors)

Five more examples generate but fail behavior. In each, Morphia's result is the server's correct answer and the page is wrong:

  • divide/divideHoursIntoWorkdays: seeds conferencePlanning but aggregates planning.
  • binarySize/findLargestBinaryData and bsonSize/returnDocumentWithLargestSpecifiedField: the pipelines sort and $limit: 1, but the pages print every document from the first stage. The bsonSize sizes are also off (152 vs the server's 140).
  • reduce/discountedMerchandise: prints ObjectId _ids for integer seeds.
  • regexFind/useCapturedGroupingsToParseUserName: prints the $addFields output, not the result after $set.

Decisions to review

  • SINGLE_ARGUMENT_ARRAY now covers $not, $allElementsTrue and $anyElementTrue. This assumes the server reads {$not: x} and {$not: [x]} the same, which holds for expression $not. The rule already skips query positions, such as $match's {a: {$not: …}}.
  • Deferred. Codex noted that the rule's query guard doesn't recognize a filter nested in $graphLookup's restrictSearchWithMatch, so it would rewrite a query $not there. $size already has the same exposure. $graphLookup has no binding, so nothing reaches that position today. I left it for when $graphLookup binds.
  • Left as gaps:
    • $filter with $zip, which needs $let; that would need a new form.
    • $median/$percentile, whose pages pass method, which Morphia fixes.
    • $mergeObjects and $dateToString, whose factories are builders.

Review

Codex: 3 rounds. Round 1 found 5 issues (4 fixed, 1 deferred as above), round 2 found 2 and round 3 found 1, all fixed. Design docs updated: the progress entry and the SINGLE_ARGUMENT_ARRAY row in operator-audits-form-migration.md.

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