Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,8 @@

import java.time.Duration;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.function.Consumer;

Expand Down Expand Up @@ -250,7 +248,6 @@ private record AggFunctionSupplierContext(AggregatorFunctionSupplier supplier, L
private static class IntermediateInputs {
private final List<Attribute> inputAttributes;
private int nextOffset;
private final Map<AggregateFunction, Integer> offsets = new HashMap<>();

IntermediateInputs(AggregateExec aggregateExec) {
inputAttributes = aggregateExec.child().output();
Expand All @@ -259,12 +256,10 @@ private static class IntermediateInputs {

List<Attribute> nextInputAttributes(AggregateFunction af, boolean grouping) {
int intermediateStateSize = AggregateMapper.intermediateStateDesc(af, grouping).size();
int offset = offsets.computeIfAbsent(af, unused -> {
int v = nextOffset;
nextOffset += intermediateStateSize;
return v;
});
return inputAttributes.subList(offset, offset + intermediateStateSize);
int endOffset = nextOffset + intermediateStateSize;
List<Attribute> attributes = inputAttributes.subList(nextOffset, endOffset);
nextOffset = endOffset;
return attributes;
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
import org.elasticsearch.xpack.esql.EsqlIllegalArgumentException;
import org.elasticsearch.xpack.esql.core.expression.Alias;
import org.elasticsearch.xpack.esql.core.expression.Attribute;
import org.elasticsearch.xpack.esql.core.expression.AttributeMap;
import org.elasticsearch.xpack.esql.core.expression.Expression;
import org.elasticsearch.xpack.esql.core.expression.FieldAttribute;
import org.elasticsearch.xpack.esql.core.expression.MetadataAttribute;
Expand All @@ -23,9 +22,8 @@
import org.elasticsearch.xpack.esql.core.type.DataType;
import org.elasticsearch.xpack.esql.expression.function.aggregate.AggregateFunction;

import java.util.HashSet;
import java.util.ArrayList;
import java.util.List;
import java.util.Set;
import java.util.stream.Stream;

/**
Expand All @@ -42,17 +40,12 @@ public static List<NamedExpression> mapGrouping(List<? extends NamedExpression>
}

private static List<NamedExpression> doMapping(List<? extends NamedExpression> aggregates, boolean grouping) {
Set<Expression> seen = new HashSet<>();
AttributeMap.Builder<NamedExpression> attrToExpressionsBuilder = AttributeMap.builder();
List<NamedExpression> namedExpressions = new ArrayList<>();
for (NamedExpression agg : aggregates) {
Expression inner = Alias.unwrap(agg);
if (seen.add(inner)) {
for (var ne : computeEntryForAgg(agg.name(), inner, grouping)) {
attrToExpressionsBuilder.put(ne.toAttribute(), ne);
}
}
namedExpressions.addAll(computeEntryForAgg(agg.name(), inner, grouping));
}
return attrToExpressionsBuilder.build().values().stream().toList();
return namedExpressions;
}

public static List<IntermediateStateDesc> intermediateStateDesc(AggregateFunction fn, boolean grouping) {
Expand Down