Skip to content

Commit

Permalink
Support is_enable_group_trim agg option
Browse files Browse the repository at this point in the history
  • Loading branch information
Jackie-Jiang committed Dec 16, 2024
1 parent 0e6b9a9 commit e6d0b43
Show file tree
Hide file tree
Showing 17 changed files with 289 additions and 104 deletions.
2 changes: 2 additions & 0 deletions pinot-common/src/main/proto/plan.proto
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,8 @@ message AggregateNode {
repeated int32 groupKeys = 3;
AggType aggType = 4;
bool leafReturnFinalResult = 5;
repeated Collation collations = 6;
int32 limit = 7;
}

message FilterNode {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ public static class AggregateOptions {
public static final String IS_PARTITIONED_BY_GROUP_BY_KEYS = "is_partitioned_by_group_by_keys";
public static final String IS_LEAF_RETURN_FINAL_RESULT = "is_leaf_return_final_result";
public static final String SKIP_LEAF_STAGE_GROUP_BY_AGGREGATION = "is_skip_leaf_stage_group_by";
public static final String ENABLE_GROUP_TRIM = "is_enable_group_trim";

public static final String NUM_GROUPS_LIMIT = "num_groups_limit";
public static final String MAX_INITIAL_RESULT_HOLDER_CAPACITY = "max_initial_result_holder_capacity";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import javax.annotation.Nullable;
import org.apache.calcite.plan.RelOptCluster;
import org.apache.calcite.plan.RelTraitSet;
import org.apache.calcite.rel.RelFieldCollation;
import org.apache.calcite.rel.RelNode;
import org.apache.calcite.rel.RelWriter;
import org.apache.calcite.rel.core.Aggregate;
Expand All @@ -35,39 +36,36 @@ public class PinotLogicalAggregate extends Aggregate {
private final AggType _aggType;
private final boolean _leafReturnFinalResult;

// The following fields are for group trimming purpose, and are extracted from the Sort on top of this Aggregate.
private final List<RelFieldCollation> _collations;
private final int _limit;

public PinotLogicalAggregate(RelOptCluster cluster, RelTraitSet traitSet, List<RelHint> hints, RelNode input,
ImmutableBitSet groupSet, @Nullable List<ImmutableBitSet> groupSets, List<AggregateCall> aggCalls,
AggType aggType, boolean leafReturnFinalResult) {
AggType aggType, boolean leafReturnFinalResult, @Nullable List<RelFieldCollation> collations, int limit) {
super(cluster, traitSet, hints, input, groupSet, groupSets, aggCalls);
_aggType = aggType;
_leafReturnFinalResult = leafReturnFinalResult;
_collations = collations;
_limit = limit;
}

public PinotLogicalAggregate(RelOptCluster cluster, RelTraitSet traitSet, List<RelHint> hints, RelNode input,
ImmutableBitSet groupSet, @Nullable List<ImmutableBitSet> groupSets, List<AggregateCall> aggCalls,
AggType aggType) {
this(cluster, traitSet, hints, input, groupSet, groupSets, aggCalls, aggType, false);
}

public PinotLogicalAggregate(Aggregate aggRel, List<AggregateCall> aggCalls, AggType aggType,
boolean leafReturnFinalResult) {
this(aggRel.getCluster(), aggRel.getTraitSet(), aggRel.getHints(), aggRel.getInput(), aggRel.getGroupSet(),
aggRel.getGroupSets(), aggCalls, aggType, leafReturnFinalResult);
public PinotLogicalAggregate(Aggregate aggRel, RelNode input, ImmutableBitSet groupSet,
@Nullable List<ImmutableBitSet> groupSets, List<AggregateCall> aggCalls, AggType aggType,
boolean leafReturnFinalResult, @Nullable List<RelFieldCollation> collations, int limit) {
this(aggRel.getCluster(), aggRel.getTraitSet(), aggRel.getHints(), input, groupSet, groupSets, aggCalls, aggType,
leafReturnFinalResult, collations, limit);
}

public PinotLogicalAggregate(Aggregate aggRel, List<AggregateCall> aggCalls, AggType aggType) {
this(aggRel, aggCalls, aggType, false);
}

public PinotLogicalAggregate(Aggregate aggRel, RelNode input, List<AggregateCall> aggCalls, AggType aggType) {
this(aggRel.getCluster(), aggRel.getTraitSet(), aggRel.getHints(), input, aggRel.getGroupSet(),
aggRel.getGroupSets(), aggCalls, aggType);
public PinotLogicalAggregate(Aggregate aggRel, RelNode input, List<AggregateCall> aggCalls, AggType aggType,
boolean leafReturnFinalResult, @Nullable List<RelFieldCollation> collations, int limit) {
this(aggRel, input, aggRel.getGroupSet(), aggRel.getGroupSets(), aggCalls, aggType,
leafReturnFinalResult, collations, limit);
}

public PinotLogicalAggregate(Aggregate aggRel, RelNode input, ImmutableBitSet groupSet, List<AggregateCall> aggCalls,
AggType aggType, boolean leafReturnFinalResult) {
this(aggRel.getCluster(), aggRel.getTraitSet(), aggRel.getHints(), input, groupSet, null, aggCalls, aggType,
leafReturnFinalResult);
AggType aggType, boolean leafReturnFinalResult, @Nullable List<RelFieldCollation> collations, int limit) {
this(aggRel, input, groupSet, null, aggCalls, aggType, leafReturnFinalResult, collations, limit);
}

public AggType getAggType() {
Expand All @@ -78,24 +76,35 @@ public boolean isLeafReturnFinalResult() {
return _leafReturnFinalResult;
}

@Nullable
public List<RelFieldCollation> getCollations() {
return _collations;
}

public int getLimit() {
return _limit;
}

@Override
public PinotLogicalAggregate copy(RelTraitSet traitSet, RelNode input, ImmutableBitSet groupSet,
@Nullable List<ImmutableBitSet> groupSets, List<AggregateCall> aggCalls) {
return new PinotLogicalAggregate(getCluster(), traitSet, hints, input, groupSet, groupSets, aggCalls, _aggType,
_leafReturnFinalResult);
_leafReturnFinalResult, _collations, _limit);
}

@Override
public RelWriter explainTerms(RelWriter pw) {
RelWriter relWriter = super.explainTerms(pw);
relWriter.item("aggType", _aggType);
relWriter.itemIf("leafReturnFinalResult", true, _leafReturnFinalResult);
relWriter.itemIf("collations", _collations, _collations != null);
relWriter.itemIf("limit", _limit, _limit > 0);
return relWriter;
}

@Override
public RelNode withHints(List<RelHint> hintList) {
return new PinotLogicalAggregate(getCluster(), traitSet, hintList, input, groupSet, groupSets, aggCalls, _aggType,
_leafReturnFinalResult);
_leafReturnFinalResult, _collations, _limit);
}
}
Loading

0 comments on commit e6d0b43

Please sign in to comment.