Skip to content

test: assert which sub-aggregation groupings use missing aggregations - #1456

Merged
myronmarston merged 1 commit into
mainfrom
myron/assert-missing-aggregations
Nov 12, 2026
Merged

myronmarston merged 1 commit into
mainfrom
myron/assert-missing-aggregations

Conversation

@myronmarston

@myronmarston myronmarston commented Nov 10, 2026 •

Copy link
Copy Markdown
Collaborator

Why. A sub-aggregation nests one level per grouping field. A grouping without a missing value placeholder needs a separate missing aggregation at every level, so the number of aggregations grows exponentially and can exceed the max clause count (#882). Nothing asserted which groupings do that, so a regression in placeholder handling would return the same results and pass every spec. #1461 builds on these assertions.

  • missing_aggregation_field_paths_from_queries reads the recorded msearch requests and returns, for each search, the field paths that have a missing aggregation.
  • The sub-aggregation acceptance specs assert on it with both grouping adapters. The composite adapter never uses missing aggregations, because composite has its own missing_bucket option.
  • The Apollo entity ref sub-aggregation spec asserts on it too. On main, the entity ref grouping uses a missing aggregation on sponsor_id.
  • A new SeasonResult enum field on TeamSeason covers grouping on an enum in a sub-aggregation. No sub-aggregation in the test schema grouped on an enum before.

Verification. The specs pass on main, where only the Boolean and entity ref groupings use missing aggregations. In #1461, the entity ref assertion changes to expect no missing aggregation.

🤖 Generated with Claude Code

@myronmarston

myronmarston commented Nov 10, 2026 •

Copy link
Copy Markdown
Collaborator Author

@myronmarston myronmarston changed the title test: assert which sub-aggregation groupings use missing aggregations test: assert which sub-aggregation groupings use missing aggregations Nov 10, 2026
A grouping without a missing value placeholder needs a separate `missing` aggregation at every
sub-aggregation level, so the number of aggregations grows exponentially. These assertions record
which groupings do that today, so changes to placeholder handling show up in the specs.

- Add `missing_aggregation_field_paths_from_queries`, which reads the recorded msearch requests, and
  `expect_last_query_to_use_missing_aggregations_on`, which asserts on the last search.
- Add an `after` hook that fails any datastore test whose searches use `missing` aggregations,
  unless the test has the `:expect_missing_aggregations` tag.
- Assert on it in the sub-aggregation acceptance specs (term, date histogram, `as_day_of_week`,
  `as_time_of_day` and geo tile groupings), in the `DatastoreQuery` sub-aggregation integration
  spec, and in the Apollo entity ref sub-aggregation spec. On `main`, `Boolean`, entity ref, date
  histogram, script term and geo tile groupings use `missing` aggregations.
- Add a `SeasonResult` enum field to `TeamSeason` so the specs cover grouping on an enum in a
  sub-aggregation.

Generated with Claude Code
@myronmarston
myronmarston merged commit 34ad53d into main Nov 12, 2026
29 checks passed
@myronmarston
myronmarston deleted the myron/assert-missing-aggregations branch November 12, 2026 21:39
myronmarston added a commit that referenced this pull request Nov 12, 2026
… fields more efficient (#1461)

**Why.** Make sub-aggregation queries that group on leaf-backed object
fields (such as the Apollo entity refs from #1453) as efficient as other
scalar groupings. A grouping without a missing value placeholder needs a
separate `missing` aggregation at every level of a sub-aggregation, so
the number of aggregations grows exponentially and can exceed the max
clause count (#882).

This is an alternative to #1454, which fixes the same bug by recording a
type name on every leaf index field (about 640 lines per
`runtime_metadata.yaml`). This PR records the type name only on the
grouped-by fields of object-typed fields backed by a leaf index field: 6
lines in `artifacts_with_apollo` and 1 in `artifacts`. Stacked on #1456,
which adds the assertions on `missing` aggregations that this PR
updates.

**How.** The schema definition records the type of the backing leaf
index field. The GraphQL layer looks up that type and uses its existing
missing value placeholder, so placeholder resolution
(`$SECURE_RANDOM_VALUE`, enums) stays in `Schema::Type`.

- `GraphQLField` runtime metadata gets an optional
`object_grouping_leaf_type_name`.
- `Field#define_grouped_by_field` sets it when the original field has an
object type and the grouped-by field's `name_in_index` resolves, from
the original field's parent type, to a leaf index field.
- The path lookup from `backing_indexing_field` moves to
`HasIndices#indexing_field_at`, so the grouped-by code can resolve the
grouped-by field's `name_in_index` from the original field's parent
type. `f.backing_indexing_field` can't be used: it resolves from the
derived `GroupedBy` type, which has no indexing fields.
- `Schema::Field#object_grouping_leaf_type` looks up the type (nil when
unset), and the query adapter uses that type's placeholder for the
grouping on a leaf-backed field.

**Verification.** The Apollo entity ref test from #1456 no longer uses a
`missing` aggregation. The leaf-backed query adapter tests, including a
new `Boolean` case with no placeholder, fail without the fix.

🤖 Generated with [Claude Code](https://claude.com/claude-code)
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.

2 participants