Skip to content

Commit

Permalink
[fix](Nereids): fix bugs in struct info (apache#27890)
Browse files Browse the repository at this point in the history
  • Loading branch information
keanji-x authored Dec 2, 2023
1 parent 10483ea commit 934f37e
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -431,14 +431,13 @@ private void addStructInfo(HyperGraph other) {
private Pair<BitSet, Long> buildStructInfo(Plan plan) {
if (plan instanceof GroupPlan) {
Group group = ((GroupPlan) plan).getGroup();
buildStructInfo(group.getLogicalExpressions().get(0).getPlan());
List<HyperGraph> childGraphs = ((GroupPlan) plan).getGroup().getHyperGraphs();
if (childGraphs.size() != 0) {
int idx = addStructInfoNode(childGraphs);
return Pair.of(new BitSet(), LongBitmap.newBitmap(idx));
}
GroupExpression groupExpression = group.getLogicalExpressions().get(0);
buildStructInfo(groupExpression.getPlan()
return buildStructInfo(groupExpression.getPlan()
.withChildren(
groupExpression.children().stream().map(GroupPlan::new).collect(Collectors.toList())));
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
// Licensed to the Apache Software Foundation (ASF) under one
// or more contributor license agreements. See the NOTICE file
// distributed with this work for additional information
// regarding copyright ownership. The ASF licenses this file
// to you under the Apache License, Version 2.0 (the
// "License"); you may not use this file except in compliance
// with the License. You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing,
// software distributed under the License is distributed on an
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
// KIND, either express or implied. See the License for the
// specific language governing permissions and limitations
// under the License.

package org.apache.doris.nereids.rules.exploration.mv;

import org.apache.doris.nereids.jobs.joinorder.hypergraph.HyperGraph;
import org.apache.doris.nereids.sqltest.SqlTestBase;
import org.apache.doris.nereids.util.PlanChecker;

import org.junit.jupiter.api.Test;

class BuildStructInfoTest extends SqlTestBase {
@Test
void testSimpleSQL() {
String sql = "select * from T1, T2, T3, T4 "
+ "where "
+ "T1.id = T2.id and "
+ "T2.score = T3.score and "
+ "T3.id = T4.id";
PlanChecker.from(connectContext)
.analyze(sql)
.rewrite()
.deriveStats()
.matches(logicalJoin()
.when(j -> {
HyperGraph.toStructInfo(j);
return true;
}));

}
}

0 comments on commit 934f37e

Please sign in to comment.