From 09a98c7f8ed86a0a56603b41edfe9c6b96670633 Mon Sep 17 00:00:00 2001 From: evanchooly Date: Mon, 23 Nov 2026 09:45:11 -0500 Subject: [PATCH] Generate $match, $group and $sort pipelines and sample-dataset cases 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. --- audits/README.md | 2 +- audits/catalog/dsl-bindings.json | 407 ++++++++++++++++++ audits/catalog/generation-review.json | 5 +- .../morphia/audits/generate/CaseGenerator.kt | 148 ++++++- .../morphia/audits/generate/DslBindings.kt | 47 +- .../audits/repairs/FixtureMigration.kt | 13 +- .../morphia/audits/offline/GeneratorTest.kt | 99 +++++ .../dev/morphia/test/OperatorCaseRunner.java | 6 +- .../generated/expressions/TestBottom.java | 48 +++ .../generated/expressions/TestBottomN.java | 35 ++ .../generated/expressions/TestFirstN.java | 34 ++ .../test/generated/expressions/TestMaxN.java | 47 ++ .../test/generated/expressions/TestMinN.java | 31 ++ .../test/generated/expressions/TestTop.java | 49 +++ .../test/generated/expressions/TestTopN.java | 35 ++ .../scenario.json | 163 +++++++ .../findTheBottomRatingInAGenre/scenario.json | 90 ++++ .../scenario.json | 127 ++++++ .../scenario.json | 123 ++++++ .../scenario.json | 182 ++++++++ .../scenario.json | 101 +++++ .../scenario.json | 92 ++++ .../scenario.json | 182 ++++++++ .../findTheTopRatingInAGenre/scenario.json | 95 ++++ .../scenario.json | 129 ++++++ .../dev/morphia/test/generated/manifest.json | 118 +++++ design/operator-audits-design.md | 32 +- design/operator-audits-progress.md | 24 +- design/operator-audits-reference.md | 5 + 29 files changed, 2446 insertions(+), 23 deletions(-) create mode 100644 core/src/test/java/dev/morphia/test/generated/expressions/TestBottom.java create mode 100644 core/src/test/java/dev/morphia/test/generated/expressions/TestBottomN.java create mode 100644 core/src/test/java/dev/morphia/test/generated/expressions/TestFirstN.java create mode 100644 core/src/test/java/dev/morphia/test/generated/expressions/TestMaxN.java create mode 100644 core/src/test/java/dev/morphia/test/generated/expressions/TestMinN.java create mode 100644 core/src/test/java/dev/morphia/test/generated/expressions/TestTop.java create mode 100644 core/src/test/java/dev/morphia/test/generated/expressions/TestTopN.java create mode 100644 core/src/test/resources/dev/morphia/test/generated/fixtures/expressions/bottom/findTheBottomRatingAcrossMultipleYears/scenario.json create mode 100644 core/src/test/resources/dev/morphia/test/generated/fixtures/expressions/bottom/findTheBottomRatingInAGenre/scenario.json create mode 100644 core/src/test/resources/dev/morphia/test/generated/fixtures/expressions/bottomN/findTheThreeLowestRatedMoviesInASingleGenre/scenario.json create mode 100644 core/src/test/resources/dev/morphia/test/generated/fixtures/expressions/firstN/findTheFirstThreeMoviesForASingleGenre/scenario.json create mode 100644 core/src/test/resources/dev/morphia/test/generated/fixtures/expressions/maxN/findTheThreeHighestRatedMoviesAcrossMultipleYears/scenario.json create mode 100644 core/src/test/resources/dev/morphia/test/generated/fixtures/expressions/maxN/findTheThreeHighestRatedMoviesForASingleYear/scenario.json create mode 100644 core/src/test/resources/dev/morphia/test/generated/fixtures/expressions/minN/findTheMinimumThreeRatingsForASingleGenre/scenario.json create mode 100644 core/src/test/resources/dev/morphia/test/generated/fixtures/expressions/top/findTheTopRatingAcrossMultipleRatings/scenario.json create mode 100644 core/src/test/resources/dev/morphia/test/generated/fixtures/expressions/top/findTheTopRatingInAGenre/scenario.json create mode 100644 core/src/test/resources/dev/morphia/test/generated/fixtures/expressions/topN/findTheThreeHighestRatedMoviesInASingleGenre/scenario.json diff --git a/audits/README.md b/audits/README.md index fcaa1a91d3e..9f803c59dcc 100644 --- a/audits/README.md +++ b/audits/README.md @@ -34,7 +34,7 @@ Every command below runs through the exec plugin from the repository root, after | --- | --- | | `audits/catalog/documented-examples.json` | Every example on the current operator pages, with its owner; unowned examples keep their source text. | | `audits/catalog/dsl-bindings.json` | Reviewed MQL-to-Morphia factory bindings the generator uses. | -| `audits/catalog/generation-review.json` | The generated families and the reviewed exclusions, each with its evidence. | +| `audits/catalog/generation-review.json` | The generated families, the reviewed exclusions with their evidence, and the sample-dataset collections. | | `audits/catalog/fixture-migration.json` | The ledger of legacy cases moved onto the case runner, with their documented sources. | | `audits/catalog/cutover.json` | Legacy cases that stay on the legacy path, with the check that fails and its first difference. | | `audits/catalog/form-review.json`, `form-migration.json` | Reviewed equivalences that retired MORPHIA_FORM locks, and the gaps left. | diff --git a/audits/catalog/dsl-bindings.json b/audits/catalog/dsl-bindings.json index 2d8333d96f5..30c13ff7041 100644 --- a/audits/catalog/dsl-bindings.json +++ b/audits/catalog/dsl-bindings.json @@ -46,6 +46,44 @@ "options": {}, "fields": {} }, + { + "operator": "$bottom", + "position": "EXPRESSION", + "form": "NAMED", + "owner": "dev.morphia.aggregation.expressions.AccumulatorExpressions", + "method": "bottom", + "parameters": [ + "java.lang.Object", + "dev.morphia.query.Sort[]" + ], + "varargs": true, + "arguments": [ + "output", + "sortBy" + ], + "options": {}, + "fields": {} + }, + { + "operator": "$bottomN", + "position": "EXPRESSION", + "form": "NAMED", + "owner": "dev.morphia.aggregation.expressions.AccumulatorExpressions", + "method": "bottomN", + "parameters": [ + "java.lang.Object", + "java.lang.Object", + "dev.morphia.query.Sort[]" + ], + "varargs": true, + "arguments": [ + "n", + "output", + "sortBy" + ], + "options": {}, + "fields": {} + }, { "operator": "$concat", "position": "EXPRESSION", @@ -61,6 +99,24 @@ "options": {}, "fields": {} }, + { + "operator": "$convert", + "position": "EXPRESSION", + "form": "NAMED", + "owner": "dev.morphia.aggregation.expressions.TypeExpressions", + "method": "convert", + "parameters": [ + "java.lang.Object", + "dev.morphia.aggregation.expressions.impls.ConvertType" + ], + "varargs": false, + "arguments": [ + "input", + "to" + ], + "options": {}, + "fields": {} + }, { "operator": "$dateDiff", "position": "EXPRESSION", @@ -134,6 +190,103 @@ "varargs": false, "fields": {} }, + { + "operator": "$firstN", + "position": "EXPRESSION", + "form": "NAMED", + "owner": "dev.morphia.aggregation.expressions.AccumulatorExpressions", + "method": "firstN", + "parameters": [ + "java.lang.Object", + "java.lang.Object" + ], + "varargs": false, + "arguments": [ + "n", + "input" + ], + "options": {}, + "fields": {} + }, + { + "operator": "$lastN", + "position": "EXPRESSION", + "form": "NAMED", + "owner": "dev.morphia.aggregation.expressions.AccumulatorExpressions", + "method": "lastN", + "parameters": [ + "java.lang.Object", + "java.lang.Object" + ], + "varargs": false, + "arguments": [ + "n", + "input" + ], + "options": {}, + "fields": {} + }, + { + "operator": "$map", + "position": "EXPRESSION", + "form": "NAMED", + "owner": "dev.morphia.aggregation.expressions.ArrayExpressions", + "method": "map", + "parameters": [ + "java.lang.Object", + "java.lang.Object" + ], + "varargs": false, + "arguments": [ + "input", + "in" + ], + "options": { + "as": { + "method": "as", + "parameters": [ + "java.lang.String" + ] + } + }, + "fields": {} + }, + { + "operator": "$maxN", + "position": "EXPRESSION", + "form": "NAMED", + "owner": "dev.morphia.aggregation.expressions.AccumulatorExpressions", + "method": "maxN", + "parameters": [ + "java.lang.Object", + "java.lang.Object" + ], + "varargs": false, + "arguments": [ + "n", + "input" + ], + "options": {}, + "fields": {} + }, + { + "operator": "$minN", + "position": "EXPRESSION", + "form": "NAMED", + "owner": "dev.morphia.aggregation.expressions.AccumulatorExpressions", + "method": "minN", + "parameters": [ + "java.lang.Object", + "java.lang.Object" + ], + "varargs": false, + "arguments": [ + "n", + "input" + ], + "options": {}, + "fields": {} + }, { "operator": "$mod", "position": "EXPRESSION", @@ -223,6 +376,177 @@ "options": {}, "fields": {} }, + { + "operator": "$top", + "position": "EXPRESSION", + "form": "NAMED", + "owner": "dev.morphia.aggregation.expressions.AccumulatorExpressions", + "method": "top", + "parameters": [ + "java.lang.Object", + "dev.morphia.query.Sort[]" + ], + "varargs": true, + "arguments": [ + "output", + "sortBy" + ], + "options": {}, + "fields": {} + }, + { + "operator": "$topN", + "position": "EXPRESSION", + "form": "NAMED", + "owner": "dev.morphia.aggregation.expressions.AccumulatorExpressions", + "method": "topN", + "parameters": [ + "java.lang.Object", + "java.lang.Object", + "dev.morphia.query.Sort[]" + ], + "varargs": true, + "arguments": [ + "n", + "output", + "sortBy" + ], + "options": {}, + "fields": {} + }, + { + "operator": "[]", + "position": "EXPRESSION", + "form": "POSITIONAL", + "owner": "dev.morphia.aggregation.expressions.ArrayExpressions", + "method": "array", + "parameters": [ + "java.lang.Object[]" + ], + "varargs": true, + "arguments": [], + "options": {}, + "fields": {} + }, + { + "operator": "$eq", + "position": "FILTER", + "form": "FIELD", + "owner": "dev.morphia.query.filters.Filters", + "method": "eq", + "parameters": [ + "java.lang.String", + "java.lang.Object" + ], + "varargs": false, + "arguments": [], + "options": {}, + "fields": {} + }, + { + "operator": "$exists", + "position": "FILTER", + "form": "FIELD", + "owner": "dev.morphia.query.filters.Filters", + "method": "exists", + "parameters": [ + "java.lang.String" + ], + "varargs": false, + "arguments": [], + "options": {}, + "fields": {} + }, + { + "operator": "$gt", + "position": "FILTER", + "form": "FIELD", + "owner": "dev.morphia.query.filters.Filters", + "method": "gt", + "parameters": [ + "java.lang.String", + "java.lang.Object" + ], + "varargs": false, + "arguments": [], + "options": {}, + "fields": {} + }, + { + "operator": "$gte", + "position": "FILTER", + "form": "FIELD", + "owner": "dev.morphia.query.filters.Filters", + "method": "gte", + "parameters": [ + "java.lang.String", + "java.lang.Object" + ], + "varargs": false, + "arguments": [], + "options": {}, + "fields": {} + }, + { + "operator": "$in", + "position": "FILTER", + "form": "FIELD", + "owner": "dev.morphia.query.filters.Filters", + "method": "in", + "parameters": [ + "java.lang.String", + "java.lang.Iterable" + ], + "varargs": false, + "arguments": [], + "options": {}, + "fields": {} + }, + { + "operator": "$lt", + "position": "FILTER", + "form": "FIELD", + "owner": "dev.morphia.query.filters.Filters", + "method": "lt", + "parameters": [ + "java.lang.String", + "java.lang.Object" + ], + "varargs": false, + "arguments": [], + "options": {}, + "fields": {} + }, + { + "operator": "$lte", + "position": "FILTER", + "form": "FIELD", + "owner": "dev.morphia.query.filters.Filters", + "method": "lte", + "parameters": [ + "java.lang.String", + "java.lang.Object" + ], + "varargs": false, + "arguments": [], + "options": {}, + "fields": {} + }, + { + "operator": "$ne", + "position": "FILTER", + "form": "FIELD", + "owner": "dev.morphia.query.filters.Filters", + "method": "ne", + "parameters": [ + "java.lang.String", + "java.lang.Object" + ], + "varargs": false, + "arguments": [], + "options": {}, + "fields": {} + }, { "operator": "$addFields", "position": "STAGE", @@ -243,6 +567,48 @@ "arguments": [], "options": {} }, + { + "operator": "$group", + "position": "STAGE", + "form": "GROUP", + "owner": "dev.morphia.aggregation.stages.Group", + "method": "group", + "parameters": [ + "dev.morphia.aggregation.stages.Group.GroupId" + ], + "varargs": false, + "arguments": [], + "options": {}, + "fields": { + "id": { + "method": "id", + "parameters": [ + "java.lang.Object" + ] + }, + "value": { + "method": "field", + "parameters": [ + "java.lang.String", + "java.lang.Object" + ] + } + } + }, + { + "operator": "$match", + "position": "STAGE", + "form": "FILTERS", + "owner": "dev.morphia.aggregation.stages.Match", + "method": "match", + "parameters": [ + "dev.morphia.query.filters.Filter[]" + ], + "varargs": true, + "arguments": [], + "options": {}, + "fields": {} + }, { "operator": "$project", "position": "STAGE", @@ -298,6 +664,47 @@ "varargs": false, "arguments": [], "options": {} + }, + { + "operator": "$sort", + "position": "STAGE", + "form": "SORT", + "owner": "dev.morphia.aggregation.stages.Sort", + "method": "sort", + "parameters": [], + "varargs": false, + "arguments": [], + "options": {}, + "fields": { + "ascending": { + "method": "ascending", + "parameters": [ + "java.lang.String", + "java.lang.String[]" + ] + }, + "descending": { + "method": "descending", + "parameters": [ + "java.lang.String", + "java.lang.String[]" + ] + } + } + }, + { + "operator": "$unwind", + "position": "STAGE", + "form": "POSITIONAL", + "owner": "dev.morphia.aggregation.stages.Unwind", + "method": "unwind", + "parameters": [ + "java.lang.String" + ], + "varargs": false, + "arguments": [], + "options": {}, + "fields": {} } ] } diff --git a/audits/catalog/generation-review.json b/audits/catalog/generation-review.json index 0bea8c33ad1..66a99f92c55 100644 --- a/audits/catalog/generation-review.json +++ b/audits/catalog/generation-review.json @@ -16,5 +16,8 @@ "name": "aggregation/expressions/filter/useIdxToAccessTheIndex", "reason": "$$IDX is newer than the tests' MongoDB 8.2, which rejects it (Use of undefined variable: IDX); 8.3 cannot run on the test hosts' kernels (SERVER-121912)." } - ] + ], + "sampleDatasets": { + "movies": "sample_mflix" + } } diff --git a/audits/src/main/kotlin/dev/morphia/audits/generate/CaseGenerator.kt b/audits/src/main/kotlin/dev/morphia/audits/generate/CaseGenerator.kt index f68d5d49631..0f1ec576d0f 100644 --- a/audits/src/main/kotlin/dev/morphia/audits/generate/CaseGenerator.kt +++ b/audits/src/main/kotlin/dev/morphia/audits/generate/CaseGenerator.kt @@ -1,11 +1,14 @@ package dev.morphia.audits.generate import dev.morphia.audits.repairs.ActionShape +import dev.morphia.audits.repairs.BlockRole import dev.morphia.audits.repairs.FixtureMigration import dev.morphia.audits.repairs.FormMigration import dev.morphia.audits.repairs.FormOverride +import dev.morphia.audits.repairs.FormRule import dev.morphia.audits.repairs.GENERATED import dev.morphia.audits.repairs.ManifestCase +import org.bson.BsonBoolean import org.bson.BsonValue /** Why an example of a generated family has no generated case. */ @@ -41,12 +44,15 @@ data class Exclusion(val name: String, val reason: String) /** * The reviewed scope of generation: the families (legacy packages) whose unowned examples are - * generated, and the cases excluded from them, each with its reason. + * generated, and the cases excluded from them, each with its reason. [sampleDatasets] maps a + * collection of MongoDB's sample datasets to its dataset: an example that queries one without + * seeding data is generated with that dataset, and only its serialization is checked. */ data class GenerationReview( val schemaVersion: Int = 1, val families: List, val excluded: List = emptyList(), + val sampleDatasets: Map = emptyMap(), ) /** A generated case: its manifest entry, its scenario's text, and its test method's source. */ @@ -72,6 +78,10 @@ object CaseGenerator { private const val PACKAGE = "dev.morphia.test.generated" private const val OBJECT = "java.lang.Object" private const val STRING = "java.lang.String" + private const val ITERABLE = "java.lang.Iterable" + private const val SORTS = "dev.morphia.query.Sort[]" + /** The binding key of an array literal in an expression. */ + const val ARRAY = "[]" /** * [protected] holds the repository paths that generation must not write: moved handwritten @@ -91,6 +101,10 @@ object CaseGenerator { catalog.bindings .filter { it.position == BindingPosition.EXPRESSION } .associateBy { it.operator } + val filters = + catalog.bindings + .filter { it.position == BindingPosition.FILTER } + .associateBy { it.operator } val excluded = review.excluded.associate { it.name to it.reason } val cases = mutableListOf>() val gaps = mutableListOf() @@ -138,7 +152,7 @@ object CaseGenerator { "a ${documented.shape} action is not generated yet", ) } - val emitted = Emitter(stages, expressions) + val emitted = Emitter(stages, expressions, filters) val pipeline = try { documented.action.mapIndexed { index, stage -> @@ -147,6 +161,12 @@ object CaseGenerator { } catch (unbound: Unbound) { return@forEach gap(GapKind.UNBOUND, unbound.message!!) } + // An example that seeds nothing and queries a sample collection runs against + // that dataset, which the tests do not load. + val dataset = + review.sampleDatasets[documented.collection].takeIf { + example.blocks.none { it.role == BlockRole.DATA } + } val scenario = FixtureMigration.scenarioPath(name, GENERATED) val override = FormOverride( @@ -159,7 +179,7 @@ object CaseGenerator { example = example.title, shape = documented.shape, blocks = example.blocks, - rules = emptyList(), + rules = emitted.rules.sorted(), retiredLock = null, fixtureFiles = emptyMap(), ) @@ -179,7 +199,7 @@ object CaseGenerator { cases += GeneratedCase( ManifestCase(name, GENERATED, resource, "$PACKAGE.$folder.$type#$stem"), - FixtureMigration.scenario(override, ordered = true), + FixtureMigration.scenario(override, ordered = true, dataset = dataset), method, ) to emitted } @@ -274,11 +294,17 @@ object CaseGenerator { private class Emitter( val stages: Map, val expressions: Map, + val filters: Map, ) { /** Owner and method of every factory called. */ val calls = mutableSetOf>() /** Types named in the source, such as an enum argument's. */ val types = mutableSetOf() + /** + * The form rules the emitted spelling needs: Morphia writes an implicit equality as `$eq` + * and several operators on one field as one filter each. + */ + val rules = mutableSetOf() fun stage(value: BsonValue, path: String): String { val (operator, argument) = @@ -359,6 +385,57 @@ object CaseGenerator { ".$method(${literal(field)}, ${value(each, OBJECT, "$path/$field")})" } } + BindingForm.FILTERS -> { + if (!argument.isDocument) + throw Unbound("$path: ${binding.operator} takes a query document") + factory.format( + argument + .asDocument() + .entries + .flatMap { (field, predicate) -> + predicates(field, predicate, "$path/$field") + } + .joinToString(", ") + ) + } + BindingForm.FIELD -> + throw Unbound("$path: ${binding.operator} is a query operator, not a value") + BindingForm.GROUP -> { + if (!argument.isDocument || "_id" !in argument.asDocument()) + throw Unbound("$path: ${binding.operator} takes a document with an _id") + val id = binding.fields.getValue("id") + val group = argument.asDocument() + val key = group["_id"]!! + if (key.isDocument && operator(key, "$path/_id") == null) + throw Unbound("$path/_id: a compound _id has no binding") + calls += binding.owner to id.method + factory.format("${id.method}(${value(key, OBJECT, "$path/_id")})") + + group.entries + .filter { it.key != "_id" } + .joinToString("") { (field, each) -> + val method = binding.fields.getValue("value").method + ".$method(${literal(field)}, ${value(each, OBJECT, "$path/$field")})" + } + } + BindingForm.SORT -> { + if (!argument.isDocument) + throw Unbound("$path: ${binding.operator} takes a document") + factory.format("") + + argument.asDocument().entries.joinToString("") { (field, each) -> + val direction = + when { + each.isNumber && each.asNumber().doubleValue() == 1.0 -> + "ascending" + each.isNumber && each.asNumber().doubleValue() == -1.0 -> + "descending" + else -> + throw Unbound( + "$path/$field: a sort by $each has no binding" + ) + } + ".${binding.fields.getValue(direction).method}(${literal(field)})" + } + } BindingForm.PROJECTION -> { if (!argument.isDocument) throw Unbound("$path: ${binding.operator} takes a document") @@ -384,6 +461,41 @@ object CaseGenerator { } } + /** The filters of one field's predicate: one per operator, or `$eq` for a plain value. */ + private fun predicates(field: String, predicate: BsonValue, path: String): List { + if (field.startsWith("$")) throw Unbound("$path: query operator $field has no binding") + val operators = + predicate + .takeIf { it.isDocument } + ?.asDocument() + ?.takeIf { it.isNotEmpty() && it.keys.all { key -> key.startsWith("$") } } + if (operators == null) { + rules += FormRule.EQ_SHORTHAND + return listOf(filter("\$eq", field, predicate, path)) + } + if (operators.size > 1) rules += FormRule.FIELD_OPERATORS_AND + return operators.entries.map { (operator, value) -> + filter(operator, field, value, "$path/$operator") + } + } + + private fun filter( + operator: String, + field: String, + value: BsonValue, + path: String, + ): String { + val binding = + filters[operator] ?: throw Unbound("$path: query operator $operator has no binding") + calls += binding.owner to binding.method + if (binding.parameters.size == 1) { + if (value != BsonBoolean.TRUE) + throw Unbound("$path: $operator $value has no binding") + return "${binding.method}(${literal(field)})" + } + return "${binding.method}(${literal(field)}, ${value(value, binding.parameters[1], path)})" + } + /** * Whether a projection value is an inclusion (`1`, `true`) or an exclusion (`0`, `false`). */ @@ -406,6 +518,34 @@ object CaseGenerator { expressions[operator] ?: throw Unbound("$path: $operator has no binding") return call(binding, argument, "$path/$operator") } + if (value.isArray && type == ITERABLE) { + val items = value.asArray().values + if (items.any { it.isNull }) throw Unbound("$path: List.of cannot hold null") + types += "java.util.List" + return items + .mapIndexed { index, item -> value(item, OBJECT, "$path/$index") } + .joinToString(", ", "List.of(", ")") + } + if (value.isDocument && type == SORTS) { + // `{f: -1, g: 1}` as `Sort` varargs, in order. + return value.asDocument().entries.joinToString(", ") { (field, each) -> + val direction = + when { + each.isNumber && each.asNumber().doubleValue() == 1.0 -> "ascending" + each.isNumber && each.asNumber().doubleValue() == -1.0 -> "descending" + else -> throw Unbound("$path/$field: a sort by $each has no binding") + } + calls += SORTS.removeSuffix("[]") to direction + "$direction(${literal(field)})" + } + } + if (value.isArray && type == OBJECT) { + // An array argument, such as `$top`'s output of several fields, is an expression + // in Morphia; its binding is the catalog's `[]` entry. + val binding = + expressions[ARRAY] ?: throw Unbound("$path: an array literal has no binding") + return call(binding, value, "$path/$ARRAY") + } if (value.isDocument) throw Unbound("$path: a document literal has no binding") if (value.isArray) throw Unbound("$path: an array literal has no binding") return when (type) { diff --git a/audits/src/main/kotlin/dev/morphia/audits/generate/DslBindings.kt b/audits/src/main/kotlin/dev/morphia/audits/generate/DslBindings.kt index 45b42c79334..1b8909ecb7b 100644 --- a/audits/src/main/kotlin/dev/morphia/audits/generate/DslBindings.kt +++ b/audits/src/main/kotlin/dev/morphia/audits/generate/DslBindings.kt @@ -3,10 +3,13 @@ package dev.morphia.audits.generate import dev.morphia.audits.api.ApiInventory import dev.morphia.audits.api.DeclarationKind -/** Where an MQL operator appears: as a pipeline stage or inside an expression. */ +/** + * Where an MQL operator appears: as a pipeline stage, inside an expression, or in a query filter. + */ enum class BindingPosition { STAGE, EXPRESSION, + FILTER, } /** How an operator's BSON value becomes the factory's arguments. */ @@ -29,6 +32,26 @@ enum class BindingForm { PROJECTION, /** `{$addFields: {field: value, …}}`: no arguments, then the `value` call per field. */ FIELDS, + /** + * `{$match: {field: predicate, …}}`: one varargs parameter taking a filter per predicate. A + * field's `{$op: v, …}` is a [FIELD] filter per operator; any other value is `$eq`. + */ + FILTERS, + /** + * A query operator on a field, `{field: {$op: v}}`: the factory takes the field name and, when + * it has a second parameter, `v`. A one-parameter factory (`$exists`) takes only `true`. + */ + FIELD, + /** + * `{$group: {_id: v, field: value, …}}`: the factory takes the [DslBinding.fields] `id` call of + * `v` (a static factory of the stage's class), then the `value` call per field. + */ + GROUP, + /** + * `{$sort: {field: 1 | -1, …}}`: no arguments, then the `ascending` or `descending` call per + * field, in order. + */ + SORT, } /** A method called on a factory's result, by name and erased parameter types. */ @@ -57,6 +80,7 @@ data class DslBindingCatalog(val schemaVersion: Int = 1, val bindings: List + if (!binding.varargs || binding.parameters != listOf("$FILTER[]")) + problems += "$label: a filters stage takes only $FILTER varargs" + BindingForm.GROUP -> + if (binding.fields.keys != setOf("id", "value") || binding.parameters.size != 1) + problems += "$label: a group stage takes its id and binds [id, value]" + BindingForm.SORT -> + if ( + binding.fields.keys != setOf("ascending", "descending") || + binding.parameters.isNotEmpty() + ) + problems += + "$label: a sort stage takes no arguments and binds [ascending, descending]" + BindingForm.FIELD -> + if ( + binding.position != BindingPosition.FILTER || + binding.parameters.firstOrNull() != "java.lang.String" || + binding.parameters.size !in 1..2 + ) + problems += + "$label: a field filter takes the field name and at most a value" } val result = erase(factory.returnType ?: "") (binding.options + binding.fields).forEach { (key, call) -> diff --git a/audits/src/main/kotlin/dev/morphia/audits/repairs/FixtureMigration.kt b/audits/src/main/kotlin/dev/morphia/audits/repairs/FixtureMigration.kt index d43030b41de..fd37e987244 100644 --- a/audits/src/main/kotlin/dev/morphia/audits/repairs/FixtureMigration.kt +++ b/audits/src/main/kotlin/dev/morphia/audits/repairs/FixtureMigration.kt @@ -257,12 +257,15 @@ object FixtureMigration { /** * The scenario a runner executes for [override]: its documented data, action and results. * [ordered] is whether the legacy test compared results in order, and [options] are its other - * options, each one of [mappedOptions]. + * options, each one of [mappedOptions]. A [dataset] names the sample dataset the example + * queries instead of seeding its own data; the tests do not load one, so its results are not + * checked. */ fun scenario( override: FormOverride, ordered: Boolean, options: List = emptyList(), + dataset: String? = null, ): String { require(options.all { it.name in mappedOptions && it.name != "orderMatters" }) { "${override.fixture}: options ${options.map { it.name }} are not mapped" @@ -277,6 +280,12 @@ object FixtureMigration { skipped["results"] = BsonString("the legacy test skipped its data check (skipDataCheck)") } + if (dataset != null) { + skipped["results"] = + BsonString( + "the example queries the $dataset sample dataset, which the tests do not load" + ) + } val documented = pinned(override, FormMigration.documented(override)) val action = BsonDocument("kind", BsonString(kind(documented.shape))) @@ -318,7 +327,7 @@ object FixtureMigration { .append("path", BsonString(override.source.path)) .append("blob", BsonString(override.pageBlob)), ) - .append("dataset", BsonNull.VALUE) + .append("dataset", dataset?.let { BsonString(it) } ?: BsonNull.VALUE) .append("collections", collections) .append("indexes", BsonArray()) .append("action", action) diff --git a/audits/src/test/kotlin/dev/morphia/audits/offline/GeneratorTest.kt b/audits/src/test/kotlin/dev/morphia/audits/offline/GeneratorTest.kt index dc60b978eea..77523325990 100644 --- a/audits/src/test/kotlin/dev/morphia/audits/offline/GeneratorTest.kt +++ b/audits/src/test/kotlin/dev/morphia/audits/offline/GeneratorTest.kt @@ -23,6 +23,7 @@ import java.nio.file.Files import java.nio.file.Path import kotlin.io.path.createDirectories import kotlin.io.path.writeText +import org.bson.BsonDocument import org.junit.jupiter.api.Assertions.assertEquals import org.junit.jupiter.api.Assertions.assertThrows import org.junit.jupiter.api.Assertions.assertTrue @@ -305,6 +306,104 @@ class GeneratorTest { assertTrue(none.cases.isEmpty() && none.gaps.isEmpty()) } + /** + * Sample-dataset examples, generated with the committed bindings: query filters, a group with a + * ranked accumulator, and a sort. Each seeds nothing and queries `movies`. + */ + @Test + fun sampleDatasetExamplesCheckTheirSerialization() { + val root = directory.resolve("repository") + write( + root.resolve("audits/catalog/fixture-migration.json"), + AuditJson.write(FixtureMigrationLedger()), + ) + fun movies(pipeline: String) = block("db.movies.aggregate( [ $pipeline ] )") + page( + "top", + "group", + """ + |Examples + |-------- + | + |Top Rated by Year + |~~~~~~~~~~~~~~~~~ + | + |${movies("""{ ${'$'}match: { genres: "Comedy", year: { ${'$'}gte: 2010, ${'$'}lte: 2012 }, rated: { ${'$'}in: [ "G", "PG" ] }, "imdb.rating": { ${'$'}exists: true } } }, + | { ${'$'}group: { _id: "${'$'}year", best: { ${'$'}top: { output: [ "${'$'}title", "${'$'}imdb.rating" ], sortBy: { "imdb.rating": -1, title: 1 } } } } }, + | { ${'$'}sort: { _id: 1 } }""")} + |${block("[ { _id: 2010, best: [ 'A', 9 ] } ]")} + |Grouped by Two Fields + |~~~~~~~~~~~~~~~~~~~~~ + | + |${movies("""{ ${'$'}group: { _id: { y: "${'$'}year" }, best: { ${'$'}top: { output: "${'$'}title", sortBy: { year: 1 } } } } }""")} + |Without a Rating + |~~~~~~~~~~~~~~~~ + | + |${movies("""{ ${'$'}match: { "imdb.rating": { ${'$'}exists: false } } }""")} + |Typed Years + |~~~~~~~~~~~ + | + |${movies("""{ ${'$'}match: { year: { ${'$'}type: "int" } } }""")}""" + .trimMargin(), + ) + val inventory = + DocumentedExamples.capture( + root, + directory.resolve("pages"), + CurrentPages( + commit = commit, + pages = listOf(CurrentPage(FormSource(commit, "$folder/top.txt"))), + ), + ) + val repository = + generateSequence(Path.of("").toAbsolutePath()) { it.parent } + .first { Files.isDirectory(it.resolve("audits/catalog")) } + val committed = + AuditJson.dslBindings(Files.readString(repository.resolve(DslBindings.PATH))) + val generation = + CaseGenerator.generate( + inventory, + committed, + GenerationReview( + families = listOf("aggregation/expressions"), + sampleDatasets = mapOf("movies" to "sample_mflix"), + ), + emptySet(), + ) + val case = generation.cases.single().manifest + assertEquals("aggregation/expressions/top/topRatedByYear", case.name) + val source = + generation.files.getValue( + "core/src/test/java/dev/morphia/test/generated/expressions/TestTop.java" + ) + val pipeline = + "match(eq(\"genres\", \"Comedy\"), gte(\"year\", 2010), lte(\"year\", 2012), " + + "in(\"rated\", List.of(\"G\", \"PG\")), exists(\"imdb.rating\")),\n" + + " group(id(\"\$year\")).field(\"best\", top(array(\"\$title\", " + + "\"\$imdb.rating\"), descending(\"imdb.rating\"), ascending(\"title\"))),\n" + + " sort().ascending(\"_id\")" + assertTrue(pipeline in source, source) + assertTrue("import java.util.List;" in source, source) + val scenario = + BsonDocument.parse(generation.files.getValue("core/src/test/resources${case.scenario}")) + assertEquals("sample_mflix", scenario.getString("dataset").value) + assertTrue("sample_mflix" in scenario.getDocument("skipped").getString("results").value) + assertEquals( + listOf("EQ_SHORTHAND", "FIELD_OPERATORS_AND"), + scenario.getDocument("comparison").getArray("rules").map { it.asString().value }, + ) + assertEquals( + mapOf( + "Grouped by Two Fields" to "/pipeline/0/\$group/_id: a compound _id has no binding", + "Without a Rating" to + "/pipeline/0/\$match/imdb.rating/\$exists: \$exists BsonBoolean{value=false} has no binding", + "Typed Years" to + "/pipeline/0/\$match/year/\$type: query operator \$type has no binding", + ), + generation.gaps.associate { it.title to it.detail }, + ) + } + @Test fun bindingsAreCheckedAgainstTheCurrentSource() { val root = directory.resolve("api") diff --git a/core/src/test/java/dev/morphia/test/OperatorCaseRunner.java b/core/src/test/java/dev/morphia/test/OperatorCaseRunner.java index e80fd9db8d2..6db88e3b6da 100644 --- a/core/src/test/java/dev/morphia/test/OperatorCaseRunner.java +++ b/core/src/test/java/dev/morphia/test/OperatorCaseRunner.java @@ -54,7 +54,8 @@ * published comparison only, a * {@code requirements.minimumServer} skips the case on an older server, and a check the scenario lists under * {@code skipped}, with its reason, is not run. This runner supports aggregations with exact or printed expected results - * and no tolerances, datasets or indexes; a scenario that needs any of them fails rather than being checked loosely. + * and no tolerances or indexes, and a dataset only when the scenario skips its results; a scenario that needs any + * of them fails rather than being checked loosely. */ public class OperatorCaseRunner { // Canonical extended JSON, so a failure shows BSON types: relaxed JSON prints an Int64 like an Int32. @@ -294,7 +295,8 @@ private void run(OperatorCase operatorCase, String kind, Shape shape, private static void supported(OperatorCase operatorCase, BsonDocument scenario) { BsonDocument comparison = scenario.getDocument("comparison"); List unsupported = new ArrayList<>(); - if (!scenario.get("dataset").isNull()) { + // A sample dataset is not loaded, so a case that names one must skip its results. + if (!scenario.get("dataset").isNull() && !scenario.getDocument("skipped", new BsonDocument()).containsKey("results")) { unsupported.add("dataset"); } if (!scenario.getArray("indexes").isEmpty()) { diff --git a/core/src/test/java/dev/morphia/test/generated/expressions/TestBottom.java b/core/src/test/java/dev/morphia/test/generated/expressions/TestBottom.java new file mode 100644 index 00000000000..29740aaac8c --- /dev/null +++ b/core/src/test/java/dev/morphia/test/generated/expressions/TestBottom.java @@ -0,0 +1,48 @@ +// spotless:off +package dev.morphia.test.generated.expressions; + +import dev.morphia.test.OperatorCase; +import dev.morphia.test.OperatorCaseRunner; +import dev.morphia.test.TestBase; + +import org.junit.jupiter.api.DisplayName; +import org.junit.jupiter.api.Test; + +import static dev.morphia.aggregation.expressions.AccumulatorExpressions.bottom; +import static dev.morphia.aggregation.expressions.ArrayExpressions.array; +import static dev.morphia.aggregation.stages.Group.group; +import static dev.morphia.aggregation.stages.Group.id; +import static dev.morphia.aggregation.stages.Match.match; +import static dev.morphia.aggregation.stages.Sort.sort; +import static dev.morphia.query.Sort.descending; +import static dev.morphia.query.filters.Filters.eq; +import static dev.morphia.query.filters.Filters.exists; +import static dev.morphia.query.filters.Filters.gte; +import static dev.morphia.query.filters.Filters.lte; + +/** Generated by GenerateMainKt from audits/catalog/documented-examples.json; do not edit. */ +public class TestBottom extends TestBase { + private final OperatorCaseRunner runner = new OperatorCaseRunner(this); + + @Test + @DisplayName("Find the Bottom Rating Across Multiple Years") + public void findTheBottomRatingAcrossMultipleYears() { + runner.aggregate( + OperatorCase.of("/dev/morphia/test/generated/fixtures/expressions/bottom/findTheBottomRatingAcrossMultipleYears/scenario.json"), + (aggregation) -> aggregation.pipeline( + match(exists("imdb.rating"), gte("year", 2010), lte("year", 2012)), + group(id("$year")).field("lowestRatedMovie", bottom(array("$title", "$imdb.rating"), descending("imdb.rating"))), + sort().ascending("_id"))); + } + + @Test + @DisplayName("Find the Bottom Rating in a Genre") + public void findTheBottomRatingInAGenre() { + runner.aggregate( + OperatorCase.of("/dev/morphia/test/generated/fixtures/expressions/bottom/findTheBottomRatingInAGenre/scenario.json"), + (aggregation) -> aggregation.pipeline( + match(eq("genres", "Comedy")), + group(id("Comedy")).field("lowestRatedMovie", bottom(array("$title", "$imdb.rating"), descending("imdb.rating"))))); + } +} +// spotless:on diff --git a/core/src/test/java/dev/morphia/test/generated/expressions/TestBottomN.java b/core/src/test/java/dev/morphia/test/generated/expressions/TestBottomN.java new file mode 100644 index 00000000000..af1677a2ba2 --- /dev/null +++ b/core/src/test/java/dev/morphia/test/generated/expressions/TestBottomN.java @@ -0,0 +1,35 @@ +// spotless:off +package dev.morphia.test.generated.expressions; + +import dev.morphia.test.OperatorCase; +import dev.morphia.test.OperatorCaseRunner; +import dev.morphia.test.TestBase; + +import org.junit.jupiter.api.DisplayName; +import org.junit.jupiter.api.Test; + +import static dev.morphia.aggregation.expressions.AccumulatorExpressions.bottomN; +import static dev.morphia.aggregation.expressions.ArrayExpressions.array; +import static dev.morphia.aggregation.stages.Group.group; +import static dev.morphia.aggregation.stages.Group.id; +import static dev.morphia.aggregation.stages.Match.match; +import static dev.morphia.query.Sort.ascending; +import static dev.morphia.query.Sort.descending; +import static dev.morphia.query.filters.Filters.eq; +import static dev.morphia.query.filters.Filters.exists; + +/** Generated by GenerateMainKt from audits/catalog/documented-examples.json; do not edit. */ +public class TestBottomN extends TestBase { + private final OperatorCaseRunner runner = new OperatorCaseRunner(this); + + @Test + @DisplayName("Find the Three Lowest Rated Movies in a Single Genre") + public void findTheThreeLowestRatedMoviesInASingleGenre() { + runner.aggregate( + OperatorCase.of("/dev/morphia/test/generated/fixtures/expressions/bottomN/findTheThreeLowestRatedMoviesInASingleGenre/scenario.json"), + (aggregation) -> aggregation.pipeline( + match(eq("genres", "Short"), exists("imdb.rating")), + group(id("Short")).field("lowestRatedMovies", bottomN(3, array("$title", "$imdb.rating"), descending("imdb.rating"), ascending("title"))))); + } +} +// spotless:on diff --git a/core/src/test/java/dev/morphia/test/generated/expressions/TestFirstN.java b/core/src/test/java/dev/morphia/test/generated/expressions/TestFirstN.java new file mode 100644 index 00000000000..f6b1fc7c2f5 --- /dev/null +++ b/core/src/test/java/dev/morphia/test/generated/expressions/TestFirstN.java @@ -0,0 +1,34 @@ +// spotless:off +package dev.morphia.test.generated.expressions; + +import dev.morphia.test.OperatorCase; +import dev.morphia.test.OperatorCaseRunner; +import dev.morphia.test.TestBase; + +import org.junit.jupiter.api.DisplayName; +import org.junit.jupiter.api.Test; + +import static dev.morphia.aggregation.expressions.AccumulatorExpressions.firstN; +import static dev.morphia.aggregation.expressions.ArrayExpressions.array; +import static dev.morphia.aggregation.stages.Group.group; +import static dev.morphia.aggregation.stages.Group.id; +import static dev.morphia.aggregation.stages.Match.match; +import static dev.morphia.aggregation.stages.Sort.sort; +import static dev.morphia.query.filters.Filters.eq; + +/** Generated by GenerateMainKt from audits/catalog/documented-examples.json; do not edit. */ +public class TestFirstN extends TestBase { + private final OperatorCaseRunner runner = new OperatorCaseRunner(this); + + @Test + @DisplayName("Find the First Three Movies for a Single Genre") + public void findTheFirstThreeMoviesForASingleGenre() { + runner.aggregate( + OperatorCase.of("/dev/morphia/test/generated/fixtures/expressions/firstN/findTheFirstThreeMoviesForASingleGenre/scenario.json"), + (aggregation) -> aggregation.pipeline( + match(eq("genres", "Horror")), + sort().ascending("year"), + group(id("Horror")).field("firstThreeMovies", firstN(3, array("$title", "$year"))))); + } +} +// spotless:on diff --git a/core/src/test/java/dev/morphia/test/generated/expressions/TestMaxN.java b/core/src/test/java/dev/morphia/test/generated/expressions/TestMaxN.java new file mode 100644 index 00000000000..4738b75d972 --- /dev/null +++ b/core/src/test/java/dev/morphia/test/generated/expressions/TestMaxN.java @@ -0,0 +1,47 @@ +// spotless:off +package dev.morphia.test.generated.expressions; + +import java.util.List; + +import dev.morphia.test.OperatorCase; +import dev.morphia.test.OperatorCaseRunner; +import dev.morphia.test.TestBase; + +import org.junit.jupiter.api.DisplayName; +import org.junit.jupiter.api.Test; + +import static dev.morphia.aggregation.expressions.AccumulatorExpressions.maxN; +import static dev.morphia.aggregation.stages.Group.group; +import static dev.morphia.aggregation.stages.Group.id; +import static dev.morphia.aggregation.stages.Match.match; +import static dev.morphia.aggregation.stages.Sort.sort; +import static dev.morphia.query.filters.Filters.eq; +import static dev.morphia.query.filters.Filters.exists; +import static dev.morphia.query.filters.Filters.in; + +/** Generated by GenerateMainKt from audits/catalog/documented-examples.json; do not edit. */ +public class TestMaxN extends TestBase { + private final OperatorCaseRunner runner = new OperatorCaseRunner(this); + + @Test + @DisplayName("Find the Three Highest Rated Movies Across Multiple Years") + public void findTheThreeHighestRatedMoviesAcrossMultipleYears() { + runner.aggregate( + OperatorCase.of("/dev/morphia/test/generated/fixtures/expressions/maxN/findTheThreeHighestRatedMoviesAcrossMultipleYears/scenario.json"), + (aggregation) -> aggregation.pipeline( + match(in("year", List.of(1999, 2000, 2001)), exists("imdb.rating")), + group(id("$year")).field("topThreeRatings", maxN(3, "$imdb.rating")), + sort().ascending("_id"))); + } + + @Test + @DisplayName("Find the Three Highest Rated Movies for a Single Year") + public void findTheThreeHighestRatedMoviesForASingleYear() { + runner.aggregate( + OperatorCase.of("/dev/morphia/test/generated/fixtures/expressions/maxN/findTheThreeHighestRatedMoviesForASingleYear/scenario.json"), + (aggregation) -> aggregation.pipeline( + match(eq("year", 1999), exists("imdb.rating")), + group(id(1999)).field("topThreeRatings", maxN(3, "$imdb.rating")))); + } +} +// spotless:on diff --git a/core/src/test/java/dev/morphia/test/generated/expressions/TestMinN.java b/core/src/test/java/dev/morphia/test/generated/expressions/TestMinN.java new file mode 100644 index 00000000000..3ab8d457eb4 --- /dev/null +++ b/core/src/test/java/dev/morphia/test/generated/expressions/TestMinN.java @@ -0,0 +1,31 @@ +// spotless:off +package dev.morphia.test.generated.expressions; + +import dev.morphia.test.OperatorCase; +import dev.morphia.test.OperatorCaseRunner; +import dev.morphia.test.TestBase; + +import org.junit.jupiter.api.DisplayName; +import org.junit.jupiter.api.Test; + +import static dev.morphia.aggregation.expressions.AccumulatorExpressions.minN; +import static dev.morphia.aggregation.stages.Group.group; +import static dev.morphia.aggregation.stages.Group.id; +import static dev.morphia.aggregation.stages.Match.match; +import static dev.morphia.query.filters.Filters.eq; + +/** Generated by GenerateMainKt from audits/catalog/documented-examples.json; do not edit. */ +public class TestMinN extends TestBase { + private final OperatorCaseRunner runner = new OperatorCaseRunner(this); + + @Test + @DisplayName("Find the Minimum Three Ratings for a Single Genre") + public void findTheMinimumThreeRatingsForASingleGenre() { + runner.aggregate( + OperatorCase.of("/dev/morphia/test/generated/fixtures/expressions/minN/findTheMinimumThreeRatingsForASingleGenre/scenario.json"), + (aggregation) -> aggregation.pipeline( + match(eq("genres", "Horror")), + group(id("Horror")).field("minThreeRatings", minN(3, "$imdb.rating")))); + } +} +// spotless:on diff --git a/core/src/test/java/dev/morphia/test/generated/expressions/TestTop.java b/core/src/test/java/dev/morphia/test/generated/expressions/TestTop.java new file mode 100644 index 00000000000..b158a317492 --- /dev/null +++ b/core/src/test/java/dev/morphia/test/generated/expressions/TestTop.java @@ -0,0 +1,49 @@ +// spotless:off +package dev.morphia.test.generated.expressions; + +import java.util.List; + +import dev.morphia.test.OperatorCase; +import dev.morphia.test.OperatorCaseRunner; +import dev.morphia.test.TestBase; + +import org.junit.jupiter.api.DisplayName; +import org.junit.jupiter.api.Test; + +import static dev.morphia.aggregation.expressions.AccumulatorExpressions.top; +import static dev.morphia.aggregation.expressions.ArrayExpressions.array; +import static dev.morphia.aggregation.stages.Group.group; +import static dev.morphia.aggregation.stages.Group.id; +import static dev.morphia.aggregation.stages.Match.match; +import static dev.morphia.aggregation.stages.Sort.sort; +import static dev.morphia.query.Sort.descending; +import static dev.morphia.query.filters.Filters.eq; +import static dev.morphia.query.filters.Filters.gt; +import static dev.morphia.query.filters.Filters.in; + +/** Generated by GenerateMainKt from audits/catalog/documented-examples.json; do not edit. */ +public class TestTop extends TestBase { + private final OperatorCaseRunner runner = new OperatorCaseRunner(this); + + @Test + @DisplayName("Find the Top Rating Across Multiple Ratings") + public void findTheTopRatingAcrossMultipleRatings() { + runner.aggregate( + OperatorCase.of("/dev/morphia/test/generated/fixtures/expressions/top/findTheTopRatingAcrossMultipleRatings/scenario.json"), + (aggregation) -> aggregation.pipeline( + match(in("rated", List.of("G", "PG", "PG-13", "R")), gt("imdb.rating", 0)), + group(id("$rated")).field("highestRatedMovie", top(array("$title", "$imdb.rating"), descending("imdb.rating"))), + sort().ascending("_id"))); + } + + @Test + @DisplayName("Find the Top Rating in a Genre") + public void findTheTopRatingInAGenre() { + runner.aggregate( + OperatorCase.of("/dev/morphia/test/generated/fixtures/expressions/top/findTheTopRatingInAGenre/scenario.json"), + (aggregation) -> aggregation.pipeline( + match(eq("genres", "Comedy"), gt("imdb.rating", 0)), + group(id("Comedy")).field("highestRatedMovie", top(array("$title", "$imdb.rating"), descending("imdb.rating"))))); + } +} +// spotless:on diff --git a/core/src/test/java/dev/morphia/test/generated/expressions/TestTopN.java b/core/src/test/java/dev/morphia/test/generated/expressions/TestTopN.java new file mode 100644 index 00000000000..6cccdd2c7c3 --- /dev/null +++ b/core/src/test/java/dev/morphia/test/generated/expressions/TestTopN.java @@ -0,0 +1,35 @@ +// spotless:off +package dev.morphia.test.generated.expressions; + +import dev.morphia.test.OperatorCase; +import dev.morphia.test.OperatorCaseRunner; +import dev.morphia.test.TestBase; + +import org.junit.jupiter.api.DisplayName; +import org.junit.jupiter.api.Test; + +import static dev.morphia.aggregation.expressions.AccumulatorExpressions.topN; +import static dev.morphia.aggregation.expressions.ArrayExpressions.array; +import static dev.morphia.aggregation.stages.Group.group; +import static dev.morphia.aggregation.stages.Group.id; +import static dev.morphia.aggregation.stages.Match.match; +import static dev.morphia.query.Sort.ascending; +import static dev.morphia.query.Sort.descending; +import static dev.morphia.query.filters.Filters.eq; +import static dev.morphia.query.filters.Filters.gt; + +/** Generated by GenerateMainKt from audits/catalog/documented-examples.json; do not edit. */ +public class TestTopN extends TestBase { + private final OperatorCaseRunner runner = new OperatorCaseRunner(this); + + @Test + @DisplayName("Find the Three Highest-Rated Movies in a Single Genre") + public void findTheThreeHighestRatedMoviesInASingleGenre() { + runner.aggregate( + OperatorCase.of("/dev/morphia/test/generated/fixtures/expressions/topN/findTheThreeHighestRatedMoviesInASingleGenre/scenario.json"), + (aggregation) -> aggregation.pipeline( + match(eq("genres", "Short"), gt("imdb.rating", 0)), + group(id("Short")).field("topRatedMovies", topN(3, array("$title", "$imdb.rating"), descending("imdb.rating"), ascending("title"))))); + } +} +// spotless:on diff --git a/core/src/test/resources/dev/morphia/test/generated/fixtures/expressions/bottom/findTheBottomRatingAcrossMultipleYears/scenario.json b/core/src/test/resources/dev/morphia/test/generated/fixtures/expressions/bottom/findTheBottomRatingAcrossMultipleYears/scenario.json new file mode 100644 index 00000000000..4e317164ae7 --- /dev/null +++ b/core/src/test/resources/dev/morphia/test/generated/fixtures/expressions/bottom/findTheBottomRatingAcrossMultipleYears/scenario.json @@ -0,0 +1,163 @@ +{ + "schemaVersion": { + "$numberInt": "1" + }, + "name": "aggregation/expressions/bottom/findTheBottomRatingAcrossMultipleYears", + "title": "Find the Bottom Rating Across Multiple Years", + "context": "EXPRESSION", + "source": { + "repository": "mongodb/docs", + "commit": "e4b0c153a0f39829bb1c2e5195beee1e92a8eff7", + "path": "content/manual/manual/source/reference/operator/aggregation/bottom.txt", + "blob": "09c132aa13207d6184617e20e2867a2505304562" + }, + "dataset": "sample_mflix", + "collections": {}, + "indexes": [], + "action": { + "kind": "aggregate", + "collection": "movies", + "pipeline": [ + { + "$match": { + "imdb.rating": { + "$exists": true + }, + "year": { + "$gte": { + "$numberInt": "2010" + }, + "$lte": { + "$numberInt": "2012" + } + } + } + }, + { + "$group": { + "_id": "$year", + "lowestRatedMovie": { + "$bottom": { + "output": [ + "$title", + "$imdb.rating" + ], + "sortBy": { + "imdb.rating": { + "$numberInt": "-1" + } + } + } + } + } + }, + { + "$sort": { + "_id": { + "$numberInt": "1" + } + } + } + ] + }, + "expected": { + "printed": [ + { + "document": [ + { + "name": "_id", + "value": { + "whole": { + "$numberInt": "2010" + } + } + }, + { + "name": "lowestRatedMovie", + "value": { + "array": [ + { + "text": "Khan the Con" + }, + { + "exact": { + "$numberDouble": "2.5" + } + } + ] + } + } + ] + }, + { + "document": [ + { + "name": "_id", + "value": { + "whole": { + "$numberInt": "2011" + } + } + }, + { + "name": "lowestRatedMovie", + "value": { + "array": [ + { + "text": "Justin Bieber: Never Say Never" + }, + { + "exact": { + "$numberDouble": "1.6" + } + } + ] + } + } + ] + }, + { + "document": [ + { + "name": "_id", + "value": { + "whole": { + "$numberInt": "2012" + } + } + }, + { + "name": "lowestRatedMovie", + "value": { + "array": [ + { + "text": "USS Seaviper" + }, + { + "exact": { + "$numberDouble": "2.5" + } + } + ] + } + } + ] + } + ] + }, + "comparison": { + "order": "ORDERED", + "rules": [ + "FIELD_OPERATORS_AND" + ], + "ignore": [], + "tolerance": null + }, + "requirements": { + "minimumServer": null, + "topology": "STANDALONE" + }, + "skipped": { + "results": "the example queries the sample_mflix sample dataset, which the tests do not load" + } +} diff --git a/core/src/test/resources/dev/morphia/test/generated/fixtures/expressions/bottom/findTheBottomRatingInAGenre/scenario.json b/core/src/test/resources/dev/morphia/test/generated/fixtures/expressions/bottom/findTheBottomRatingInAGenre/scenario.json new file mode 100644 index 00000000000..c775dca26fe --- /dev/null +++ b/core/src/test/resources/dev/morphia/test/generated/fixtures/expressions/bottom/findTheBottomRatingInAGenre/scenario.json @@ -0,0 +1,90 @@ +{ + "schemaVersion": { + "$numberInt": "1" + }, + "name": "aggregation/expressions/bottom/findTheBottomRatingInAGenre", + "title": "Find the Bottom Rating in a Genre", + "context": "EXPRESSION", + "source": { + "repository": "mongodb/docs", + "commit": "e4b0c153a0f39829bb1c2e5195beee1e92a8eff7", + "path": "content/manual/manual/source/reference/operator/aggregation/bottom.txt", + "blob": "09c132aa13207d6184617e20e2867a2505304562" + }, + "dataset": "sample_mflix", + "collections": {}, + "indexes": [], + "action": { + "kind": "aggregate", + "collection": "movies", + "pipeline": [ + { + "$match": { + "genres": "Comedy" + } + }, + { + "$group": { + "_id": "Comedy", + "lowestRatedMovie": { + "$bottom": { + "output": [ + "$title", + "$imdb.rating" + ], + "sortBy": { + "imdb.rating": { + "$numberInt": "-1" + } + } + } + } + } + } + ] + }, + "expected": { + "printed": [ + { + "document": [ + { + "name": "_id", + "value": { + "text": "Comedy" + } + }, + { + "name": "lowestRatedMovie", + "value": { + "array": [ + { + "text": "Saving Christmas" + }, + { + "exact": { + "$numberDouble": "1.6" + } + } + ] + } + } + ] + } + ] + }, + "comparison": { + "order": "ORDERED", + "rules": [ + "EQ_SHORTHAND" + ], + "ignore": [], + "tolerance": null + }, + "requirements": { + "minimumServer": null, + "topology": "STANDALONE" + }, + "skipped": { + "results": "the example queries the sample_mflix sample dataset, which the tests do not load" + } +} diff --git a/core/src/test/resources/dev/morphia/test/generated/fixtures/expressions/bottomN/findTheThreeLowestRatedMoviesInASingleGenre/scenario.json b/core/src/test/resources/dev/morphia/test/generated/fixtures/expressions/bottomN/findTheThreeLowestRatedMoviesInASingleGenre/scenario.json new file mode 100644 index 00000000000..8e57b2c99dd --- /dev/null +++ b/core/src/test/resources/dev/morphia/test/generated/fixtures/expressions/bottomN/findTheThreeLowestRatedMoviesInASingleGenre/scenario.json @@ -0,0 +1,127 @@ +{ + "schemaVersion": { + "$numberInt": "1" + }, + "name": "aggregation/expressions/bottomN/findTheThreeLowestRatedMoviesInASingleGenre", + "title": "Find the Three Lowest Rated Movies in a Single Genre", + "context": "EXPRESSION", + "source": { + "repository": "mongodb/docs", + "commit": "e4b0c153a0f39829bb1c2e5195beee1e92a8eff7", + "path": "content/manual/manual/source/reference/operator/aggregation/bottomN.txt", + "blob": "e889d2a459bf25885175611a49408f65c55394f4" + }, + "dataset": "sample_mflix", + "collections": {}, + "indexes": [], + "action": { + "kind": "aggregate", + "collection": "movies", + "pipeline": [ + { + "$match": { + "genres": "Short", + "imdb.rating": { + "$exists": true + } + } + }, + { + "$group": { + "_id": "Short", + "lowestRatedMovies": { + "$bottomN": { + "output": [ + "$title", + "$imdb.rating" + ], + "sortBy": { + "imdb.rating": { + "$numberInt": "-1" + }, + "title": { + "$numberInt": "1" + } + }, + "n": { + "$numberInt": "3" + } + } + } + } + } + ] + }, + "expected": { + "printed": [ + { + "document": [ + { + "name": "_id", + "value": { + "text": "Short" + } + }, + { + "name": "lowestRatedMovies", + "value": { + "array": [ + { + "array": [ + { + "text": "Andrè and Wally B." + }, + { + "exact": { + "$numberDouble": "5.4" + } + } + ] + }, + { + "array": [ + { + "text": "The Education of Mohammad Hussein" + }, + { + "exact": { + "$numberDouble": "5.4" + } + } + ] + }, + { + "array": [ + { + "text": "Enigma" + }, + { + "exact": { + "$numberDouble": "5.3" + } + } + ] + } + ] + } + } + ] + } + ] + }, + "comparison": { + "order": "ORDERED", + "rules": [ + "EQ_SHORTHAND" + ], + "ignore": [], + "tolerance": null + }, + "requirements": { + "minimumServer": null, + "topology": "STANDALONE" + }, + "skipped": { + "results": "the example queries the sample_mflix sample dataset, which the tests do not load" + } +} diff --git a/core/src/test/resources/dev/morphia/test/generated/fixtures/expressions/firstN/findTheFirstThreeMoviesForASingleGenre/scenario.json b/core/src/test/resources/dev/morphia/test/generated/fixtures/expressions/firstN/findTheFirstThreeMoviesForASingleGenre/scenario.json new file mode 100644 index 00000000000..49e4a23ee68 --- /dev/null +++ b/core/src/test/resources/dev/morphia/test/generated/fixtures/expressions/firstN/findTheFirstThreeMoviesForASingleGenre/scenario.json @@ -0,0 +1,123 @@ +{ + "schemaVersion": { + "$numberInt": "1" + }, + "name": "aggregation/expressions/firstN/findTheFirstThreeMoviesForASingleGenre", + "title": "Find the First Three Movies for a Single Genre", + "context": "EXPRESSION", + "source": { + "repository": "mongodb/docs", + "commit": "e4b0c153a0f39829bb1c2e5195beee1e92a8eff7", + "path": "content/manual/manual/source/reference/operator/aggregation/firstN.txt", + "blob": "0bc605aac52ba143b2d5c2f4be44cb68254dcafe" + }, + "dataset": "sample_mflix", + "collections": {}, + "indexes": [], + "action": { + "kind": "aggregate", + "collection": "movies", + "pipeline": [ + { + "$match": { + "genres": "Horror" + } + }, + { + "$sort": { + "year": { + "$numberInt": "1" + } + } + }, + { + "$group": { + "_id": "Horror", + "firstThreeMovies": { + "$firstN": { + "input": [ + "$title", + "$year" + ], + "n": { + "$numberInt": "3" + } + } + } + } + } + ] + }, + "expected": { + "printed": [ + { + "document": [ + { + "name": "_id", + "value": { + "text": "Horror" + } + }, + { + "name": "firstThreeMovies", + "value": { + "array": [ + { + "array": [ + { + "text": "Dr. Jekyll and Mr. Hyde" + }, + { + "whole": { + "$numberInt": "1931" + } + } + ] + }, + { + "array": [ + { + "text": "Dracula" + }, + { + "whole": { + "$numberInt": "1931" + } + } + ] + }, + { + "array": [ + { + "text": "The Black Cat" + }, + { + "whole": { + "$numberInt": "1934" + } + } + ] + } + ] + } + } + ] + } + ] + }, + "comparison": { + "order": "ORDERED", + "rules": [ + "EQ_SHORTHAND" + ], + "ignore": [], + "tolerance": null + }, + "requirements": { + "minimumServer": null, + "topology": "STANDALONE" + }, + "skipped": { + "results": "the example queries the sample_mflix sample dataset, which the tests do not load" + } +} diff --git a/core/src/test/resources/dev/morphia/test/generated/fixtures/expressions/maxN/findTheThreeHighestRatedMoviesAcrossMultipleYears/scenario.json b/core/src/test/resources/dev/morphia/test/generated/fixtures/expressions/maxN/findTheThreeHighestRatedMoviesAcrossMultipleYears/scenario.json new file mode 100644 index 00000000000..26690df1c5f --- /dev/null +++ b/core/src/test/resources/dev/morphia/test/generated/fixtures/expressions/maxN/findTheThreeHighestRatedMoviesAcrossMultipleYears/scenario.json @@ -0,0 +1,182 @@ +{ + "schemaVersion": { + "$numberInt": "1" + }, + "name": "aggregation/expressions/maxN/findTheThreeHighestRatedMoviesAcrossMultipleYears", + "title": "Find the Three Highest Rated Movies Across Multiple Years", + "context": "EXPRESSION", + "source": { + "repository": "mongodb/docs", + "commit": "e4b0c153a0f39829bb1c2e5195beee1e92a8eff7", + "path": "content/manual/manual/source/reference/operator/aggregation/maxN.txt", + "blob": "cf1200c4cd68051729b66c1e31462cd0cf6d1b1a" + }, + "dataset": "sample_mflix", + "collections": {}, + "indexes": [], + "action": { + "kind": "aggregate", + "collection": "movies", + "pipeline": [ + { + "$match": { + "year": { + "$in": [ + { + "$numberInt": "1999" + }, + { + "$numberInt": "2000" + }, + { + "$numberInt": "2001" + } + ] + }, + "imdb.rating": { + "$exists": true + } + } + }, + { + "$group": { + "_id": "$year", + "topThreeRatings": { + "$maxN": { + "input": "$imdb.rating", + "n": { + "$numberInt": "3" + } + } + } + } + }, + { + "$sort": { + "_id": { + "$numberInt": "1" + } + } + } + ] + }, + "expected": { + "printed": [ + { + "document": [ + { + "name": "_id", + "value": { + "whole": { + "$numberInt": "1999" + } + } + }, + { + "name": "topThreeRatings", + "value": { + "array": [ + { + "exact": { + "$numberDouble": "8.9" + } + }, + { + "exact": { + "$numberDouble": "8.7" + } + }, + { + "exact": { + "$numberDouble": "8.7" + } + } + ] + } + } + ] + }, + { + "document": [ + { + "name": "_id", + "value": { + "whole": { + "$numberInt": "2000" + } + } + }, + { + "name": "topThreeRatings", + "value": { + "array": [ + { + "exact": { + "$numberDouble": "8.5" + } + }, + { + "exact": { + "$numberDouble": "8.5" + } + }, + { + "exact": { + "$numberDouble": "8.5" + } + } + ] + } + } + ] + }, + { + "document": [ + { + "name": "_id", + "value": { + "whole": { + "$numberInt": "2001" + } + } + }, + { + "name": "topThreeRatings", + "value": { + "array": [ + { + "exact": { + "$numberDouble": "9.6" + } + }, + { + "exact": { + "$numberDouble": "9.2" + } + }, + { + "exact": { + "$numberDouble": "8.8" + } + } + ] + } + } + ] + } + ] + }, + "comparison": { + "order": "ORDERED", + "rules": [], + "ignore": [], + "tolerance": null + }, + "requirements": { + "minimumServer": null, + "topology": "STANDALONE" + }, + "skipped": { + "results": "the example queries the sample_mflix sample dataset, which the tests do not load" + } +} diff --git a/core/src/test/resources/dev/morphia/test/generated/fixtures/expressions/maxN/findTheThreeHighestRatedMoviesForASingleYear/scenario.json b/core/src/test/resources/dev/morphia/test/generated/fixtures/expressions/maxN/findTheThreeHighestRatedMoviesForASingleYear/scenario.json new file mode 100644 index 00000000000..d3830b655c5 --- /dev/null +++ b/core/src/test/resources/dev/morphia/test/generated/fixtures/expressions/maxN/findTheThreeHighestRatedMoviesForASingleYear/scenario.json @@ -0,0 +1,101 @@ +{ + "schemaVersion": { + "$numberInt": "1" + }, + "name": "aggregation/expressions/maxN/findTheThreeHighestRatedMoviesForASingleYear", + "title": "Find the Three Highest Rated Movies for a Single Year", + "context": "EXPRESSION", + "source": { + "repository": "mongodb/docs", + "commit": "e4b0c153a0f39829bb1c2e5195beee1e92a8eff7", + "path": "content/manual/manual/source/reference/operator/aggregation/maxN.txt", + "blob": "cf1200c4cd68051729b66c1e31462cd0cf6d1b1a" + }, + "dataset": "sample_mflix", + "collections": {}, + "indexes": [], + "action": { + "kind": "aggregate", + "collection": "movies", + "pipeline": [ + { + "$match": { + "year": { + "$numberInt": "1999" + }, + "imdb.rating": { + "$exists": true + } + } + }, + { + "$group": { + "_id": { + "$numberInt": "1999" + }, + "topThreeRatings": { + "$maxN": { + "input": "$imdb.rating", + "n": { + "$numberInt": "3" + } + } + } + } + } + ] + }, + "expected": { + "printed": [ + { + "document": [ + { + "name": "_id", + "value": { + "whole": { + "$numberInt": "1999" + } + } + }, + { + "name": "topThreeRatings", + "value": { + "array": [ + { + "exact": { + "$numberDouble": "8.9" + } + }, + { + "exact": { + "$numberDouble": "8.7" + } + }, + { + "exact": { + "$numberDouble": "8.7" + } + } + ] + } + } + ] + } + ] + }, + "comparison": { + "order": "ORDERED", + "rules": [ + "EQ_SHORTHAND" + ], + "ignore": [], + "tolerance": null + }, + "requirements": { + "minimumServer": null, + "topology": "STANDALONE" + }, + "skipped": { + "results": "the example queries the sample_mflix sample dataset, which the tests do not load" + } +} diff --git a/core/src/test/resources/dev/morphia/test/generated/fixtures/expressions/minN/findTheMinimumThreeRatingsForASingleGenre/scenario.json b/core/src/test/resources/dev/morphia/test/generated/fixtures/expressions/minN/findTheMinimumThreeRatingsForASingleGenre/scenario.json new file mode 100644 index 00000000000..363be9620b1 --- /dev/null +++ b/core/src/test/resources/dev/morphia/test/generated/fixtures/expressions/minN/findTheMinimumThreeRatingsForASingleGenre/scenario.json @@ -0,0 +1,92 @@ +{ + "schemaVersion": { + "$numberInt": "1" + }, + "name": "aggregation/expressions/minN/findTheMinimumThreeRatingsForASingleGenre", + "title": "Find the Minimum Three Ratings for a Single Genre", + "context": "EXPRESSION", + "source": { + "repository": "mongodb/docs", + "commit": "e4b0c153a0f39829bb1c2e5195beee1e92a8eff7", + "path": "content/manual/manual/source/reference/operator/aggregation/minN.txt", + "blob": "8a1f595f514f95f04f57ea98c2fbca7cd639200d" + }, + "dataset": "sample_mflix", + "collections": {}, + "indexes": [], + "action": { + "kind": "aggregate", + "collection": "movies", + "pipeline": [ + { + "$match": { + "genres": "Horror" + } + }, + { + "$group": { + "_id": "Horror", + "minThreeRatings": { + "$minN": { + "input": "$imdb.rating", + "n": { + "$numberInt": "3" + } + } + } + } + } + ] + }, + "expected": { + "printed": [ + { + "document": [ + { + "name": "_id", + "value": { + "text": "Horror" + } + }, + { + "name": "minThreeRatings", + "value": { + "array": [ + { + "whole": { + "$numberInt": "2" + } + }, + { + "whole": { + "$numberInt": "2" + } + }, + { + "exact": { + "$numberDouble": "2.2" + } + } + ] + } + } + ] + } + ] + }, + "comparison": { + "order": "ORDERED", + "rules": [ + "EQ_SHORTHAND" + ], + "ignore": [], + "tolerance": null + }, + "requirements": { + "minimumServer": null, + "topology": "STANDALONE" + }, + "skipped": { + "results": "the example queries the sample_mflix sample dataset, which the tests do not load" + } +} diff --git a/core/src/test/resources/dev/morphia/test/generated/fixtures/expressions/top/findTheTopRatingAcrossMultipleRatings/scenario.json b/core/src/test/resources/dev/morphia/test/generated/fixtures/expressions/top/findTheTopRatingAcrossMultipleRatings/scenario.json new file mode 100644 index 00000000000..b1919680ad3 --- /dev/null +++ b/core/src/test/resources/dev/morphia/test/generated/fixtures/expressions/top/findTheTopRatingAcrossMultipleRatings/scenario.json @@ -0,0 +1,182 @@ +{ + "schemaVersion": { + "$numberInt": "1" + }, + "name": "aggregation/expressions/top/findTheTopRatingAcrossMultipleRatings", + "title": "Find the Top Rating Across Multiple Ratings", + "context": "EXPRESSION", + "source": { + "repository": "mongodb/docs", + "commit": "e4b0c153a0f39829bb1c2e5195beee1e92a8eff7", + "path": "content/manual/manual/source/reference/operator/aggregation/top.txt", + "blob": "a44a9ba7c0218bd34c9b72de45d12a4a9a7d800e" + }, + "dataset": "sample_mflix", + "collections": {}, + "indexes": [], + "action": { + "kind": "aggregate", + "collection": "movies", + "pipeline": [ + { + "$match": { + "rated": { + "$in": [ + "G", + "PG", + "PG-13", + "R" + ] + }, + "imdb.rating": { + "$gt": { + "$numberInt": "0" + } + } + } + }, + { + "$group": { + "_id": "$rated", + "highestRatedMovie": { + "$top": { + "output": [ + "$title", + "$imdb.rating" + ], + "sortBy": { + "imdb.rating": { + "$numberInt": "-1" + } + } + } + } + } + }, + { + "$sort": { + "_id": { + "$numberInt": "1" + } + } + } + ] + }, + "expected": { + "printed": [ + { + "document": [ + { + "name": "_id", + "value": { + "text": "G" + } + }, + { + "name": "highestRatedMovie", + "value": { + "array": [ + { + "text": "Modern Times" + }, + { + "exact": { + "$numberDouble": "8.6" + } + } + ] + } + } + ] + }, + { + "document": [ + { + "name": "_id", + "value": { + "text": "PG" + } + }, + { + "name": "highestRatedMovie", + "value": { + "array": [ + { + "text": "Life" + }, + { + "exact": { + "$numberDouble": "9.2" + } + } + ] + } + } + ] + }, + { + "document": [ + { + "name": "_id", + "value": { + "text": "PG-13" + } + }, + { + "name": "highestRatedMovie", + "value": { + "array": [ + { + "text": "A Brave Heart: The Lizzie Velasquez Story" + }, + { + "exact": { + "$numberDouble": "9.4" + } + } + ] + } + } + ] + }, + { + "document": [ + { + "name": "_id", + "value": { + "text": "R" + } + }, + { + "name": "highestRatedMovie", + "value": { + "array": [ + { + "text": "The Shawshank Redemption" + }, + { + "exact": { + "$numberDouble": "9.3" + } + } + ] + } + } + ] + } + ] + }, + "comparison": { + "order": "ORDERED", + "rules": [], + "ignore": [], + "tolerance": null + }, + "requirements": { + "minimumServer": null, + "topology": "STANDALONE" + }, + "skipped": { + "results": "the example queries the sample_mflix sample dataset, which the tests do not load" + } +} diff --git a/core/src/test/resources/dev/morphia/test/generated/fixtures/expressions/top/findTheTopRatingInAGenre/scenario.json b/core/src/test/resources/dev/morphia/test/generated/fixtures/expressions/top/findTheTopRatingInAGenre/scenario.json new file mode 100644 index 00000000000..741804ecbcc --- /dev/null +++ b/core/src/test/resources/dev/morphia/test/generated/fixtures/expressions/top/findTheTopRatingInAGenre/scenario.json @@ -0,0 +1,95 @@ +{ + "schemaVersion": { + "$numberInt": "1" + }, + "name": "aggregation/expressions/top/findTheTopRatingInAGenre", + "title": "Find the Top Rating in a Genre", + "context": "EXPRESSION", + "source": { + "repository": "mongodb/docs", + "commit": "e4b0c153a0f39829bb1c2e5195beee1e92a8eff7", + "path": "content/manual/manual/source/reference/operator/aggregation/top.txt", + "blob": "a44a9ba7c0218bd34c9b72de45d12a4a9a7d800e" + }, + "dataset": "sample_mflix", + "collections": {}, + "indexes": [], + "action": { + "kind": "aggregate", + "collection": "movies", + "pipeline": [ + { + "$match": { + "genres": "Comedy", + "imdb.rating": { + "$gt": { + "$numberInt": "0" + } + } + } + }, + { + "$group": { + "_id": "Comedy", + "highestRatedMovie": { + "$top": { + "output": [ + "$title", + "$imdb.rating" + ], + "sortBy": { + "imdb.rating": { + "$numberInt": "-1" + } + } + } + } + } + } + ] + }, + "expected": { + "printed": [ + { + "document": [ + { + "name": "_id", + "value": { + "text": "Comedy" + } + }, + { + "name": "highestRatedMovie", + "value": { + "array": [ + { + "text": "Over the Garden Wall" + }, + { + "exact": { + "$numberDouble": "9.2" + } + } + ] + } + } + ] + } + ] + }, + "comparison": { + "order": "ORDERED", + "rules": [ + "EQ_SHORTHAND" + ], + "ignore": [], + "tolerance": null + }, + "requirements": { + "minimumServer": null, + "topology": "STANDALONE" + }, + "skipped": { + "results": "the example queries the sample_mflix sample dataset, which the tests do not load" + } +} diff --git a/core/src/test/resources/dev/morphia/test/generated/fixtures/expressions/topN/findTheThreeHighestRatedMoviesInASingleGenre/scenario.json b/core/src/test/resources/dev/morphia/test/generated/fixtures/expressions/topN/findTheThreeHighestRatedMoviesInASingleGenre/scenario.json new file mode 100644 index 00000000000..d1e62571db6 --- /dev/null +++ b/core/src/test/resources/dev/morphia/test/generated/fixtures/expressions/topN/findTheThreeHighestRatedMoviesInASingleGenre/scenario.json @@ -0,0 +1,129 @@ +{ + "schemaVersion": { + "$numberInt": "1" + }, + "name": "aggregation/expressions/topN/findTheThreeHighestRatedMoviesInASingleGenre", + "title": "Find the Three Highest-Rated Movies in a Single Genre", + "context": "EXPRESSION", + "source": { + "repository": "mongodb/docs", + "commit": "e4b0c153a0f39829bb1c2e5195beee1e92a8eff7", + "path": "content/manual/manual/source/reference/operator/aggregation/topN.txt", + "blob": "68fd3a1a63bbfa2718f454f01671d272aa12d972" + }, + "dataset": "sample_mflix", + "collections": {}, + "indexes": [], + "action": { + "kind": "aggregate", + "collection": "movies", + "pipeline": [ + { + "$match": { + "genres": "Short", + "imdb.rating": { + "$gt": { + "$numberInt": "0" + } + } + } + }, + { + "$group": { + "_id": "Short", + "topRatedMovies": { + "$topN": { + "output": [ + "$title", + "$imdb.rating" + ], + "sortBy": { + "imdb.rating": { + "$numberInt": "-1" + }, + "title": { + "$numberInt": "1" + } + }, + "n": { + "$numberInt": "3" + } + } + } + } + } + ] + }, + "expected": { + "printed": [ + { + "document": [ + { + "name": "_id", + "value": { + "text": "Short" + } + }, + { + "name": "topRatedMovies", + "value": { + "array": [ + { + "array": [ + { + "text": "Rabbit and Deer" + }, + { + "exact": { + "$numberDouble": "8.7" + } + } + ] + }, + { + "array": [ + { + "text": "Assume the Position with Mr. Wuhl" + }, + { + "exact": { + "$numberDouble": "8.6" + } + } + ] + }, + { + "array": [ + { + "text": "Hole" + }, + { + "exact": { + "$numberDouble": "8.6" + } + } + ] + } + ] + } + } + ] + } + ] + }, + "comparison": { + "order": "ORDERED", + "rules": [ + "EQ_SHORTHAND" + ], + "ignore": [], + "tolerance": null + }, + "requirements": { + "minimumServer": null, + "topology": "STANDALONE" + }, + "skipped": { + "results": "the example queries the sample_mflix sample dataset, which the tests do not load" + } +} diff --git a/core/src/test/resources/dev/morphia/test/generated/manifest.json b/core/src/test/resources/dev/morphia/test/generated/manifest.json index 4b52e019aab..aab2e5e8942 100644 --- a/core/src/test/resources/dev/morphia/test/generated/manifest.json +++ b/core/src/test/resources/dev/morphia/test/generated/manifest.json @@ -129,6 +129,16 @@ "name" : "aggregation/expressions/bitXor/bitXorExpressionOperator", "scenario" : "/dev/morphia/test/aggregation/expressions/bitXor/bitXorExpressionOperator/scenario.json", "test" : "dev.morphia.test.aggregation.expressions.TestBitXor#testBitXorExpressionOperator" + }, { + "kind" : "GENERATED", + "name" : "aggregation/expressions/bottom/findTheBottomRatingAcrossMultipleYears", + "scenario" : "/dev/morphia/test/generated/fixtures/expressions/bottom/findTheBottomRatingAcrossMultipleYears/scenario.json", + "test" : "dev.morphia.test.generated.expressions.TestBottom#findTheBottomRatingAcrossMultipleYears" + }, { + "kind" : "GENERATED", + "name" : "aggregation/expressions/bottom/findTheBottomRatingInAGenre", + "scenario" : "/dev/morphia/test/generated/fixtures/expressions/bottom/findTheBottomRatingInAGenre/scenario.json", + "test" : "dev.morphia.test.generated.expressions.TestBottom#findTheBottomRatingInAGenre" }, { "kind" : "CONVERTED", "name" : "aggregation/expressions/bottom/findTheBottomScore", @@ -144,6 +154,11 @@ "name" : "aggregation/expressions/bottomN/computingNBasedOnTheGroupKeyForGroup", "scenario" : "/dev/morphia/test/aggregation/expressions/bottomN/computingNBasedOnTheGroupKeyForGroup/scenario.json", "test" : "dev.morphia.test.aggregation.expressions.TestBottomN#testComputingNBasedOnTheGroupKeyForGroup" + }, { + "kind" : "GENERATED", + "name" : "aggregation/expressions/bottomN/findTheThreeLowestRatedMoviesInASingleGenre", + "scenario" : "/dev/morphia/test/generated/fixtures/expressions/bottomN/findTheThreeLowestRatedMoviesInASingleGenre/scenario.json", + "test" : "dev.morphia.test.generated.expressions.TestBottomN#findTheThreeLowestRatedMoviesInASingleGenre" }, { "kind" : "CONVERTED", "name" : "aggregation/expressions/bottomN/findTheThreeLowestScores", @@ -354,6 +369,11 @@ "name" : "aggregation/expressions/firstN/computingNBasedOnTheGroupKeyForGroup", "scenario" : "/dev/morphia/test/aggregation/expressions/firstN/computingNBasedOnTheGroupKeyForGroup/scenario.json", "test" : "dev.morphia.test.aggregation.expressions.TestFirstN#testComputingNBasedOnTheGroupKeyForGroup" + }, { + "kind" : "GENERATED", + "name" : "aggregation/expressions/firstN/findTheFirstThreeMoviesForASingleGenre", + "scenario" : "/dev/morphia/test/generated/fixtures/expressions/firstN/findTheFirstThreeMoviesForASingleGenre/scenario.json", + "test" : "dev.morphia.test.generated.expressions.TestFirstN#findTheFirstThreeMoviesForASingleGenre" }, { "kind" : "CONVERTED", "name" : "aggregation/expressions/firstN/findTheFirstThreePlayerScoresForASingleGame", @@ -554,6 +574,16 @@ "name" : "aggregation/expressions/maxN/findTheMaximumThreeScoresForASingleGame", "scenario" : "/dev/morphia/test/aggregation/expressions/maxN/findTheMaximumThreeScoresForASingleGame/scenario.json", "test" : "dev.morphia.test.aggregation.expressions.TestMaxN#testFindTheMaximumThreeScoresForASingleGame" + }, { + "kind" : "GENERATED", + "name" : "aggregation/expressions/maxN/findTheThreeHighestRatedMoviesAcrossMultipleYears", + "scenario" : "/dev/morphia/test/generated/fixtures/expressions/maxN/findTheThreeHighestRatedMoviesAcrossMultipleYears/scenario.json", + "test" : "dev.morphia.test.generated.expressions.TestMaxN#findTheThreeHighestRatedMoviesAcrossMultipleYears" + }, { + "kind" : "GENERATED", + "name" : "aggregation/expressions/maxN/findTheThreeHighestRatedMoviesForASingleYear", + "scenario" : "/dev/morphia/test/generated/fixtures/expressions/maxN/findTheThreeHighestRatedMoviesForASingleYear/scenario.json", + "test" : "dev.morphia.test.generated.expressions.TestMaxN#findTheThreeHighestRatedMoviesForASingleYear" }, { "kind" : "CONVERTED", "name" : "aggregation/expressions/maxN/findingTheMaximumThreeScoresAcrossMultipleGames", @@ -604,6 +634,11 @@ "name" : "aggregation/expressions/minN/computingNBasedOnTheGroupKeyForGroup", "scenario" : "/dev/morphia/test/aggregation/expressions/minN/computingNBasedOnTheGroupKeyForGroup/scenario.json", "test" : "dev.morphia.test.aggregation.expressions.TestMinN#testComputingNBasedOnTheGroupKeyForGroup" + }, { + "kind" : "GENERATED", + "name" : "aggregation/expressions/minN/findTheMinimumThreeRatingsForASingleGenre", + "scenario" : "/dev/morphia/test/generated/fixtures/expressions/minN/findTheMinimumThreeRatingsForASingleGenre/scenario.json", + "test" : "dev.morphia.test.generated.expressions.TestMinN#findTheMinimumThreeRatingsForASingleGenre" }, { "kind" : "CONVERTED", "name" : "aggregation/expressions/minN/findTheMinimumThreeScoresForASingleGame", @@ -1034,6 +1069,16 @@ "name" : "aggregation/expressions/toUpper/toUpperExpressionOperator", "scenario" : "/dev/morphia/test/aggregation/expressions/toUpper/toUpperExpressionOperator/scenario.json", "test" : "dev.morphia.test.aggregation.expressions.TestToUpper#testToUpperExpressionOperator" + }, { + "kind" : "GENERATED", + "name" : "aggregation/expressions/top/findTheTopRatingAcrossMultipleRatings", + "scenario" : "/dev/morphia/test/generated/fixtures/expressions/top/findTheTopRatingAcrossMultipleRatings/scenario.json", + "test" : "dev.morphia.test.generated.expressions.TestTop#findTheTopRatingAcrossMultipleRatings" + }, { + "kind" : "GENERATED", + "name" : "aggregation/expressions/top/findTheTopRatingInAGenre", + "scenario" : "/dev/morphia/test/generated/fixtures/expressions/top/findTheTopRatingInAGenre/scenario.json", + "test" : "dev.morphia.test.generated.expressions.TestTop#findTheTopRatingInAGenre" }, { "kind" : "CONVERTED", "name" : "aggregation/expressions/top/findTheTopScore", @@ -1049,6 +1094,11 @@ "name" : "aggregation/expressions/topN/computingNBasedOnTheGroupKeyForGroup", "scenario" : "/dev/morphia/test/aggregation/expressions/topN/computingNBasedOnTheGroupKeyForGroup/scenario.json", "test" : "dev.morphia.test.aggregation.expressions.TestTopN#testComputingNBasedOnTheGroupKeyForGroup" + }, { + "kind" : "GENERATED", + "name" : "aggregation/expressions/topN/findTheThreeHighestRatedMoviesInASingleGenre", + "scenario" : "/dev/morphia/test/generated/fixtures/expressions/topN/findTheThreeHighestRatedMoviesInASingleGenre/scenario.json", + "test" : "dev.morphia.test.generated.expressions.TestTopN#findTheThreeHighestRatedMoviesInASingleGenre" }, { "kind" : "CONVERTED", "name" : "aggregation/expressions/topN/findTheThreeHighestScores", @@ -1824,10 +1874,38 @@ "owner" : "GENERATED", "path" : "src/test/java/dev/morphia/test/generated/expressions/TestAdd.java", "sha256" : "0a3bed7e8749f53389cb2e7934de336864e4e47766d612e4b2cddf5738aa91af" + }, { + "owner" : "GENERATED", + "path" : "src/test/java/dev/morphia/test/generated/expressions/TestBottom.java", + "sha256" : "b5494de085da1f077e1de4d7220e1a63531597b4d661e1689b2868be84ec66c6" + }, { + "owner" : "GENERATED", + "path" : "src/test/java/dev/morphia/test/generated/expressions/TestBottomN.java", + "sha256" : "4a2bd26d75fedd9d2362420193fcf77745c91e6c62c05aed370052dd099ee641" + }, { + "owner" : "GENERATED", + "path" : "src/test/java/dev/morphia/test/generated/expressions/TestFirstN.java", + "sha256" : "c95471f1b217c4881fbf8018009f52f4f50d63d21a241c99a6f42a8bebacb3f5" + }, { + "owner" : "GENERATED", + "path" : "src/test/java/dev/morphia/test/generated/expressions/TestMaxN.java", + "sha256" : "4f95b5f229f7fb00e340c3ded0f48ca1444335c71152a6f4a6a39c14c4acca8b" + }, { + "owner" : "GENERATED", + "path" : "src/test/java/dev/morphia/test/generated/expressions/TestMinN.java", + "sha256" : "bc0d5fc21f1a298c678e407a4aafaf07c778dd0259ca7e8ec150e7c004d8111d" }, { "owner" : "PROTECTED", "path" : "src/test/java/dev/morphia/test/generated/expressions/TestRound.java", "sha256" : "6abe26be2247d04fb1865980cfd2dc8e09978492cd20b3bc26d562c02f8b6798" + }, { + "owner" : "GENERATED", + "path" : "src/test/java/dev/morphia/test/generated/expressions/TestTop.java", + "sha256" : "9456ea99778a76a345f605776d296946fec36a7d67f25d152da69118be1f874f" + }, { + "owner" : "GENERATED", + "path" : "src/test/java/dev/morphia/test/generated/expressions/TestTopN.java", + "sha256" : "60d9727f2c4e2891bfed4f4689c7853e9248d56ab24b06ad3ab982ac17d92e9c" }, { "owner" : "GENERATED", "path" : "src/test/resources/dev/morphia/test/aggregation/expressions/abs/absExpressionOperator/scenario.json", @@ -2952,10 +3030,50 @@ "owner" : "GENERATED", "path" : "src/test/resources/dev/morphia/test/generated/fixtures/expressions/add/addNonIntegerValuesToADate/scenario.json", "sha256" : "a8a5d9b730661bb7a2b4e5f9b8be75a967708b4d55c62737784210fbfe16ec2a" + }, { + "owner" : "GENERATED", + "path" : "src/test/resources/dev/morphia/test/generated/fixtures/expressions/bottom/findTheBottomRatingAcrossMultipleYears/scenario.json", + "sha256" : "386a320bce697eb4944f465f8423cd9b447cdfd1180d6b6b625935e53b1a2e77" + }, { + "owner" : "GENERATED", + "path" : "src/test/resources/dev/morphia/test/generated/fixtures/expressions/bottom/findTheBottomRatingInAGenre/scenario.json", + "sha256" : "ca01406e371ac6d641ed62694c18090af9777d6b061a58ddd5850f7e6228f790" + }, { + "owner" : "GENERATED", + "path" : "src/test/resources/dev/morphia/test/generated/fixtures/expressions/bottomN/findTheThreeLowestRatedMoviesInASingleGenre/scenario.json", + "sha256" : "22053109001193c7bb877b43311df5ac88254c3c38b4b70a95c1299539932466" + }, { + "owner" : "GENERATED", + "path" : "src/test/resources/dev/morphia/test/generated/fixtures/expressions/firstN/findTheFirstThreeMoviesForASingleGenre/scenario.json", + "sha256" : "e6b04741d3a95332d0b6530eaba9197231cc7355c15a718a754a70252581ff02" + }, { + "owner" : "GENERATED", + "path" : "src/test/resources/dev/morphia/test/generated/fixtures/expressions/maxN/findTheThreeHighestRatedMoviesAcrossMultipleYears/scenario.json", + "sha256" : "58b899553d1f69903b4888716263c7e729356dda9fcb1e8937acd58f6346536f" + }, { + "owner" : "GENERATED", + "path" : "src/test/resources/dev/morphia/test/generated/fixtures/expressions/maxN/findTheThreeHighestRatedMoviesForASingleYear/scenario.json", + "sha256" : "2f9a52e4361e091ed0af097cb67085665606deb9afa35bbf05c4696c3ef257ca" + }, { + "owner" : "GENERATED", + "path" : "src/test/resources/dev/morphia/test/generated/fixtures/expressions/minN/findTheMinimumThreeRatingsForASingleGenre/scenario.json", + "sha256" : "39119f69699062f533d5e6facae77297af5757e7e0351fbb0f0e1152119c62f0" }, { "owner" : "GENERATED", "path" : "src/test/resources/dev/morphia/test/generated/fixtures/expressions/round/roundExpressionOperator/scenario.json", "sha256" : "250c3054a8e40ed14a0aaa36cafa2d7f8e5b324987937c61a7732e718848802d" + }, { + "owner" : "GENERATED", + "path" : "src/test/resources/dev/morphia/test/generated/fixtures/expressions/top/findTheTopRatingAcrossMultipleRatings/scenario.json", + "sha256" : "a68bef250e2fcc2f0a3898874873d0aef30d0bfd6a8a4c5b986190fc7ea795b3" + }, { + "owner" : "GENERATED", + "path" : "src/test/resources/dev/morphia/test/generated/fixtures/expressions/top/findTheTopRatingInAGenre/scenario.json", + "sha256" : "4ec04e434e2517e18ed05c11129fae06d55dee0c5f743a354fc40152ccd81e37" + }, { + "owner" : "GENERATED", + "path" : "src/test/resources/dev/morphia/test/generated/fixtures/expressions/topN/findTheThreeHighestRatedMoviesInASingleGenre/scenario.json", + "sha256" : "60aa1a5031c2b402052f2c1f619abe9d70b98b55a5ca499a6e2df6ee8a53eae5" }, { "owner" : "PROTECTED", "path" : "src/test/resources/dev/morphia/test/generated/fixtures/runner/crossDatabase/scenario.json", diff --git a/design/operator-audits-design.md b/design/operator-audits-design.md index bbb02bff81e..54c7a67c6ec 100644 --- a/design/operator-audits-design.md +++ b/design/operator-audits-design.md @@ -237,17 +237,30 @@ then show up as generation gaps. `GenerateMainKt candidate` turns each unowned example of the reviewed families into a scenario and a test method: -1. **Verify the bindings.** Each entry in `dsl-bindings.json` maps an MQL operator, as a stage or - an expression, to a Morphia factory by its exact erased signature, with the form its BSON takes - (`POSITIONAL`, `NAMED`, `PROJECTION` or `FIELDS`). The API inventory of core's current source - must contain every one; a stale binding stops generation. +1. **Verify the bindings.** Each entry in `dsl-bindings.json` maps an MQL operator, as a stage, an + expression or a query filter, to a Morphia factory by its exact erased signature, with the form + its BSON takes: + - `POSITIONAL` and `NAMED` for operators, `PROJECTION`, `FIELDS`, `GROUP` and `SORT` for those + stages, `FILTERS` for `$match`, and `FIELD` for a query operator on a field; + - the `[]` entry binds an array literal (`ArrayExpressions.array`). + + The API inventory of core's current source must contain every one; a stale binding stops + generation. 2. **Lower the source.** `FormMigration.documented` turns the example's mongosh blocks into typed seed data, an action and expected results, through `ShellPrograms`. 3. **Emit the call.** The emitter walks the pipeline. Every stage and operator node needs a binding, - and every value is emitted only in a form its parameter type accepts. The first node without a - binding makes the example a gap. + and every value is emitted only in a form its parameter type accepts: an array as `List.of` for + an `Iterable`, a sort document as `Sort` varargs. The first node without a binding makes the + example a gap. 4. **Write the scenario.** `FixtureMigration.scenario` writes it in the same format a converted - case uses, ordered, with no form rules. + case uses, ordered. Its form rules are those the emitted spelling needs: `EQ_SHORTHAND` when a + plain value became `eq()`, `FIELD_OPERATORS_AND` when one field's operators became one filter + each. + +An example that seeds no data and queries a collection of MongoDB's sample datasets, as most tested +snippets do, names that dataset (`generation-review.json`'s `sampleDatasets`). The tests do not load +sample datasets, so its scenario skips the results checks with that reason, and only its +serialization is checked: Morphia must still build exactly the documented pipeline. Examples that are not generated are listed in `gaps.json`, each with its reason: @@ -259,8 +272,9 @@ Examples that are not generated are listed in `gaps.json`, each with its reason: | `EXCLUDED` | A reviewed exclusion. | Its reason says what would lift it. | | `PROTECTED_CLASS` | The operator's class holds a moved handwritten body. | Move the body or the case. | -Only aggregation expressions are generated today. Stages, queries and updates need more bindings -and generator support for find and update actions. +Only the aggregation expressions family is generated today, its pipelines using the bound stages. +Stage pages, queries and updates need more bindings and generator support for find and update +actions. ### Candidates, integration and promotion diff --git a/design/operator-audits-progress.md b/design/operator-audits-progress.md index 3d8bc4afea4..aca0fc23cfd 100644 --- a/design/operator-audits-progress.md +++ b/design/operator-audits-progress.md @@ -18,7 +18,7 @@ how the audits work updates it too; this file records what each PR delivered. Every step of the plan (0–7) has been started. What stands: -- **On the runner:** 363 legacy cases (362 converted, 1 migrated), plus 1 generated case. +- **On the runner:** 363 legacy cases (362 converted, 1 migrated), plus 11 generated cases. Core gate: 662 tests under each mapper; audits: 452. - **Generation:** inventory of mongodb/docs `e4b0c153` (297 pages read, tested snippets included; 433 examples owned, 115 unowned, 30 unnamed, 4 ambiguous), reviewed DSL bindings checked against core's API, and the @@ -41,8 +41,9 @@ Waiting on reviews or decisions: Do not report them ourselves. Step 5, generation and cutover: -- **Bindings for the gaps** the weekly job files as issues (today `$match`, `$serializeEJSON`, - `$deserializeEJSON`, `$toObject`, `$reduce` `valueAs`). +- **Bindings for the remaining gaps** the weekly job files as issues (today `$serializeEJSON`, + `$deserializeEJSON`, `$toObject`, `$toArray`, `$hexHash`, `$percentile`, `$limit`, `$type`, a + compound `$group` `_id`, `$convert` options, `$reduce` `valueAs`). - **Find and update generation.** Only aggregation pipelines are generated. - **Reviewed names** for the 30 unnamed and 4 ambiguous examples. - **The remaining legacy fixtures:** 193 directories. @@ -2609,3 +2610,20 @@ no product-documentation changes. Legacy operator AsciiDoc tables are intentiona bindings). Many snippets query MongoDB's sample datasets and print elided results. - The new inventory is committed with the change, so the weekly job does not file every newly visible example as NEW_EXAMPLE. + +## Filters, groups and sample datasets (2026-11-23) + +- Branch audits-match-filters, with the core fix on audits-ranked-sortby (#4571). +- New binding forms: `FILTERS` (`$match`), `FIELD` (query operators on a field), `GROUP` and `SORT`, + plus a `FILTER` position. Bindings: `$match`, `$unwind`, `$group`, `$sort`; `$eq`, `$ne`, `$gt`, + `$gte`, `$lt`, `$lte`, `$in`, `$exists`; `$top`, `$bottom`, `$topN`, `$bottomN`, `$firstN`, + `$lastN`, `$maxN`, `$minN`, `$map`, `$convert`; and `[]` (array literals, as + `ArrayExpressions.array`). `Iterable` arguments are `List.of`, sort documents `Sort` varargs. +- Generated scenarios declare the rules their spelling needs (`EQ_SHORTHAND`, + `FIELD_OPERATORS_AND`). `generation-review.json`'s `sampleDatasets` (`movies` -> + `sample_mflix`) marks unseeded examples; their scenarios name the dataset and skip results, and + the runner accepts a dataset only with that skip. +- Integration found a Morphia bug: ranked accumulators wrote several sort keys as an array of + one-key documents. Fixed in #4571 (2.5 has the same code). +- 10 new generated cases (`$top`, `$bottom`, `$topN`, `$bottomN`, `$firstN`, `$maxN`, `$minN`), all + sample-dataset cases checking serialization. Core: 689 tests under each mapper; audits: 456. diff --git a/design/operator-audits-reference.md b/design/operator-audits-reference.md index 1386f8c5ae0..93dbced42bc 100644 --- a/design/operator-audits-reference.md +++ b/design/operator-audits-reference.md @@ -711,6 +711,11 @@ build core first), then generates the families that `audits/catalog/generation-r `promote` then take the candidate into the checkout. A case that fails integration is excluded in the review with its evidence, never generated looser. +Generated scenarios declare the form rules their emitted spelling needs (`EQ_SHORTHAND`, +`FIELD_OPERATORS_AND`). An example that seeds no data and queries a collection the review's +`sampleDatasets` maps names that dataset; its scenario skips the results checks with that reason, +and the runner accepts a dataset only alongside that skip. + ## Scheduled discovery `.github/workflows/operator-discovery.yml` runs weekly and on demand with read-only permissions.