Repository navigation
Conversation
…de its own reference cycle TypeMapper.mapInstantiatedGeneric read the type parameters of the generic shape, which are collected as its fields are added. Instantiated while it is still being visited (Hit -> inner_hits -> HitsMetadata -> Hit<TDocument>), the shape has none yet and getTypeParameters() is null. Whether that happens depends on the order the cycle is entered in; spec opensearch-project#1113 changes it and breaks the scheduled code generation. The parameters are now read from the generic schema in that case. The code generated from the vendored spec is unchanged. Signed-off-by: yyfamazon <yyf@amazon.com> (cherry picked from commit 28175b8)
The terms aggregates were generated as TermsAggregateBase<JsonData> since the October regeneration (opensearch-project#1957): the specification narrows the generic Buckets union to a plain array for terms (opensearch-api-specification opensearch-project#1063), and TypeMapper.mapInstantiatedGeneric only bound a type parameter when the generic schema and the instantiation had the same shape, so TBucket was never bound and fell back to JsonData. - TypeMapper: bind the parameter from the union branch whose container kind matches the instantiation (items <-> items, additionalProperties <-> additionalProperties). - GenericLabelingVisitor: only treat a subclass as an instantiation when the extended schema's own chain declares a type parameter; isGeneric also propagates through plain references, which mislabeled TermsBucketBase and produced TermsAggregateBase<TermsBucketBase<>> for UnsignedLongTermsAggregate. - Regenerate: the five terms aggregates get their bucket type back and the bucket classes are generated again, now with doc_count_error_upper_bound. - Return AbstractRequestIT, AbstractSearchTemplateRequestIT and TypedKeysTest to typed bucket access. Closes opensearch-project#2302 Signed-off-by: Minseok Choi <minseok184@gmail.com>
minseoky
requested review from
Bukhtawar,
VachaShah,
Xtansia,
madhusudhankonda,
reta,
saratvemulapalli and
szczepanczykd
as code owners
November 23, 2026 02:59
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.
Description
Fixes the code generator so that the
termsaggregates are generated with their bucket type again (TermsAggregateBase<StringTermsBucket>instead ofTermsAggregateBase<JsonData>), and regenerates the client. Details and history are in #2302.Changes to
java-codegen, and whyTypeMapper.mapInstantiatedGeneric: the generic schema declaresbucketsas a union (Buckets<TBucket>=oneOf: [keyed map of TBucket, array of TBucket]), while thetermsinstantiations declare only one branch of it (buckets: array of StringTermsBucket, as the specification does since Fix Terms aggregation response spec accuracy issues opensearch-api-specification#1063). The zipped walk of generic and instantiation never pairsTBucketwithStringTermsBucket, so the type parameter silently fell back toJsonData. The change binds the parameter from the union branch whose container kind matches the instantiation (items↔items,additionalProperties↔additionalProperties). Instantiations that keep the full union shape are untouched (right.hasOneOf()returns early), which is why no other generated file changes.GenericLabelingVisitor.isInstantiatedGeneric:isGenericpropagates through plain references (MultiBucketBase.additionalProperties: Aggregate → TopHitsAggregate.hits → HitsMetadata<TDocument>), soTermsBucketBaseis labeled generic although it declares no type parameter. Once the buckets were typed again, that madeUnsignedLongTermsAggregatecome out asTermsAggregateBase<TermsBucketBase<>>. The added guard only treats a subclass as an instantiation when the extended schema's own chain declares a type parameter.I would appreciate a check on whether this is an acceptable way to handle the narrowed-union case in
TypeMapper. The broader alternative is to make the generic labeling order-independent, as discussed in #2298; this change is deliberately narrower so that it can land without that.Dependency
The first commit is #2298's NPE fix (28175b8), cherry-picked unchanged with its author: the new binding instantiates
StringTermsBucketinside the aggregation reference cycle and hits exactly thatNullPointerExceptionwithout it. If #2298 lands first I will rebase and drop it; if this lands first, #2298 can drop that commit.Generated code
StringTermsAggregate,LongTermsAggregate,DoubleTermsAggregate,UnsignedLongTermsAggregateget their bucket type back;UnmappedTermsAggregateisTermsAggregateBase<Void>again, as on3.x.StringTermsBucket,LongTermsBucket,LongTermsBucketKey,DoubleTermsBucket,TermsBucketBase,UnsignedLongTermsBucketare generated again.TermsBucketBasenow includesdoc_count_error_upper_bound(Terms aggregation on raw field returns Exception jakarta.json.stream.JsonParsingException: Property name 'doc_count_error_upper_bound' is not in the 'type#name' format. Make sure the request has 'typed_keys' set #613, [BUG] Error parsing search response aggregation, property name 'doc_count_error_upper_bound' is not in the 'type#name' format. Make sure the request has 'typed_keys' set. #1737).StringTermsAggregate,LongTermsAggregateandUnmappedTermsAggregateare byte-identical to their3.xversions.Tests and samples
AbstractRequestIT,AbstractSearchTemplateRequestIT,TypedKeysTestandsamples/Search.javareturn to typed bucket access; they had been adjusted toJsonDatabuckets in #1957.Verification
./gradlew :java-codegen:run— only the 11 terms-related files change, andup_to_datereproduces the committed output./gradlew clean build -x test,spotlessJavaCheck,:java-codegen:test— pass./gradlew unitTest— 663 tests, 0 failures./gradlew clean integrationTest— 39 suites, 243 tests, 0 failures (OpenSearch via Testcontainers)Issues Resolved
Closes #2302. Also resolves #613 and #1737 (
doc_count_error_upper_boundonTermsBucketBase).By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.
For more information on following Developer Certificate of Origin and signing off your commits, please check here.