adonis0147 commented on code in PR #11330: URL: https://github.com/apache/doris/pull/11330#discussion_r934117331
########## fe/fe-core/src/test/java/org/apache/doris/nereids/rules/implementation/LogicalProjectToPhysicalProjectTest.java: ########## @@ -18,28 +18,61 @@ package org.apache.doris.nereids.rules.implementation; import org.apache.doris.nereids.PlannerContext; -import org.apache.doris.nereids.memo.Group; import org.apache.doris.nereids.rules.Rule; -import org.apache.doris.nereids.trees.plans.GroupPlan; import org.apache.doris.nereids.trees.plans.Plan; import org.apache.doris.nereids.trees.plans.PlanType; +import org.apache.doris.nereids.trees.plans.logical.LogicalAggregate; +import org.apache.doris.nereids.trees.plans.logical.LogicalFilter; +import org.apache.doris.nereids.trees.plans.logical.LogicalJoin; +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.LogicalSort; +import org.apache.doris.nereids.trees.plans.physical.PhysicalPlan; +import org.apache.doris.nereids.util.PlanConstructor; +import com.google.common.collect.ImmutableMap; import com.google.common.collect.Lists; import mockit.Mocked; import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Test; import java.util.List; +import java.util.Map; public class LogicalProjectToPhysicalProjectTest { - @Test - public void projectionImplTest(@Mocked Group group, @Mocked PlannerContext plannerContext) { - Plan plan = new LogicalProject(Lists.newArrayList(), new GroupPlan(group)); - Rule rule = new LogicalProjectToPhysicalProject().build(); + private final Map<String, Rule> rulesMap + = ImmutableMap.<String, Rule>builder() + .put(LogicalProject.class.getName(), (new LogicalProjectToPhysicalProject()).build()) + .put(LogicalAggregate.class.getName(), (new LogicalAggToPhysicalHashAgg()).build()) + .put(LogicalJoin.class.getName(), (new LogicalJoinToHashJoin()).build()) + .put(LogicalOlapScan.class.getName(), (new LogicalOlapScanToPhysicalOlapScan()).build()) + .put(LogicalFilter.class.getName(), (new LogicalFilterToPhysicalFilter()).build()) + .put(LogicalSort.class.getName(), (new LogicalSortToPhysicalHeapSort()).build()) + .build(); + + private PhysicalPlan rewriteLogicalToPhysical(LogicalPlan plan, PlannerContext plannerContext) { + String name = plan.getClass().getName(); + Rule rule = rulesMap.get(name); List<Plan> transform = rule.transform(plan, plannerContext); Assertions.assertEquals(1, transform.size()); - Plan implPlan = transform.get(0); + Assertions.assertTrue(transform.get(0) instanceof PhysicalPlan); + PhysicalPlan implPlan = (PhysicalPlan) transform.get(0); + List<Plan> children = Lists.newArrayList(); + for (Plan child : plan.children()) { + children.add(rewriteLogicalToPhysical((LogicalPlan) child, plannerContext)); Review Comment: ```suggestion LogicalPlan subLogicalPlan = (LogicalPlan) ((GroupPlan) child).getGroup().getLogicalExpression().getPlan(); children.add(rewriteLogicalToPhysical(subLogicalPlan, plannerContext)); ``` ########## fe/fe-core/src/test/java/org/apache/doris/nereids/rules/implementation/LogicalProjectToPhysicalProjectTest.java: ########## @@ -18,28 +18,61 @@ package org.apache.doris.nereids.rules.implementation; import org.apache.doris.nereids.PlannerContext; -import org.apache.doris.nereids.memo.Group; import org.apache.doris.nereids.rules.Rule; -import org.apache.doris.nereids.trees.plans.GroupPlan; import org.apache.doris.nereids.trees.plans.Plan; import org.apache.doris.nereids.trees.plans.PlanType; +import org.apache.doris.nereids.trees.plans.logical.LogicalAggregate; +import org.apache.doris.nereids.trees.plans.logical.LogicalFilter; +import org.apache.doris.nereids.trees.plans.logical.LogicalJoin; +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.LogicalSort; +import org.apache.doris.nereids.trees.plans.physical.PhysicalPlan; +import org.apache.doris.nereids.util.PlanConstructor; +import com.google.common.collect.ImmutableMap; import com.google.common.collect.Lists; import mockit.Mocked; import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Test; import java.util.List; +import java.util.Map; public class LogicalProjectToPhysicalProjectTest { - @Test - public void projectionImplTest(@Mocked Group group, @Mocked PlannerContext plannerContext) { - Plan plan = new LogicalProject(Lists.newArrayList(), new GroupPlan(group)); - Rule rule = new LogicalProjectToPhysicalProject().build(); + private final Map<String, Rule> rulesMap + = ImmutableMap.<String, Rule>builder() + .put(LogicalProject.class.getName(), (new LogicalProjectToPhysicalProject()).build()) + .put(LogicalAggregate.class.getName(), (new LogicalAggToPhysicalHashAgg()).build()) + .put(LogicalJoin.class.getName(), (new LogicalJoinToHashJoin()).build()) + .put(LogicalOlapScan.class.getName(), (new LogicalOlapScanToPhysicalOlapScan()).build()) + .put(LogicalFilter.class.getName(), (new LogicalFilterToPhysicalFilter()).build()) + .put(LogicalSort.class.getName(), (new LogicalSortToPhysicalHeapSort()).build()) + .build(); + + private PhysicalPlan rewriteLogicalToPhysical(LogicalPlan plan, PlannerContext plannerContext) { + String name = plan.getClass().getName(); + Rule rule = rulesMap.get(name); List<Plan> transform = rule.transform(plan, plannerContext); Assertions.assertEquals(1, transform.size()); - Plan implPlan = transform.get(0); + Assertions.assertTrue(transform.get(0) instanceof PhysicalPlan); + PhysicalPlan implPlan = (PhysicalPlan) transform.get(0); + List<Plan> children = Lists.newArrayList(); + for (Plan child : plan.children()) { + children.add(rewriteLogicalToPhysical((LogicalPlan) child, plannerContext)); + } + implPlan.withChildren(children); + return implPlan; + } + + + @Test + public void projectionImplTest(@Mocked PlannerContext plannerContext) { + LogicalOlapScan scan = PlanConstructor.newLogicalOlapScan("a"); + LogicalPlan project = new LogicalProject<>(Lists.newArrayList(), scan); + + Plan implPlan = rewriteLogicalToPhysical(project, plannerContext); Review Comment: ```suggestion Plan plan = new Memo(project).getRoot().getLogicalExpression().getPlan(); Plan implPlan = rewriteLogicalToPhysical((LogicalPlan) plan, plannerContext); ``` -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: commits-unsubscr...@doris.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org --------------------------------------------------------------------- To unsubscribe, e-mail: commits-unsubscr...@doris.apache.org For additional commands, e-mail: commits-h...@doris.apache.org