use of io.trino.sql.planner.LocalExecutionPlanner.MatchAggregationLabelDependency in project trino by trinodb.
the class ThreadEquivalence method classifyAggregations.
// for every label, iterate over aggregations in the label's defining condition, and divide them into sublists:
// - aggregations which do not depend on `CLASSIFIER`, that is, either do not use `CLASSIFIER` in any of their arguments,
// or apply to only one label, in which case the result of `CLASSIFIER` is always the same.
// - aggregations which depend on `CLASSIFIER`, that is, use `CLASSIFIER` in some of their arguments,
// and apply to more than one label (incl. the universal pattern variable), in which case the result of `CLASSIFIER`
// depends on the actual matched label.
private static AggregationIndexes classifyAggregations(List<List<PhysicalValueAccessor>> valuePointers, List<MatchAggregationLabelDependency> labelDependencies) {
ImmutableList.Builder<List<Integer>> noClassifierAggregations = ImmutableList.builder();
boolean foundNoClassifierAggregations = false;
ImmutableList.Builder<List<Integer>> classifierAggregations = ImmutableList.builder();
boolean foundClassifierAggregations = false;
for (List<PhysicalValueAccessor> pointerList : valuePointers) {
ImmutableList.Builder<Integer> noClassifierAggregationIndexes = ImmutableList.builder();
ImmutableList.Builder<Integer> classifierAggregationIndexes = ImmutableList.builder();
for (PhysicalValueAccessor pointer : pointerList) {
if (pointer instanceof MatchAggregationPointer) {
int aggregationIndex = ((MatchAggregationPointer) pointer).getIndex();
MatchAggregationLabelDependency labelDependency = labelDependencies.get(aggregationIndex);
if (!labelDependency.isClassifierInvolved() || labelDependency.getLabels().size() == 1) {
foundNoClassifierAggregations = true;
noClassifierAggregationIndexes.add(aggregationIndex);
} else {
foundClassifierAggregations = true;
classifierAggregationIndexes.add(aggregationIndex);
}
}
}
noClassifierAggregations.add(noClassifierAggregationIndexes.build());
classifierAggregations.add(classifierAggregationIndexes.build());
}
return new AggregationIndexes(foundNoClassifierAggregations, noClassifierAggregations.build(), foundClassifierAggregations, classifierAggregations.build());
}
Aggregations