[feat](Nereids) update struct info map when there is new expr (#32119)

This commit is contained in:
谢健
2024-03-13 11:16:57 +08:00
committed by yiguolei
parent 7b74b199a5
commit 8a8a06d8b6
2 changed files with 69 additions and 6 deletions

View File

@ -97,28 +97,38 @@ public class StructInfoMap {
* refresh group expression map
*
* @param group the root group
*
* @return whether groupExpressionMap is updated
*/
public void refresh(Group group) {
public boolean refresh(Group group) {
Set<Group> refreshedGroup = new HashSet<>();
int originSize = groupExpressionMap.size();
for (GroupExpression groupExpression : group.getLogicalExpressions()) {
List<Set<BitSet>> childrenTableMap = new ArrayList<>();
boolean needRefresh = false;
if (groupExpression.children().isEmpty()) {
groupExpressionMap.put(constructLeaf(groupExpression), Pair.of(groupExpression, new ArrayList<>()));
BitSet leaf = constructLeaf(groupExpression);
groupExpressionMap.put(leaf, Pair.of(groupExpression, new ArrayList<>()));
continue;
}
for (Group child : groupExpression.children()) {
if (!refreshedGroup.contains(child)) {
StructInfoMap childStructInfoMap = child.getstructInfoMap();
childStructInfoMap.refresh(child);
needRefresh |= childStructInfoMap.refresh(child);
}
refreshedGroup.add(child);
childrenTableMap.add(child.getstructInfoMap().getTableMaps());
}
Set<Pair<BitSet, List<BitSet>>> bitSetWithChildren = cartesianProduct(childrenTableMap);
for (Pair<BitSet, List<BitSet>> bitSetWithChild : bitSetWithChildren) {
groupExpressionMap.put(bitSetWithChild.first, Pair.of(groupExpression, bitSetWithChild.second));
if (needRefresh) {
Set<Pair<BitSet, List<BitSet>>> bitSetWithChildren = cartesianProduct(childrenTableMap);
for (Pair<BitSet, List<BitSet>> bitSetWithChild : bitSetWithChildren) {
groupExpressionMap.put(bitSetWithChild.first, Pair.of(groupExpression, bitSetWithChild.second));
}
}
}
return originSize != groupExpressionMap.size();
}
private BitSet constructLeaf(GroupExpression groupExpression) {