Skip to content
Merged
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 @@ -30,6 +30,7 @@
import org.apache.doris.nereids.trees.expressions.literal.Literal;
import org.apache.doris.nereids.trees.plans.logical.LogicalOlapScan;
import org.apache.doris.nereids.trees.plans.logical.LogicalPlan;
import org.apache.doris.nereids.trees.plans.logical.LogicalRepeat;
import org.apache.doris.nereids.util.ExpressionUtils;
import org.apache.doris.nereids.util.LogicalPlanBuilder;
import org.apache.doris.nereids.util.MemoPatternMatchSupported;
Expand All @@ -41,6 +42,8 @@
import com.google.common.collect.ImmutableSet;
import org.junit.jupiter.api.Test;

import java.util.Optional;

public class PushdownFilterThroughAggregationTest implements MemoPatternMatchSupported {
private final LogicalOlapScan scan = new LogicalOlapScan(StatementScopeIdGenerator.newRelationId(), PlanConstructor.student,
ImmutableList.of(""));
Expand Down Expand Up @@ -145,4 +148,59 @@ public void pushDownPredicateTwoFilterTest() {
);
}

@Test
public void pushDownPredicateGroupWithRepeatTest() {
Slot id = scan.getOutput().get(0);
Slot gender = scan.getOutput().get(1);
Slot name = scan.getOutput().get(2);
LogicalRepeat repeatPlan = new LogicalRepeat<>(
ImmutableList.of(ImmutableList.of(id, gender), ImmutableList.of(id)),
ImmutableList.of(id, gender, name), scan);
NamedExpression nameMax = new Alias(new Max(name), "nameMax");

final Expression filterPredicateId = new GreaterThan(id, Literal.of(1));
LogicalPlan plan = new LogicalPlanBuilder(repeatPlan)
.aggGroupUsingIndexAndSourceRepeat(ImmutableList.of(0, 1), ImmutableList.of(
id, gender, nameMax), Optional.of(repeatPlan))
.filter(filterPredicateId)
.project(ImmutableList.of(0))
.build();

PlanChecker.from(MemoTestUtils.createConnectContext(), plan)
.applyTopDown(new PushdownFilterThroughAggregation())
.printlnTree()
.matches(
logicalProject(
logicalAggregate(
logicalFilter(
logicalRepeat()
).when(filter -> filter.getConjuncts().equals(ImmutableSet.of(filterPredicateId)))
)
)
);

repeatPlan = new LogicalRepeat<>(
ImmutableList.of(ImmutableList.of(id, gender), ImmutableList.of(gender)),
ImmutableList.of(id, gender, name), scan);
plan = new LogicalPlanBuilder(repeatPlan)
.aggGroupUsingIndexAndSourceRepeat(ImmutableList.of(0, 1), ImmutableList.of(
id, gender, nameMax), Optional.of(repeatPlan))
.filter(filterPredicateId)
.project(ImmutableList.of(0))
.build();

PlanChecker.from(MemoTestUtils.createConnectContext(), plan)
.applyTopDown(new PushdownFilterThroughAggregation())
.printlnTree()
.matches(
logicalProject(
logicalFilter(
logicalAggregate(
logicalRepeat()
)
).when(filter -> filter.getConjuncts().equals(ImmutableSet.of(filterPredicateId)))
)
);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
import org.apache.doris.nereids.trees.plans.logical.LogicalOlapScan;
import org.apache.doris.nereids.trees.plans.logical.LogicalPlan;
import org.apache.doris.nereids.trees.plans.logical.LogicalProject;
import org.apache.doris.nereids.trees.plans.logical.LogicalRepeat;
import org.apache.doris.nereids.trees.plans.logical.LogicalSort;

import com.google.common.base.Preconditions;
Expand Down Expand Up @@ -170,13 +171,19 @@ public LogicalPlanBuilder aggAllUsingIndex(List<Integer> groupByKeysIndex, List<

public LogicalPlanBuilder aggGroupUsingIndex(List<Integer> groupByKeysIndex,
List<NamedExpression> outputExprsList) {
return aggGroupUsingIndexAndSourceRepeat(groupByKeysIndex, outputExprsList, Optional.empty());
}

public LogicalPlanBuilder aggGroupUsingIndexAndSourceRepeat(List<Integer> groupByKeysIndex,
List<NamedExpression> outputExprsList,
Optional<LogicalRepeat<?>> sourceRepeat) {
Builder<Expression> groupByBuilder = ImmutableList.builder();
for (Integer index : groupByKeysIndex) {
groupByBuilder.add(this.plan.getOutput().get(index));
}
List<Expression> groupByKeys = groupByBuilder.build();

LogicalAggregate<Plan> agg = new LogicalAggregate<>(groupByKeys, outputExprsList, this.plan);
LogicalAggregate<Plan> agg = new LogicalAggregate<>(groupByKeys, outputExprsList, sourceRepeat, this.plan);
return from(agg);
}

Expand Down