use of org.apache.calcite.rex.RexTableInputRef.RelTableRef in project calcite by apache.
the class AbstractMaterializedViewRule method generateTableMappings.
/**
* It will flatten a multimap containing table references to table references,
* producing all possible combinations of mappings. Each of the mappings will
* be bi-directional.
*/
private static List<BiMap<RelTableRef, RelTableRef>> generateTableMappings(Multimap<RelTableRef, RelTableRef> multiMapTables) {
if (multiMapTables.isEmpty()) {
return ImmutableList.of();
}
List<BiMap<RelTableRef, RelTableRef>> result = ImmutableList.<BiMap<RelTableRef, RelTableRef>>of(HashBiMap.<RelTableRef, RelTableRef>create());
for (Entry<RelTableRef, Collection<RelTableRef>> e : multiMapTables.asMap().entrySet()) {
if (e.getValue().size() == 1) {
// Only one reference, we can just add it to every map
RelTableRef target = e.getValue().iterator().next();
for (BiMap<RelTableRef, RelTableRef> m : result) {
m.put(e.getKey(), target);
}
continue;
}
// Multiple references: flatten
ImmutableList.Builder<BiMap<RelTableRef, RelTableRef>> newResult = ImmutableList.builder();
for (RelTableRef target : e.getValue()) {
for (BiMap<RelTableRef, RelTableRef> m : result) {
if (!m.containsValue(target)) {
final BiMap<RelTableRef, RelTableRef> newM = HashBiMap.<RelTableRef, RelTableRef>create(m);
newM.put(e.getKey(), target);
newResult.add(newM);
}
}
}
result = newResult.build();
}
return result;
}
Aggregations