Skip to content

API: Add indexStatsNames to create field names for content stats#17010

Open
rdblue wants to merge 1 commit into
apache:mainfrom
rdblue:add-index-stats-names
Open

API: Add indexStatsNames to create field names for content stats#17010
rdblue wants to merge 1 commit into
apache:mainfrom
rdblue:add-index-stats-names

Conversation

@rdblue

@rdblue rdblue commented Jun 30, 2026

Copy link
Copy Markdown
Contributor

This introduces a new TypeUtil method to index fields in a type that produces names that can be used for stats fields in content stats. These names prefer short names, like locations.lat instead of locations.element.lat and uses underscores instead of . to join names into a single string.

This is exposed through TypeUtil to avoid making more of IndexByName public.

@github-actions github-actions Bot added the API label Jun 30, 2026

@wombatu-kun wombatu-kun left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Heads up: the red core-tests on this PR is a real regression from this change, not a flaky test. Root cause and a suggested fix inline on byId().

Comment on lines +89 to +93
if (useShortNames) {
shortNameToId.forEach((key, value) -> builder.put(value, key));
}

return builder.buildKeepingLast();

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Switching byId() from build() to buildKeepingLast() also changes the two existing callers of byId(), TypeUtil.indexNameById and indexQuotedNameById. Schema's constructor relies on indexNameById to reject duplicate field IDs: it calls lazyIdToName() -> indexNameById() -> byId(), and the ImmutableMap keyed by field ID used to throw on a duplicate key. With buildKeepingLast() a schema with two fields sharing an ID is now silently accepted, which is why TestNameMapping.testFailsDuplicateId fails on both JDK 17 and 21 ("Expecting code to raise a throwable").

The short-name-overrides-full-name behavior is only needed for the new indexStatsNames path, so gating buildKeepingLast() behind useShortNames keeps the existing validation intact:

Suggested change
if (useShortNames) {
shortNameToId.forEach((key, value) -> builder.put(value, key));
}
return builder.buildKeepingLast();
if (useShortNames) {
// short names intentionally override the full name for the same field ID
shortNameToId.forEach((key, value) -> builder.put(value, key));
return builder.buildKeepingLast();
}
return builder.build();

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants