'Change the aliases in change_map (which maps old-alias -> new-alias),
relabelling any references to them in select columns and the where
clause.'

def change_aliases(self, change_map):

    assert set(change_map).isdisjoint(change_map.values())
    self.where.relabel_aliases(change_map)
    if isinstance(self.group_by, tuple):
        self.group_by = tuple([col.relabeled_clone(change_map) for col in self.group_by])
    self.select = tuple([col.relabeled_clone(change_map) for col in self.select])
    if self._annotations:
        self._annotations = OrderedDict(((key, col.relabeled_clone(change_map)) for (key, col) in self._annotations.items()))
    for (old_alias, new_alias) in change_map.items():
        if (old_alias not in self.alias_map):
            continue
        alias_data = self.alias_map[old_alias].relabeled_clone(change_map)
        self.alias_map[new_alias] = alias_data
        self.alias_refcount[new_alias] = self.alias_refcount[old_alias]
        del self.alias_refcount[old_alias]
        del self.alias_map[old_alias]
        table_aliases = self.table_map[alias_data.table_name]
        for (pos, alias) in enumerate(table_aliases):
            if (alias == old_alias):
                table_aliases[pos] = new_alias
                break
    self.external_aliases = {change_map.get(alias, alias) for alias in self.external_aliases}
