Search in sources :

Example 1 with MatchAggregationLabelDependency

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());
}
Also used : MatchAggregationLabelDependency(io.trino.sql.planner.LocalExecutionPlanner.MatchAggregationLabelDependency) ImmutableList.toImmutableList(com.google.common.collect.ImmutableList.toImmutableList) ImmutableList(com.google.common.collect.ImmutableList) MatchAggregationPointer(io.trino.operator.window.pattern.MatchAggregationPointer) ImmutableList.toImmutableList(com.google.common.collect.ImmutableList.toImmutableList) ArrayList(java.util.ArrayList) List(java.util.List) ImmutableList(com.google.common.collect.ImmutableList) PhysicalValueAccessor(io.trino.operator.window.pattern.PhysicalValueAccessor)

Aggregations

ImmutableList (com.google.common.collect.ImmutableList)1 ImmutableList.toImmutableList (com.google.common.collect.ImmutableList.toImmutableList)1 MatchAggregationPointer (io.trino.operator.window.pattern.MatchAggregationPointer)1 PhysicalValueAccessor (io.trino.operator.window.pattern.PhysicalValueAccessor)1 MatchAggregationLabelDependency (io.trino.sql.planner.LocalExecutionPlanner.MatchAggregationLabelDependency)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1