Skip to content
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions docs/changelog/142935.yaml

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.

Given it doesn't change functionality, should we add >non-issue

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.

Yes, thanks! Added a tag

Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
area: ES|QL
issues: []
pr: 142935
summary: '`MetricsInfoOperator` rafctoring'
type: enhancement
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,7 @@ public enum Mode {
/**
* Creates an INITIAL-mode operator (data nodes).
*/
public MetricsInfoOperator(BlockFactory blockFactory, MetricFieldLookup fieldLookup, int metadataSourceChannel, int indexChannel) {
private MetricsInfoOperator(BlockFactory blockFactory, MetricFieldLookup fieldLookup, int metadataSourceChannel, int indexChannel) {

@kkrik-es kkrik-es Feb 24, 2026

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.

You can even keep a single constructor as private, and pass the right combination of args in each factory.

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.

That's even better. Polished. Thanks!

this.mode = Mode.INITIAL;
this.blockFactory = blockFactory;
this.breaker = blockFactory.breaker();
Expand All @@ -215,7 +215,7 @@ public MetricsInfoOperator(BlockFactory blockFactory, MetricFieldLookup fieldLoo
* @param channels the 6 input channel indices mapping to
* [metric_name, data_stream, unit, metric_type, field_type, dimension_fields]
*/
public MetricsInfoOperator(BlockFactory blockFactory, int[] channels) {
private MetricsInfoOperator(BlockFactory blockFactory, int[] channels) {
this.mode = Mode.FINAL;
this.blockFactory = blockFactory;
this.breaker = blockFactory.breaker();
Expand Down Expand Up @@ -246,6 +246,7 @@ private void addInputInitial(Page page) {
BytesRefBlock indexBlock = page.getBlock(indexChannel);

BytesRef indexScratch = new BytesRef();
BytesRef sourceScratch = new BytesRef();

for (int p = 0; p < page.getPositionCount(); p++) {
if (metadataSource.isNull(p)) {
Expand All @@ -257,7 +258,7 @@ private void addInputInitial(Page page) {

String indexName = indexBlock.getBytesRef(p, indexScratch).utf8ToString();
String dataStreamName = resolveDataStreamName(indexName);
Map<String, Object> metadata = parseMetadataSource(metadataSource, p);
Map<String, Object> metadata = parseMetadataSource(metadataSource, p, sourceScratch);
if (metadata == null) {
continue;
}
Expand Down Expand Up @@ -530,11 +531,11 @@ private static void appendMultiValued(BytesRefBlock.Builder builder, Set<String>
}
}

private Map<String, Object> parseMetadataSource(BytesRefBlock metadataSource, int position) {
private Map<String, Object> parseMetadataSource(BytesRefBlock metadataSource, int position, BytesRef sourceScratch) {
if (metadataSource == null || metadataSource.isNull(position)) {
return null;
}
BytesRef bytes = metadataSource.getBytesRef(position, new BytesRef());
BytesRef bytes = metadataSource.getBytesRef(position, sourceScratch);
try (
var parser = XContentType.JSON.xContent()
.createParser(XContentParserConfiguration.EMPTY, bytes.bytes, bytes.offset, bytes.length)
Expand Down
Loading
Loading