Skip to content

Commit 9edb151

Browse files
authored
Simplify EsRelation transformation (#138100)
1 parent 3dda52b commit 9edb151

File tree

6 files changed

+10
-18
lines changed

6 files changed

+10
-18
lines changed

x-pack/plugin/esql/src/main/java/org/elasticsearch/xpack/esql/analysis/Analyzer.java

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1942,13 +1942,7 @@ private static LogicalPlan addGeneratedFieldsToEsRelations(LogicalPlan plan, Lis
19421942
}
19431943

19441944
if (missing.isEmpty() == false) {
1945-
return new EsRelation(
1946-
esr.source(),
1947-
esr.indexPattern(),
1948-
esr.indexMode(),
1949-
esr.indexNameWithModes(),
1950-
CollectionUtils.combine(esr.output(), missing)
1951-
);
1945+
return esr.withAttributes(CollectionUtils.combine(esr.output(), missing));
19521946
}
19531947
return esr;
19541948
});

x-pack/plugin/esql/src/main/java/org/elasticsearch/xpack/esql/optimizer/rules/logical/PruneColumns.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -193,7 +193,7 @@ private static LogicalPlan pruneColumnsInEsRelation(EsRelation esr, AttributeSet
193193
// it works differently as we extract all fields (other than the join key) that the EsRelation has.
194194
var remaining = pruneUnusedAndAddReferences(esr.output(), used);
195195
if (remaining != null) {
196-
p = new EsRelation(esr.source(), esr.indexPattern(), esr.indexMode(), esr.indexNameWithModes(), remaining);
196+
p = esr.withAttributes(remaining);
197197
}
198198
}
199199

x-pack/plugin/esql/src/main/java/org/elasticsearch/xpack/esql/optimizer/rules/logical/PruneUnusedIndexMode.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ public PruneUnusedIndexMode() {
2626
protected LogicalPlan rule(EsRelation r) {
2727
if (r.indexMode() == IndexMode.TIME_SERIES) {
2828
if (Expressions.anyMatch(r.output(), a -> MetadataAttribute.TSID_FIELD.equals(((Attribute) a).name())) == false) {
29-
return new EsRelation(r.source(), r.indexPattern(), IndexMode.STANDARD, r.indexNameWithModes(), r.output());
29+
return r.withIndexMode(IndexMode.STANDARD);
3030
}
3131
}
3232
return r;

x-pack/plugin/esql/src/main/java/org/elasticsearch/xpack/esql/optimizer/rules/logical/TranslateTimeSeriesAggregate.java

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -320,15 +320,9 @@ protected LogicalPlan rule(TimeSeriesAggregate aggregate, LogicalOptimizerContex
320320
LogicalPlan newChild = aggregate.child().transformUp(EsRelation.class, r -> {
321321
IndexMode indexMode = requiredTimeSeriesSource.get() ? r.indexMode() : IndexMode.STANDARD;
322322
if (r.output().contains(tsid.get()) == false) {
323-
return new EsRelation(
324-
r.source(),
325-
r.indexPattern(),
326-
indexMode,
327-
r.indexNameWithModes(),
328-
CollectionUtils.combine(r.output(), tsid.get())
329-
);
323+
return r.withIndexMode(indexMode).withAttributes(CollectionUtils.combine(r.output(), tsid.get()));
330324
} else {
331-
return new EsRelation(r.source(), r.indexPattern(), indexMode, r.indexNameWithModes(), r.output());
325+
return r.withIndexMode(indexMode);
332326
}
333327
});
334328
final var firstPhase = new TimeSeriesAggregate(

x-pack/plugin/esql/src/main/java/org/elasticsearch/xpack/esql/plan/logical/EsRelation.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -196,4 +196,8 @@ public String nodeString() {
196196
public EsRelation withAttributes(List<Attribute> newAttributes) {
197197
return new EsRelation(source(), indexPattern, indexMode, indexNameWithModes, newAttributes);
198198
}
199+
200+
public EsRelation withIndexMode(IndexMode indexMode) {
201+
return new EsRelation(source(), indexPattern, indexMode, indexNameWithModes, attrs);
202+
}
199203
}

x-pack/plugin/esql/src/main/java/org/elasticsearch/xpack/esql/plugin/LateMaterializationPlanner.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ public static Optional<ReductionPlan> planReduceDriverTopN(
106106
return r;
107107
}
108108
List<Attribute> attributes = CollectionUtils.prependToCopy(doc, r.output());
109-
return new EsRelation(r.source(), r.indexPattern(), r.indexMode(), r.indexNameWithModes(), attributes);
109+
return r.withAttributes(attributes);
110110
});
111111
if (withAddedDocToRelation.output().stream().noneMatch(EsQueryExec::isDocAttribute)) {
112112
// Defensive check: if any intermediate projects (or possibly another operator) removed the doc field, just abort this

0 commit comments

Comments
 (0)