From 04a4aa54cfe37a6ff7d0b1dded0fc34395a8813d Mon Sep 17 00:00:00 2001 From: Phillip Cloud <417981+cpcloud@users.noreply.github.com> Date: Fri, 10 Mar 2023 05:34:36 -0500 Subject: [PATCH] fix(compiler): generate aliases in a less clever way --- ibis/backends/base/sql/compiler/translator.py | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/ibis/backends/base/sql/compiler/translator.py b/ibis/backends/base/sql/compiler/translator.py index 2567ad7b2c93..cc6b130743d0 100644 --- a/ibis/backends/base/sql/compiler/translator.py +++ b/ibis/backends/base/sql/compiler/translator.py @@ -27,6 +27,7 @@ def __init__(self, compiler, indent=2, parent=None, params=None): self.always_alias = True self.query = None self.params = params if params is not None else {} + self._alias_counter = getattr(parent, "_alias_counter", 0) def _compile_subquery(self, op): sub_ctx = self.subcontext() @@ -73,11 +74,9 @@ def get_compiled_expr(self, node): return result def make_alias(self, node): - i = len(self.table_refs) + i = self._alias_counter - # Get total number of aliases up and down the tree at this point; if we - # find the table prior-aliased along the way, however, we reuse that - # alias + # check for existing tables that we're referencing from a parent context for ctx in itertools.islice(self._contexts(), 1, None): try: alias = ctx.table_refs[node] @@ -87,8 +86,7 @@ def make_alias(self, node): self.set_ref(node, alias) return - i += len(ctx.table_refs) - + self._alias_counter += 1 alias = f't{i:d}' self.set_ref(node, alias)