Skip to content

Commit 187dc92

Browse files
committed
Update with() methods
1 parent 74e780c commit 187dc92

File tree

5 files changed

+43
-41
lines changed

5 files changed

+43
-41
lines changed

x-pack/plugin/esql/src/main/java/org/elasticsearch/xpack/esql/optimizer/rules/physical/local/SpatialDocValuesExtraction.java

Lines changed: 3 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -20,14 +20,11 @@
2020
import org.elasticsearch.xpack.esql.expression.function.scalar.spatial.SpatialRelatesFunction;
2121
import org.elasticsearch.xpack.esql.optimizer.LocalPhysicalOptimizerContext;
2222
import org.elasticsearch.xpack.esql.optimizer.PhysicalOptimizerRules;
23-
import org.elasticsearch.xpack.esql.plan.physical.AbstractAggregateExec;
2423
import org.elasticsearch.xpack.esql.plan.physical.AggregateExec;
2524
import org.elasticsearch.xpack.esql.plan.physical.EvalExec;
2625
import org.elasticsearch.xpack.esql.plan.physical.FieldExtractExec;
2726
import org.elasticsearch.xpack.esql.plan.physical.FilterExec;
2827
import org.elasticsearch.xpack.esql.plan.physical.PhysicalPlan;
29-
import org.elasticsearch.xpack.esql.plan.physical.TimeSeriesAggregateExec;
30-
import org.elasticsearch.xpack.esql.plan.physical.TopNAggregateExec;
3128
import org.elasticsearch.xpack.esql.plan.physical.UnaryExec;
3229
import org.elasticsearch.xpack.esql.stats.SearchStats;
3330

@@ -79,7 +76,7 @@ protected PhysicalPlan rule(AggregateExec aggregate, LocalPhysicalOptimizerConte
7976
var foundAttributes = new HashSet<FieldAttribute>();
8077

8178
PhysicalPlan plan = aggregate.transformDown(UnaryExec.class, exec -> {
82-
if (exec instanceof AbstractAggregateExec agg) {
79+
if (exec instanceof AggregateExec agg) {
8380
var orderedAggregates = new ArrayList<NamedExpression>();
8481
var changedAggregates = false;
8582
for (NamedExpression aggExpr : agg.aggregates()) {
@@ -100,39 +97,7 @@ && allowedForDocValues(fieldAttribute, ctx.searchStats(), agg, foundAttributes))
10097
}
10198
}
10299
if (changedAggregates) {
103-
exec = switch (agg) {
104-
case TimeSeriesAggregateExec tsAggExec -> new TimeSeriesAggregateExec(
105-
agg.source(),
106-
agg.child(),
107-
agg.groupings(),
108-
orderedAggregates,
109-
agg.getMode(),
110-
agg.intermediateAttributes(),
111-
agg.estimatedRowSize(),
112-
tsAggExec.timeBucket()
113-
);
114-
case AggregateExec aggExec -> new AggregateExec(
115-
agg.source(),
116-
agg.child(),
117-
agg.groupings(),
118-
orderedAggregates,
119-
agg.getMode(),
120-
agg.intermediateAttributes(),
121-
agg.estimatedRowSize()
122-
);
123-
case TopNAggregateExec topNAggExec -> new TopNAggregateExec(
124-
agg.source(),
125-
agg.child(),
126-
agg.groupings(),
127-
orderedAggregates,
128-
agg.getMode(),
129-
agg.intermediateAttributes(),
130-
agg.estimatedRowSize(),
131-
topNAggExec.order(),
132-
topNAggExec.limit()
133-
);
134-
default -> throw new IllegalStateException("Unexpected aggregate type: " + agg.getClass().getName());
135-
};
100+
exec = agg.withAggregates(orderedAggregates);
136101
}
137102
}
138103
if (exec instanceof EvalExec evalExec) {
@@ -206,7 +171,7 @@ private boolean foundField(Expression expression, Set<FieldAttribute> foundAttri
206171
private boolean allowedForDocValues(
207172
FieldAttribute fieldAttribute,
208173
SearchStats stats,
209-
AbstractAggregateExec agg,
174+
AggregateExec agg,
210175
Set<FieldAttribute> foundAttributes
211176
) {
212177
if (stats.hasDocValues(fieldAttribute.fieldName()) == false) {

x-pack/plugin/esql/src/main/java/org/elasticsearch/xpack/esql/plan/physical/AbstractAggregateExec.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,10 +113,12 @@ public PhysicalPlan estimateRowSize(State state) {
113113
return Objects.equals(this.estimatedRowSize, size) ? this : withEstimatedSize(size);
114114
}
115115

116-
protected abstract AbstractAggregateExec withEstimatedSize(int estimatedRowSize);
116+
public abstract AbstractAggregateExec withAggregates(List<? extends NamedExpression> aggregates);
117117

118118
public abstract AbstractAggregateExec withMode(AggregatorMode newMode);
119119

120+
protected abstract AbstractAggregateExec withEstimatedSize(int estimatedRowSize);
121+
120122
public AggregatorMode getMode() {
121123
return mode;
122124
}

x-pack/plugin/esql/src/main/java/org/elasticsearch/xpack/esql/plan/physical/AggregateExec.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,11 @@ public AggregateExec replaceChild(PhysicalPlan newChild) {
6464
return new AggregateExec(source(), newChild, groupings, aggregates, mode, intermediateAttributes, estimatedRowSize);
6565
}
6666

67+
@Override
68+
public AggregateExec withAggregates(List<? extends NamedExpression> aggregates) {
69+
return new AggregateExec(source(), child(), groupings, aggregates, mode, intermediateAttributes, estimatedRowSize);
70+
}
71+
6772
@Override
6873
public AggregateExec withMode(AggregatorMode newMode) {
6974
return new AggregateExec(source(), child(), groupings, aggregates, newMode, intermediateAttributes, estimatedRowSize);

x-pack/plugin/esql/src/main/java/org/elasticsearch/xpack/esql/plan/physical/TimeSeriesAggregateExec.java

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,21 @@ public TimeSeriesAggregateExec replaceChild(PhysicalPlan newChild) {
9797
);
9898
}
9999

100+
@Override
101+
public TimeSeriesAggregateExec withAggregates(List<? extends NamedExpression> aggregates) {
102+
return new TimeSeriesAggregateExec(
103+
source(),
104+
child(),
105+
groupings,
106+
aggregates,
107+
mode,
108+
intermediateAttributes,
109+
estimatedRowSize,
110+
timeBucket
111+
);
112+
}
113+
114+
@Override
100115
public TimeSeriesAggregateExec withMode(AggregatorMode newMode) {
101116
return new TimeSeriesAggregateExec(
102117
source(),
@@ -111,7 +126,7 @@ public TimeSeriesAggregateExec withMode(AggregatorMode newMode) {
111126
}
112127

113128
@Override
114-
protected AggregateExec withEstimatedSize(int estimatedRowSize) {
129+
protected TimeSeriesAggregateExec withEstimatedSize(int estimatedRowSize) {
115130
return new TimeSeriesAggregateExec(
116131
source(),
117132
child(),

x-pack/plugin/esql/src/main/java/org/elasticsearch/xpack/esql/plan/physical/TopNAggregateExec.java

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ public Expression limit() {
108108
}
109109

110110
@Override
111-
protected TopNAggregateExec withEstimatedSize(int estimatedRowSize) {
111+
public TopNAggregateExec withAggregates(List<? extends NamedExpression> aggregates) {
112112
return new TopNAggregateExec(
113113
source(),
114114
child(),
@@ -137,6 +137,21 @@ public TopNAggregateExec withMode(AggregatorMode newMode) {
137137
);
138138
}
139139

140+
@Override
141+
protected TopNAggregateExec withEstimatedSize(int estimatedRowSize) {
142+
return new TopNAggregateExec(
143+
source(),
144+
child(),
145+
groupings,
146+
aggregates,
147+
mode,
148+
intermediateAttributes,
149+
estimatedRowSize,
150+
order,
151+
limit
152+
);
153+
}
154+
140155
@Override
141156
public int hashCode() {
142157
return Objects.hash(groupings, aggregates, mode, intermediateAttributes, estimatedRowSize, order, limit, child());

0 commit comments

Comments
 (0)