Skip to content

Commit 3685545

Browse files
committed
remove unused maps
1 parent 13437ca commit 3685545

File tree

11 files changed

+39
-172
lines changed

11 files changed

+39
-172
lines changed

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

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,6 @@ private static PhysicalPlan rewrite(
124124
queryExec.source(),
125125
queryExec.indexName(),
126126
queryExec.indexMode(),
127-
queryExec.indexNameWithModes(),
128127
queryExec.output(),
129128
query,
130129
queryExec.limit(),

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,6 @@ protected PhysicalPlan rule(EsSourceExec plan) {
5353
attributes.add(ma);
5454
}
5555
});
56-
return new EsQueryExec(plan.source(), plan.indexName(), plan.indexMode(), plan.indexNameWithModes(), attributes, plan.query());
56+
return new EsQueryExec(plan.source(), plan.indexName(), plan.indexMode(), attributes, plan.query());
5757
}
5858
}

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

Lines changed: 12 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,6 @@ public class EsQueryExec extends LeafExec implements EstimatesRowSize {
5050

5151
private final String indexName;
5252
private final IndexMode indexMode;
53-
private final Map<String, IndexMode> indexNameWithModes;
5453
private final QueryBuilder query;
5554
private final Expression limit;
5655
private final List<Sort> sorts;
@@ -111,22 +110,14 @@ public FieldAttribute field() {
111110
}
112111
}
113112

114-
public EsQueryExec(
115-
Source source,
116-
String indexName,
117-
IndexMode indexMode,
118-
Map<String, IndexMode> indexNameWithModes,
119-
List<Attribute> attributes,
120-
QueryBuilder query
121-
) {
122-
this(source, indexName, indexMode, indexNameWithModes, attributes, query, null, null, null);
113+
public EsQueryExec(Source source, String indexName, IndexMode indexMode, List<Attribute> attributes, QueryBuilder query) {
114+
this(source, indexName, indexMode, attributes, query, null, null, null);
123115
}
124116

125117
public EsQueryExec(
126118
Source source,
127119
String indexName,
128120
IndexMode indexMode,
129-
Map<String, IndexMode> indexNameWithModes,
130121
List<Attribute> attrs,
131122
QueryBuilder query,
132123
Expression limit,
@@ -136,7 +127,6 @@ public EsQueryExec(
136127
super(source);
137128
this.indexName = indexName;
138129
this.indexMode = indexMode;
139-
this.indexNameWithModes = indexNameWithModes;
140130
this.query = query;
141131
this.attrs = attrs;
142132
this.limit = limit;
@@ -150,24 +140,17 @@ public EsQueryExec(
150140
*/
151141
private static EsQueryExec readFrom(StreamInput in) throws IOException {
152142
var source = Source.readFrom((PlanStreamInput) in);
153-
String indexName;
154-
Map<String, IndexMode> indexNameWithModes;
155-
if (in.getTransportVersion().onOrAfter(ESQL_SKIP_ES_INDEX_SERIALIZATION)) {
156-
indexName = in.readString();
157-
indexNameWithModes = in.readMap(IndexMode::readFrom);
158-
} else {
159-
var index = EsIndex.readFrom(in);
160-
indexName = index.name();
161-
indexNameWithModes = index.indexNameWithModes();
162-
}
143+
var indexName = in.getTransportVersion().onOrAfter(ESQL_SKIP_ES_INDEX_SERIALIZATION)
144+
? in.readString()
145+
: EsIndex.readFrom(in).name();
163146
var indexMode = EsRelation.readIndexMode(in);
164147
var attrs = in.readNamedWriteableCollectionAsList(Attribute.class);
165148
var query = in.readOptionalNamedWriteable(QueryBuilder.class);
166149
var limit = in.readOptionalNamedWriteable(Expression.class);
167150
in.readOptionalCollectionAsList(EsQueryExec::readSort);
168151
var rowSize = in.readOptionalVInt();
169152
// Ignore sorts from the old serialization format
170-
return new EsQueryExec(source, indexName, indexMode, indexNameWithModes, attrs, query, limit, NO_SORTS, rowSize);
153+
return new EsQueryExec(source, indexName, indexMode, attrs, query, limit, NO_SORTS, rowSize);
171154
}
172155

173156
private static Sort readSort(StreamInput in) throws IOException {
@@ -183,9 +166,8 @@ public void writeTo(StreamOutput out) throws IOException {
183166
Source.EMPTY.writeTo(out);
184167
if (out.getTransportVersion().onOrAfter(ESQL_SKIP_ES_INDEX_SERIALIZATION)) {
185168
out.writeString(indexName);
186-
out.writeMap(indexNameWithModes, (o, v) -> IndexMode.writeTo(v, out));
187169
} else {
188-
new EsIndex(indexName, Map.of(), indexNameWithModes).writeTo(out);
170+
new EsIndex(indexName, Map.of(), Map.of()).writeTo(out);
189171
}
190172
EsRelation.writeIndexMode(out, indexMode());
191173
out.writeNamedWriteableCollection(output());
@@ -206,18 +188,7 @@ public static boolean isSourceAttribute(Attribute attr) {
206188

207189
@Override
208190
protected NodeInfo<EsQueryExec> info() {
209-
return NodeInfo.create(
210-
this,
211-
EsQueryExec::new,
212-
indexName,
213-
indexMode,
214-
indexNameWithModes,
215-
attrs,
216-
query,
217-
limit,
218-
sorts,
219-
estimatedRowSize
220-
);
191+
return NodeInfo.create(this, EsQueryExec::new, indexName, indexMode, attrs, query, limit, sorts, estimatedRowSize);
221192
}
222193

223194
public String indexName() {
@@ -228,10 +199,6 @@ public IndexMode indexMode() {
228199
return indexMode;
229200
}
230201

231-
public Map<String, IndexMode> indexNameWithModes() {
232-
return indexNameWithModes;
233-
}
234-
235202
public QueryBuilder query() {
236203
return query;
237204
}
@@ -275,13 +242,13 @@ public PhysicalPlan estimateRowSize(State state) {
275242
}
276243
return Objects.equals(this.estimatedRowSize, size)
277244
? this
278-
: new EsQueryExec(source(), indexName, indexMode, indexNameWithModes, attrs, query, limit, sorts, size);
245+
: new EsQueryExec(source(), indexName, indexMode, attrs, query, limit, sorts, size);
279246
}
280247

281248
public EsQueryExec withLimit(Expression limit) {
282249
return Objects.equals(this.limit, limit)
283250
? this
284-
: new EsQueryExec(source(), indexName, indexMode, indexNameWithModes, attrs, query, limit, sorts, estimatedRowSize);
251+
: new EsQueryExec(source(), indexName, indexMode, attrs, query, limit, sorts, estimatedRowSize);
285252
}
286253

287254
public boolean canPushSorts() {
@@ -295,12 +262,12 @@ public EsQueryExec withSorts(List<Sort> sorts) {
295262
}
296263
return Objects.equals(this.sorts, sorts)
297264
? this
298-
: new EsQueryExec(source(), indexName, indexMode, indexNameWithModes, attrs, query, limit, sorts, estimatedRowSize);
265+
: new EsQueryExec(source(), indexName, indexMode, attrs, query, limit, sorts, estimatedRowSize);
299266
}
300267

301268
@Override
302269
public int hashCode() {
303-
return Objects.hash(indexName, indexMode, indexNameWithModes, attrs, query, limit, sorts);
270+
return Objects.hash(indexName, indexMode, attrs, query, limit, sorts);
304271
}
305272

306273
@Override
@@ -316,7 +283,6 @@ public boolean equals(Object obj) {
316283
EsQueryExec other = (EsQueryExec) obj;
317284
return Objects.equals(indexName, other.indexName)
318285
&& Objects.equals(indexMode, other.indexMode)
319-
&& Objects.equals(indexNameWithModes, other.indexNameWithModes)
320286
&& Objects.equals(attrs, other.attrs)
321287
&& Objects.equals(query, other.query)
322288
&& Objects.equals(limit, other.limit)

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

Lines changed: 9 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -36,56 +36,39 @@ public class EsSourceExec extends LeafExec {
3636

3737
private final String indexName;
3838
private final IndexMode indexMode;
39-
private final Map<String, IndexMode> indexNameWithModes;
4039
private final QueryBuilder query;
4140
private final List<Attribute> attributes;
4241

4342
public EsSourceExec(EsRelation relation) {
44-
this(relation.source(), relation.indexName(), relation.indexMode(), relation.indexNameWithModes(), null, relation.output());
43+
this(relation.source(), relation.indexName(), relation.indexMode(), null, relation.output());
4544
}
4645

47-
public EsSourceExec(
48-
Source source,
49-
String indexName,
50-
IndexMode indexMode,
51-
Map<String, IndexMode> indexNameWithModes,
52-
QueryBuilder query,
53-
List<Attribute> attributes
54-
) {
46+
public EsSourceExec(Source source, String indexName, IndexMode indexMode, QueryBuilder query, List<Attribute> attributes) {
5547
super(source);
5648
this.indexName = indexName;
5749
this.indexMode = indexMode;
58-
this.indexNameWithModes = indexNameWithModes;
5950
this.query = query;
6051
this.attributes = attributes;
6152
}
6253

6354
private static EsSourceExec readFrom(StreamInput in) throws IOException {
6455
var source = Source.readFrom((PlanStreamInput) in);
65-
String indexName;
66-
Map<String, IndexMode> indexNameWithModes;
67-
if (in.getTransportVersion().onOrAfter(ESQL_SKIP_ES_INDEX_SERIALIZATION)) {
68-
indexName = in.readString();
69-
indexNameWithModes = in.readMap(IndexMode::readFrom);
70-
} else {
71-
var index = EsIndex.readFrom(in);
72-
indexName = index.name();
73-
indexNameWithModes = index.indexNameWithModes();
74-
}
56+
var indexName = in.getTransportVersion().onOrAfter(ESQL_SKIP_ES_INDEX_SERIALIZATION)
57+
? in.readString()
58+
: EsIndex.readFrom(in).name();
7559
var attributes = in.readNamedWriteableCollectionAsList(Attribute.class);
7660
var query = in.readOptionalNamedWriteable(QueryBuilder.class);
7761
var indexMode = EsRelation.readIndexMode(in);
78-
return new EsSourceExec(source, indexName, indexMode, indexNameWithModes, query, attributes);
62+
return new EsSourceExec(source, indexName, indexMode, query, attributes);
7963
}
8064

8165
@Override
8266
public void writeTo(StreamOutput out) throws IOException {
8367
Source.EMPTY.writeTo(out);
8468
if (out.getTransportVersion().onOrAfter(ESQL_SKIP_ES_INDEX_SERIALIZATION)) {
8569
out.writeString(indexName);
86-
out.writeMap(indexNameWithModes, (o, v) -> IndexMode.writeTo(v, out));
8770
} else {
88-
new EsIndex(indexName, Map.of(), indexNameWithModes).writeTo(out);
71+
new EsIndex(indexName, Map.of(), Map.of()).writeTo(out);
8972
}
9073
out.writeNamedWriteableCollection(output());
9174
out.writeOptionalNamedWriteable(query());
@@ -105,10 +88,6 @@ public IndexMode indexMode() {
10588
return indexMode;
10689
}
10790

108-
public Map<String, IndexMode> indexNameWithModes() {
109-
return indexNameWithModes;
110-
}
111-
11291
public QueryBuilder query() {
11392
return query;
11493
}
@@ -120,12 +99,12 @@ public List<Attribute> output() {
12099

121100
@Override
122101
protected NodeInfo<? extends PhysicalPlan> info() {
123-
return NodeInfo.create(this, EsSourceExec::new, indexName, indexMode, indexNameWithModes, query, attributes);
102+
return NodeInfo.create(this, EsSourceExec::new, indexName, indexMode, query, attributes);
124103
}
125104

126105
@Override
127106
public int hashCode() {
128-
return Objects.hash(indexName, indexMode, indexNameWithModes, query, attributes);
107+
return Objects.hash(indexName, indexMode, query, attributes);
129108
}
130109

131110
@Override
@@ -141,7 +120,6 @@ public boolean equals(Object obj) {
141120
EsSourceExec other = (EsSourceExec) obj;
142121
return Objects.equals(indexName, other.indexName)
143122
&& Objects.equals(indexMode, other.indexMode)
144-
&& Objects.equals(indexNameWithModes, other.indexNameWithModes)
145123
&& Objects.equals(query, other.query)
146124
&& Objects.equals(attributes, other.attributes);
147125
}

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

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -561,15 +561,6 @@ private PhysicalOperation planLookupJoin(LookupJoinExec join, LocalExecutionPlan
561561
if (localSourceExec.indexMode() != IndexMode.LOOKUP) {
562562
throw new IllegalArgumentException("can't plan [" + join + "]");
563563
}
564-
Map<String, IndexMode> indicesWithModes = localSourceExec.indexNameWithModes();
565-
if (indicesWithModes.size() != 1) {
566-
throw new IllegalArgumentException("can't plan [" + join + "], found more than 1 index");
567-
}
568-
var entry = indicesWithModes.entrySet().iterator().next();
569-
if (entry.getValue() != IndexMode.LOOKUP) {
570-
throw new IllegalArgumentException("can't plan [" + join + "], found index with mode [" + entry.getValue() + "]");
571-
}
572-
String indexName = entry.getKey();
573564
List<Layout.ChannelAndType> matchFields = new ArrayList<>(join.leftFields().size());
574565
for (Attribute m : join.leftFields()) {
575566
Layout.ChannelAndType t = source.layout.get(m.id());
@@ -590,7 +581,7 @@ private PhysicalOperation planLookupJoin(LookupJoinExec join, LocalExecutionPlan
590581
matchFields.getFirst().channel(),
591582
lookupFromIndexService,
592583
matchFields.getFirst().type(),
593-
indexName,
584+
localSourceExec.indexName(),
594585
join.leftFields().getFirst().name(),
595586
join.addedFields().stream().map(f -> (NamedExpression) f).toList(),
596587
join.source()

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

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -186,14 +186,7 @@ public static PhysicalPlan localPlan(
186186
if (filter != null) {
187187
physicalFragment = physicalFragment.transformUp(
188188
EsSourceExec.class,
189-
query -> new EsSourceExec(
190-
Source.EMPTY,
191-
query.indexName(),
192-
query.indexMode(),
193-
query.indexNameWithModes(),
194-
filter,
195-
query.output()
196-
)
189+
query -> new EsSourceExec(Source.EMPTY, query.indexName(), query.indexMode(), filter, query.output())
197190
);
198191
}
199192
var localOptimized = physicalOptimizer.localOptimize(physicalFragment);

x-pack/plugin/esql/src/test/java/org/elasticsearch/xpack/esql/optimizer/PhysicalPlanOptimizerTests.java

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2578,14 +2578,7 @@ public void testFieldExtractWithoutSourceAttributes() {
25782578
// Transform the verified plan so that it is invalid (i.e. no source attributes)
25792579
var badPlan = verifiedPlan.transformDown(
25802580
EsQueryExec.class,
2581-
node -> new EsSourceExec(
2582-
node.source(),
2583-
node.indexName(),
2584-
IndexMode.STANDARD,
2585-
node.indexNameWithModes(),
2586-
node.query(),
2587-
List.of()
2588-
)
2581+
node -> new EsSourceExec(node.source(), node.indexName(), IndexMode.STANDARD, node.query(), List.of())
25892582
);
25902583

25912584
var e = expectThrows(VerificationException.class, () -> physicalPlanOptimizer.verify(badPlan));

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -581,7 +581,7 @@ public TestPhysicalPlanBuilder limit(int limit) {
581581

582582
public TopNExec build() {
583583
List<Attribute> attributes = new ArrayList<>(fields.values());
584-
PhysicalPlan child = new EsQueryExec(Source.EMPTY, this.index, indexMode, Map.of(), attributes, null, null, List.of(), 0);
584+
PhysicalPlan child = new EsQueryExec(Source.EMPTY, this.index, indexMode, attributes, null, null, List.of(), 0);
585585
if (aliases.isEmpty() == false) {
586586
child = new EvalExec(Source.EMPTY, child, aliases);
587587
}

x-pack/plugin/esql/src/test/java/org/elasticsearch/xpack/esql/plan/physical/EsQueryExecSerializationTests.java

Lines changed: 6 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -19,17 +19,13 @@
1919

2020
import java.io.IOException;
2121
import java.util.List;
22-
import java.util.Map;
23-
24-
import static org.elasticsearch.xpack.esql.index.EsIndexSerializationTests.randomIndexNameWithModes;
2522

2623
public class EsQueryExecSerializationTests extends AbstractPhysicalPlanSerializationTests<EsQueryExec> {
2724
public static EsQueryExec randomEsQueryExec() {
2825
return new EsQueryExec(
2926
randomSource(),
3027
randomIdentifier(),
3128
randomFrom(IndexMode.values()),
32-
randomIndexNameWithModes(),
3329
randomFieldAttributes(1, 10, false),
3430
randomQuery(),
3531
new Literal(randomSource(), between(0, Integer.MAX_VALUE), DataType.INTEGER),
@@ -51,37 +47,25 @@ protected EsQueryExec createTestInstance() {
5147
protected EsQueryExec mutateInstance(EsQueryExec instance) throws IOException {
5248
String indexName = instance.indexName();
5349
IndexMode indexMode = instance.indexMode();
54-
Map<String, IndexMode> indexNameWithModes = instance.indexNameWithModes();
5550
List<Attribute> attrs = instance.attrs();
5651
QueryBuilder query = instance.query();
5752
Expression limit = instance.limit();
5853
Integer estimatedRowSize = instance.estimatedRowSize();
59-
switch (between(0, 6)) {
54+
switch (between(0, 5)) {
6055
case 0 -> indexName = randomValueOtherThan(indexName, EsIndexSerializationTests::randomIdentifier);
6156
case 1 -> indexMode = randomValueOtherThan(indexMode, () -> randomFrom(IndexMode.values()));
62-
case 2 -> indexNameWithModes = randomValueOtherThan(indexNameWithModes, EsIndexSerializationTests::randomIndexNameWithModes);
63-
case 3 -> attrs = randomValueOtherThan(attrs, () -> randomFieldAttributes(1, 10, false));
64-
case 4 -> query = randomValueOtherThan(query, EsQueryExecSerializationTests::randomQuery);
65-
case 5 -> limit = randomValueOtherThan(
57+
case 2 -> attrs = randomValueOtherThan(attrs, () -> randomFieldAttributes(1, 10, false));
58+
case 3 -> query = randomValueOtherThan(query, EsQueryExecSerializationTests::randomQuery);
59+
case 4 -> limit = randomValueOtherThan(
6660
limit,
6761
() -> new Literal(randomSource(), between(0, Integer.MAX_VALUE), DataType.INTEGER)
6862
);
69-
case 6 -> estimatedRowSize = randomValueOtherThan(
63+
case 5 -> estimatedRowSize = randomValueOtherThan(
7064
estimatedRowSize,
7165
AbstractPhysicalPlanSerializationTests::randomEstimatedRowSize
7266
);
7367
}
74-
return new EsQueryExec(
75-
instance.source(),
76-
indexName,
77-
indexMode,
78-
indexNameWithModes,
79-
attrs,
80-
query,
81-
limit,
82-
EsQueryExec.NO_SORTS,
83-
estimatedRowSize
84-
);
68+
return new EsQueryExec(instance.source(), indexName, indexMode, attrs, query, limit, EsQueryExec.NO_SORTS, estimatedRowSize);
8569
}
8670

8771
@Override

0 commit comments

Comments
 (0)