Skip to content

Commit

Permalink
add log
Browse files Browse the repository at this point in the history
  • Loading branch information
englefly committed Dec 25, 2024
1 parent 68769f8 commit e02f81d
Showing 1 changed file with 9 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@
import org.apache.doris.nereids.trees.plans.Plan;
import org.apache.doris.nereids.trees.plans.logical.LogicalProject;
import org.apache.doris.nereids.trees.plans.logical.LogicalTopN;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;

import java.util.ArrayList;
import java.util.HashMap;
Expand All @@ -49,14 +51,15 @@
*
*/
public class AdjustTopNProject extends OneRewriteRuleFactory {
public static final Logger LOG = LogManager.getLogger(AdjustTopNProject.class);
@Override
public Rule build() {
return logicalTopN(logicalProject())
.then(topN -> adjust(topN)).toRule(RuleType.ADJUST_TOPN_PROJECT);
}

private Plan adjust(LogicalTopN<LogicalProject<Plan>> topN) {
LogicalProject<Plan> project = topN.child();
private Plan adjust(LogicalTopN<? extends Plan> topN) {
LogicalProject<Plan> project = (LogicalProject<Plan>) topN.child();
Set<Slot> projectInputSlots = project.getInputSlots();
Map<SlotReference, SlotReference> keyAsKey = new HashMap<>();
for (NamedExpression proj : project.getProjects()) {
Expand Down Expand Up @@ -84,8 +87,10 @@ private Plan adjust(LogicalTopN<LogicalProject<Plan>> topN) {
}
if (match) {
if (project.getProjects().size() >= project.getInputSlots().size()) {
LogicalTopN newTopN = topN.withChildren(project.children()).withOrderKeys(newOrderKeys);
project = (LogicalProject<Plan>) project.withChildren(newTopN);
LOG.info("$$$$ before:" +topN.treeString());
topN = topN.withChildren(project.children()).withOrderKeys(newOrderKeys);
project = (LogicalProject<Plan>) project.withChildren(topN);
LOG.info("$$$$ after:" + project.treeString());
return project;
}
}
Expand Down

0 comments on commit e02f81d

Please sign in to comment.