Skip to content

Core: Adjust calculations for reserved field IDs#16441

Open
nastra wants to merge 1 commit into
apache:mainfrom
nastra:content-stats-calculations
Open

Core: Adjust calculations for reserved field IDs#16441
nastra wants to merge 1 commit into
apache:mainfrom
nastra:content-stats-calculations

Conversation

@nastra
Copy link
Copy Markdown
Contributor

@nastra nastra commented May 20, 2026

This adjusts the calculations around stats field IDs for data and metadata columns and also updates the code to only support stats for the stats ID range [10_000, 200_000_000).

The PR was created with the help of Claude Opus 4.7 and manually adjusted in a few places.

@github-actions github-actions Bot added the core label May 20, 2026
@nastra nastra marked this pull request as draft May 20, 2026 10:39
@nastra nastra force-pushed the content-stats-calculations branch 2 times, most recently from adeecba to 563110b Compare May 20, 2026 11:01
long statsFieldId =
STATS_SPACE_FIELD_ID_START_FOR_METADATA_FIELDS
+ (NUM_SUPPORTED_STATS_PER_COLUMN * (long) offset);
if (statsFieldId < 0 || statsFieldId > RESERVED_FIELD_IDS_START) {
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

we don't need to check for the overflow anymore, because that's already guaranteed that we only ever do this calculation for the field IDs in SUPPORTED_METADATA_FIELD_IDS

}

private static int fieldIdForStatsFieldFromReservedField(int statsFieldId) {
return Math.max(
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

this isn't needed anymore, because the caller already guarantees that 9000 <= statsFieldId < 1000, so this can never be negative

@nastra nastra force-pushed the content-stats-calculations branch from 563110b to 60e24fe Compare May 20, 2026 11:14
@nastra nastra marked this pull request as ready for review May 20, 2026 11:14
// the starting field ID of the reserved field ID space
static final int RESERVED_FIELD_IDS_START = Integer.MAX_VALUE - NUM_RESERVED_FIELD_IDS;
// the number of supported stats per table column
private static final int FIRST_SUPPORTED_METADATA_FIELD_ID =
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.

To avoid future code drift, consider moving SUPPORTED_METADATA_FIELD_IDS ahead, and then FIRST_SUPPORTED_METADATA_FIELD_ID would just be Collections.min(SUPPORTED_METADATA_FIELD_IDS)

private static final int FIRST_SUPPORTED_METADATA_FIELD_ID =
MetadataColumns.LAST_UPDATED_SEQUENCE_NUMBER.fieldId();
static final Set<Integer> SUPPORTED_METADATA_FIELD_IDS =
Sets.newHashSet(
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.

Use ImmutableSet.of(..)?

}

@Test
public void statsIdsForReservedColumns() {
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.

The name is a bit stale?

MetadataColumns.LAST_UPDATED_SEQUENCE_NUMBER.fieldId(), MetadataColumns.ROW_ID.fieldId());
static final int NUM_SUPPORTED_STATS_PER_COLUMN = 200;
// the starting field ID of the stats space for data field IDs
static final int STATS_SPACE_FIELD_ID_START_FOR_METADATA_FIELDS = 9_000;
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.

Should we do a Precondition check in a static initializer block to make sure SUPPORTED_METADATA_FIELD_IDS in future don't exceed 5 (the number of slots available between 9K and 10K)?

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