From d87f1a3ebb4b8bb4a6489dbe03282005d0e2343a Mon Sep 17 00:00:00 2001 From: seawinde Date: Fri, 29 Dec 2023 09:20:35 +0800 Subject: [PATCH] use BiMap to represent --- .../exploration/mv/mapping/RelationMapping.java | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/fe/fe-core/src/main/java/org/apache/doris/nereids/rules/exploration/mv/mapping/RelationMapping.java b/fe/fe-core/src/main/java/org/apache/doris/nereids/rules/exploration/mv/mapping/RelationMapping.java index fb3164a75867b1..de7e55d6da8c83 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/nereids/rules/exploration/mv/mapping/RelationMapping.java +++ b/fe/fe-core/src/main/java/org/apache/doris/nereids/rules/exploration/mv/mapping/RelationMapping.java @@ -72,7 +72,7 @@ public static List generate(List sources, List MappedRelation.of(relation.getRelationId(), relation)); } Set sourceTableKeySet = sourceTableRelationIdMap.keySet(); - List> mappedRelations = new ArrayList<>(); + List>> mappedRelations = new ArrayList<>(); for (Long sourceTableQualifier : sourceTableKeySet) { Set sourceMappedRelations = sourceTableRelationIdMap.get(sourceTableQualifier); @@ -84,8 +84,8 @@ public static List generate(List sources, List if (targetMappedRelations.size() == 1 && sourceMappedRelations.size() == 1) { ImmutableBiMap.Builder biMapBuilder = ImmutableBiMap.builder(); mappedRelations.add(ImmutableList.of( - RelationMapping.of(biMapBuilder.put(sourceMappedRelations.iterator().next(), - targetMappedRelations.iterator().next()).build()))); + biMapBuilder.put(sourceMappedRelations.iterator().next(), + targetMappedRelations.iterator().next()).build())); continue; } // relation appear more than once, should cartesian them and power set to correct combination @@ -106,7 +106,7 @@ public static List generate(List sources, List // {a0-b0, a1-b1} // {a1-b0, a0-b1} // ] - List relationMappingPowerList = new ArrayList<>(); + List> relationMappingPowerList = new ArrayList<>(); int relationMappingSize = relationMapping.size(); int relationMappingMinSize = Math.min(sourceMappedRelations.size(), targetMappedRelations.size()); for (int i = 0; i < relationMappingSize; i++) { @@ -120,7 +120,7 @@ public static List generate(List sources, List } // mapping should contain min num of relation in source or target at least if (relationBiMap.size() >= relationMappingMinSize) { - relationMappingPowerList.add(RelationMapping.of(ImmutableBiMap.copyOf(relationBiMap))); + relationMappingPowerList.add(relationBiMap); } } mappedRelations.add(relationMappingPowerList); @@ -131,10 +131,10 @@ public static List generate(List sources, List .collect(ImmutableList.toImmutableList()); } - public static RelationMapping merge(List relationMappings) { + public static RelationMapping merge(List> relationMappings) { Builder mappingBuilder = ImmutableBiMap.builder(); - for (RelationMapping relationMapping : relationMappings) { - relationMapping.getMappedRelationMap().forEach(mappingBuilder::put); + for (BiMap relationMapping : relationMappings) { + relationMapping.forEach(mappingBuilder::put); } return RelationMapping.of(mappingBuilder.build()); }