Skip to content

Commit 94e9496

Browse files
Merge branch 'main' into do-not-add-use-case-header-twice
2 parents 9dacd3d + fcfc90e commit 94e9496

File tree

6 files changed

+60
-46
lines changed

6 files changed

+60
-46
lines changed

muted-tests.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -392,6 +392,9 @@ tests:
392392
- class: org.elasticsearch.xpack.security.SecurityRolesMultiProjectIT
393393
method: testUpdatingFileBasedRoleAffectsAllProjects
394394
issue: https://github.com/elastic/elasticsearch/issues/126223
395+
- class: org.elasticsearch.packaging.test.DockerTests
396+
method: test020PluginsListWithNoPlugins
397+
issue: https://github.com/elastic/elasticsearch/issues/126232
395398

396399
# Examples:
397400
#

x-pack/plugin/esql-core/src/main/java/org/elasticsearch/xpack/esql/core/expression/AttributeMap.java

Lines changed: 19 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
*/
77
package org.elasticsearch.xpack.esql.core.expression;
88

9+
import org.elasticsearch.common.util.Maps;
910
import org.elasticsearch.common.util.set.Sets;
1011
import org.elasticsearch.xpack.esql.core.QlIllegalArgumentException;
1112

@@ -167,7 +168,11 @@ private AttributeMap(Map<AttributeWrapper, E> other) {
167168
}
168169

169170
private AttributeMap() {
170-
delegate = new LinkedHashMap<>();
171+
this(new LinkedHashMap<>());
172+
}
173+
174+
private AttributeMap(int expectedSize) {
175+
this(Maps.newLinkedHashMapWithExpectedSize(expectedSize));
171176
}
172177

173178
public AttributeMap(Attribute key, E value) {
@@ -176,29 +181,27 @@ public AttributeMap(Attribute key, E value) {
176181
}
177182

178183
public AttributeMap<E> combine(AttributeMap<E> other) {
179-
AttributeMap<E> combine = new AttributeMap<>();
184+
AttributeMap<E> combine = new AttributeMap<>(this.size() + other.size());
180185
combine.addAll(this);
181186
combine.addAll(other);
182-
183187
return combine;
184188
}
185189

186190
public AttributeMap<E> subtract(AttributeMap<E> other) {
187-
AttributeMap<E> diff = new AttributeMap<>();
191+
AttributeMap<E> diff = new AttributeMap<>(this.size());
188192
for (Entry<AttributeWrapper, E> entry : this.delegate.entrySet()) {
189193
if (other.delegate.containsKey(entry.getKey()) == false) {
190194
diff.delegate.put(entry.getKey(), entry.getValue());
191195
}
192196
}
193-
194197
return diff;
195198
}
196199

197200
public AttributeMap<E> intersect(AttributeMap<E> other) {
198201
AttributeMap<E> smaller = (other.size() > size() ? this : other);
199202
AttributeMap<E> larger = (smaller == this ? other : this);
200203

201-
AttributeMap<E> intersect = new AttributeMap<>();
204+
AttributeMap<E> intersect = new AttributeMap<>(smaller.size());
202205
for (Entry<AttributeWrapper, E> entry : smaller.delegate.entrySet()) {
203206
if (larger.delegate.containsKey(entry.getKey())) {
204207
intersect.delegate.put(entry.getKey(), entry.getValue());
@@ -392,13 +395,20 @@ public static <E> AttributeMap<E> of(Attribute key, E value) {
392395
}
393396

394397
public static <E> Builder<E> builder() {
395-
return new Builder<>();
398+
return new Builder<>(new AttributeMap<>());
399+
}
400+
401+
public static <E> Builder<E> builder(int expectedSize) {
402+
return new Builder<>(new AttributeMap<>(expectedSize));
396403
}
397404

398405
public static class Builder<E> {
399-
private final AttributeMap<E> map = new AttributeMap<>();
400406

401-
private Builder() {}
407+
private final AttributeMap<E> map;
408+
409+
private Builder(AttributeMap<E> map) {
410+
this.map = map;
411+
}
402412

403413
public E put(Attribute attr, E value) {
404414
return map.add(attr, value);

x-pack/plugin/esql-core/src/main/java/org/elasticsearch/xpack/esql/core/expression/AttributeSet.java

Lines changed: 33 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,13 @@
66
*/
77
package org.elasticsearch.xpack.esql.core.expression;
88

9+
import java.util.ArrayList;
910
import java.util.Collection;
1011
import java.util.Iterator;
1112
import java.util.Set;
1213
import java.util.Spliterator;
1314
import java.util.function.Consumer;
15+
import java.util.function.Function;
1416
import java.util.function.Predicate;
1517
import java.util.stream.Stream;
1618

@@ -165,33 +167,58 @@ public String toString() {
165167
}
166168

167169
public Builder asBuilder() {
168-
return new Builder().addAll(this);
170+
return builder(size()).addAll(this);
169171
}
170172

171173
public static AttributeSet of(Attribute... attrs) {
172-
final AttributeMap.Builder<Object> mapBuilder = AttributeMap.builder();
174+
final AttributeMap.Builder<Object> mapBuilder = AttributeMap.builder(attrs.length);
173175
for (var a : attrs) {
174176
mapBuilder.put(a, PRESENT);
175177
}
176178
return new AttributeSet(mapBuilder.build());
177179
}
178180

179181
public static AttributeSet of(Collection<? extends Attribute> c) {
180-
final AttributeMap.Builder<Object> mapBuilder = AttributeMap.builder();
182+
final AttributeMap.Builder<Object> mapBuilder = AttributeMap.builder(c.size());
181183
for (var a : c) {
182184
mapBuilder.put(a, PRESENT);
183185
}
184186
return new AttributeSet(mapBuilder.build());
185187
}
186188

189+
public static <T> AttributeSet of(Collection<T> sources, Function<T, Collection<Attribute>> mapper) {
190+
if (sources.isEmpty()) {
191+
return AttributeSet.EMPTY;
192+
}
193+
var size = 0;
194+
var attributeSets = new ArrayList<Collection<Attribute>>(sources.size());
195+
for (T source : sources) {
196+
var attrs = mapper.apply(source);
197+
size += attrs.size();
198+
attributeSets.add(attrs);
199+
}
200+
var builder = AttributeSet.builder(size);
201+
for (Collection<Attribute> attributeSet : attributeSets) {
202+
builder.addAll(attributeSet);
203+
}
204+
return builder.build();
205+
}
206+
187207
public static Builder builder() {
188-
return new Builder();
208+
return new Builder(AttributeMap.builder());
209+
}
210+
211+
public static Builder builder(int expectedSize) {
212+
return new Builder(AttributeMap.builder(expectedSize));
189213
}
190214

191215
public static class Builder {
192-
private final AttributeMap.Builder<Object> mapBuilder = AttributeMap.builder();
193216

194-
private Builder() {}
217+
private final AttributeMap.Builder<Object> mapBuilder;
218+
219+
private Builder(AttributeMap.Builder<Object> mapBuilder) {
220+
this.mapBuilder = mapBuilder;
221+
}
195222

196223
public Builder add(Attribute attr) {
197224
mapBuilder.put(attr, PRESENT);

x-pack/plugin/esql-core/src/main/java/org/elasticsearch/xpack/esql/core/expression/Expressions.java

Lines changed: 1 addition & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -35,18 +35,6 @@ public static List<Attribute> asAttributes(List<? extends NamedExpression> named
3535
return list;
3636
}
3737

38-
public static AttributeMap<Expression> asAttributeMap(List<? extends NamedExpression> named) {
39-
if (named.isEmpty()) {
40-
return AttributeMap.emptyAttributeMap();
41-
}
42-
43-
AttributeMap.Builder<Expression> mapBuilder = AttributeMap.builder();
44-
for (NamedExpression exp : named) {
45-
mapBuilder.put(exp.toAttribute(), exp);
46-
}
47-
return mapBuilder.build();
48-
}
49-
5038
public static boolean anyMatch(List<? extends Expression> exps, Predicate<? super Expression> predicate) {
5139
for (Expression exp : exps) {
5240
if (exp.anyMatch(predicate)) {
@@ -117,15 +105,7 @@ public static List<Object> fold(FoldContext ctx, List<? extends Expression> exps
117105
}
118106

119107
public static AttributeSet references(List<? extends Expression> exps) {
120-
if (exps.isEmpty()) {
121-
return AttributeSet.EMPTY;
122-
}
123-
124-
var setBuilder = AttributeSet.builder();
125-
for (Expression exp : exps) {
126-
setBuilder.addAll(exp.references());
127-
}
128-
return setBuilder.build();
108+
return AttributeSet.of(exps, Expression::references);
129109
}
130110

131111
public static String name(Expression e) {

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

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77

88
package org.elasticsearch.xpack.esql.optimizer.rules;
99

10+
import org.elasticsearch.common.util.set.Sets;
1011
import org.elasticsearch.xpack.esql.common.Failures;
1112
import org.elasticsearch.xpack.esql.core.expression.Attribute;
1213
import org.elasticsearch.xpack.esql.core.expression.AttributeSet;
@@ -15,9 +16,6 @@
1516
import org.elasticsearch.xpack.esql.plan.logical.BinaryPlan;
1617
import org.elasticsearch.xpack.esql.plan.physical.BinaryExec;
1718

18-
import java.util.HashSet;
19-
import java.util.Set;
20-
2119
import static org.elasticsearch.xpack.esql.common.Failure.fail;
2220

2321
public class PlanConsistencyChecker {
@@ -50,8 +48,8 @@ public static void checkPlan(QueryPlan<?> p, Failures failures) {
5048
checkMissing(p, p.references(), p.inputSet(), "missing references", failures);
5149
}
5250

53-
Set<String> outputAttributeNames = new HashSet<>();
54-
Set<NameId> outputAttributeIds = new HashSet<>();
51+
var outputAttributeNames = Sets.<String>newHashSetWithExpectedSize(p.output().size());
52+
var outputAttributeIds = Sets.<NameId>newHashSetWithExpectedSize(p.output().size());
5553
for (Attribute outputAttr : p.output()) {
5654
if (outputAttributeNames.add(outputAttr.name()) == false || outputAttributeIds.add(outputAttr.id()) == false) {
5755
failures.add(

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

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -48,11 +48,7 @@ public AttributeSet outputSet() {
4848

4949
public AttributeSet inputSet() {
5050
if (lazyInputSet == null) {
51-
List<Attribute> attrs = new ArrayList<>();
52-
for (PlanType child : children()) {
53-
attrs.addAll(child.output());
54-
}
55-
lazyInputSet = AttributeSet.of(attrs);
51+
lazyInputSet = AttributeSet.of(children(), QueryPlan::output);
5652
}
5753
return lazyInputSet;
5854
}

0 commit comments

Comments
 (0)