Skip to content

Test PerFieldMapperCodec with and without synthetic ID randomly#143027

Merged
burqen merged 5 commits intoelastic:mainfrom
burqen:ap/2026.02.24.synthetic-id-fix-PerFieldMapperCodecTests
Feb 26, 2026
Merged

Test PerFieldMapperCodec with and without synthetic ID randomly#143027
burqen merged 5 commits intoelastic:mainfrom
burqen:ap/2026.02.24.synthetic-id-fix-PerFieldMapperCodecTests

Conversation

@burqen
Copy link
Copy Markdown
Contributor

@burqen burqen commented Feb 25, 2026

Using synthetic_id based on feature_flag, index mode (time_series) and random boolean.
Update assertions of expected format instances to fit.

- Add syntheticId to 5-arg createFormatSupplier chain for time series mode
- Use syntheticId(timeSeries) in tests that use the 4-arg supplier
- Assert TSDBSyntheticIdPostingsFormat or ES87/ES812 where applicable
- Run spotlessApply for formatting

Co-authored-by: Cursor <cursoragent@cursor.com>
@burqen burqen requested review from fcofdez and tlrx February 25, 2026 08:41
@burqen burqen added >test Issues or PRs that are addressing/adding tests :StorageEngine/TSDB You know, for Metrics v9.4.0 labels Feb 25, 2026
@elasticsearchmachine
Copy link
Copy Markdown
Collaborator

Pinging @elastic/es-storage-engine (Team:StorageEngine)

Copy link
Copy Markdown
Contributor

@fcofdez fcofdez left a comment

Choose a reason for hiding this comment

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

LGTM

@@ -165,17 +183,21 @@ public void testUseEs812PostingsFormatForIdField() throws IOException {
Function<String, PostingsFormat> postingsFormats = es87BloomFilterPostingsFormat.getPostingsFormats();
result = postingsFormats.apply("_id");
}
assertThat(result, instanceOf(ES812PostingsFormat.class));
assertThat(result, anyOf(instanceOf(ES812PostingsFormat.class), instanceOf(TSDBSyntheticIdPostingsFormat.class)));
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.

can't we use useSyntheticId here to make a stronger assertion?

Copy link
Copy Markdown
Member

@tlrx tlrx left a comment

Choose a reason for hiding this comment

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

LGTM but I left some minor comments I'd like to see addressed

assertThat(perFieldMapperCodec.useBloomFilter("another_field"), is(false));

Class<? extends PostingsFormat> expectedPostingsFormat = timeSeries ? ES812PostingsFormat.class : Lucene103PostingsFormat.class;
assertThat(perFieldMapperCodec.getPostingsFormatForField("another_field"), instanceOf(expectedPostingsFormat));
}

public void testUseBloomFilterWithTimestampFieldEnabled() throws IOException {
PerFieldFormatSupplier perFieldMapperCodec = createFormatSupplier(true, true, false);
boolean timeSeries = true;
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I wonder why timeSeries is stored in a local variable and not passed directly?

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.

Yeah, this feels odd

Copy link
Copy Markdown
Contributor Author

@burqen burqen Feb 25, 2026

Choose a reason for hiding this comment

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

I wanted to make the dependency between timeSeries and syntheticId clear. That can be quite difficult to decipher without knowledge of the code otherwise.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Maybe a comment could have helped?

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.

I inlined the timeSeries instead as it cause more confusion than clarity :)

@@ -94,33 +96,49 @@ public class PerFieldMapperCodecTests extends ESTestCase {

public void testUseBloomFilter() throws IOException {
boolean timeSeries = randomBoolean();
PerFieldFormatSupplier perFieldMapperCodec = createFormatSupplier(false, timeSeries, false);
boolean syntheticId = syntheticId(timeSeries);
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

nit: could we make this final and rename syntheticId to randomSyntheticId or something like this?

}
}

public void testUseES87TSDBEncodingForTimestampField() throws IOException {
PerFieldFormatSupplier perFieldMapperCodec = createFormatSupplier(true, true, true);
boolean timeSeries = true;
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

yeah, I don't get those local variables :)

@burqen burqen requested review from fcofdez and tlrx February 25, 2026 13:45
Copy link
Copy Markdown
Member

@tlrx tlrx left a comment

Choose a reason for hiding this comment

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

LGTM left nits

@burqen burqen merged commit ce105ed into elastic:main Feb 26, 2026
35 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

:StorageEngine/TSDB You know, for Metrics Team:StorageEngine >test Issues or PRs that are addressing/adding tests v9.4.0

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants