Key aggregated value aggregations off the GraphQL alias - #1331
Open
myronmarston wants to merge 1 commit into
Open
Key aggregated value aggregations off the GraphQL alias#1331myronmarston wants to merge 1 commit into
myronmarston wants to merge 1 commit into
Conversation
myronmarston
marked this pull request as ready for review
August 5, 2026 06:31
myronmarston
requested review from
BrianSigafoos-SQ,
bsorbo,
ellisandrews-toast,
jwils,
jwondrusch,
marcdaniels-toast and
rossroberts-toast
as code owners
August 5, 2026 06:31
This was referenced Aug 5, 2026
computed_index_field_name only used name_in_index for the aggregated value function's leaf, while every parent path segment already used alias-aware name_in_graphql_query. That's what forced an argument- bearing function (upcoming approximatePercentile) to invent a synthetic leaf name built independently on the query-building and resolver sides, which then had to agree byte-for-byte. Computation now carries a `leaf` PathSegment built via the same PathSegment.for factory on both sides, so the leaf key derives from the alias like every other segment. This removes the need for synthetic key naming for argument-bearing functions entirely. Behavior change (not a pure refactor): two aliases of the same function under one field used to collapse into a single computation (equal value objects, same key). Now their leaf segments differ, so two identical datastore aggregations are sent -- correct since each field resolves via its own alias. Deduping by clause content would require threading an alias-to-canonical-key map from query building into the resolver, reintroducing the coupling this change removes. Prep refactor #1 of 2 for PR #1327; the percentile function itself is not added here.
myronmarston
force-pushed
the
myron/key-aggregated-values-off-alias
branch
from
August 5, 2026 17:21
c506716 to
ed95d90
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Prep refactor #1 of 2 for PR #1327 (
approximatePercentile). The percentile function itself is not added here.An aggregated value function field that is aliased in a GraphQL query now resolves through a datastore aggregation key derived from that alias, rather than from the field's
name_in_index.Previously, the leaf segment of an aggregated value key was the only path segment keyed off
name_in_index-- every parent segment already used the alias-awarename_in_graphql_query. That inconsistency would have forced an argument-bearing function (like the upcomingapproximatePercentile) to invent a synthetic leaf name (e.g.approximate_percentile(50.0)), built independently in the query-building code and the resolver, which would then have to agree byte-for-byte. Making the leaf alias-derived removes the need for synthetic key naming entirely.Computationreplaces itscomputed_index_field_namestring attribute with aleafattribute holding aPathSegment. Itsname_in_indexis intentionally unused (the function name isn't part of the datastore index path); this is documented on the attribute.QueryAdapter) and the resolver side (Resolvers::AggregatedValues) now derive the leaf name through the samePathSegment.forfactory, so there's one rule instead of two implementations that must agree.computed_index_field_nameis deleted (not left unused), since the datastore clause already derives its index path fromsource_field_path.Behavior change
This is not a pure refactor. Two aliases of the same function under one field used to collapse into a single computation (the value objects were equal, held in a
Set, with an identical key). After this change their leaf segments differ, so two identical datastore aggregations are sent:Correct in both cases -- each field resolves via its own alias. Accepted deliberately:
Test plan
script/type_checkpassesscript/run_gem_specs elasticgraph-graphqlpasses (100% line/branch coverage maintained)script/quick_buildpassesCloses #1329
🤖 Generated with Claude Code