Skip to content

Commit 54f7bd4

Browse files
committed
upd
1 parent 6401d01 commit 54f7bd4

File tree

3 files changed

+22
-22
lines changed

3 files changed

+22
-22
lines changed

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

Lines changed: 20 additions & 0 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

@@ -184,6 +186,24 @@ public static AttributeSet of(Collection<? extends Attribute> c) {
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() {
188208
return new Builder(AttributeMap.builder());
189209
}

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

Lines changed: 1 addition & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -105,23 +105,7 @@ public static List<Object> fold(FoldContext ctx, List<? extends Expression> exps
105105
}
106106

107107
public static AttributeSet references(List<? extends Expression> exps) {
108-
if (exps.isEmpty()) {
109-
return AttributeSet.EMPTY;
110-
}
111-
112-
var size = 0;
113-
var references = new ArrayList<AttributeSet>(exps.size());
114-
for (Expression exp : exps) {
115-
var refs = exp.references();
116-
size += refs.size();
117-
references.add(refs);
118-
}
119-
120-
var builder = AttributeSet.builder(size);
121-
for (AttributeSet refs : references) {
122-
builder.addAll(refs);
123-
}
124-
return builder.build();
108+
return AttributeSet.of(exps, Expression::references);
125109
}
126110

127111
public static String name(Expression e) {

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)