XieJiann commented on code in PR #26592: URL: https://github.com/apache/doris/pull/26592#discussion_r1393848020
########## fe/fe-core/src/main/java/org/apache/doris/nereids/jobs/joinorder/hypergraph/HyperGraph.java: ########## @@ -304,6 +320,108 @@ private long calNodeMap(Set<Slot> slots) { return bitmap; } + public static HyperGraph toStructInfo(Plan plan) { + Preconditions.checkArgument(plan.getGroupExpression().isPresent(), + "HyperGraph requires a GroupExpression in ", plan); + HyperGraph hyperGraph = new HyperGraph(); + hyperGraph.buildStructInfo(plan); + return hyperGraph; + } + + public static HyperGraph toDPhyperGraph(Group group) { + HyperGraph hyperGraph = new HyperGraph(); + hyperGraph.buildDPhyperGraph(group.getLogicalExpressions().get(0)); + return hyperGraph; + } + + // Build Graph for DPhyper + private Pair<BitSet, Long> buildDPhyperGraph(GroupExpression groupExpression) { + // process Project + if (isValidProject(groupExpression.getPlan())) { + LogicalProject<?> project = (LogicalProject<?>) groupExpression.getPlan(); + Pair<BitSet, Long> res = this.buildDPhyperGraph(groupExpression.child(0).getLogicalExpressions().get(0)); + for (NamedExpression expr : project.getProjects()) { + if (expr instanceof Alias) { + this.addAlias((Alias) expr, res.second); + } + } + return res; + } + + // process Join + if (isValidJoin(groupExpression.getPlan())) { + LogicalJoin<?, ?> join = (LogicalJoin<?, ?>) groupExpression.getPlan(); + Pair<BitSet, Long> left = this.buildDPhyperGraph(groupExpression.child(0).getLogicalExpressions().get(0)); + Pair<BitSet, Long> right = this.buildDPhyperGraph(groupExpression.child(1).getLogicalExpressions().get(0)); + return Pair.of(this.addEdge(join, left, right), + LongBitmap.or(left.second, right.second)); + } + + // process Other Node + int idx = this.addDPHyperNode(groupExpression.getOwnerGroup()); + return Pair.of(new BitSet(), LongBitmap.newBitmap(idx)); + } + + // Build Graph for matching mv + private Pair<BitSet, Long> buildStructInfo(Plan plan) { + if (plan instanceof GroupPlan) { + Group group = ((GroupPlan) plan).getGroup(); + if (group.getHyperGraph() == null) { + buildStructInfo(group.getLogicalExpressions().get(0).getPlan()); + } else { Review Comment: Add with GroupPlan children -- 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