Skip to content

Commit

Permalink
fix(compiler): generate aliases in a less clever way
Browse files Browse the repository at this point in the history
  • Loading branch information
cpcloud authored and gforsyth committed Mar 10, 2023
1 parent e449c07 commit 04a4aa5
Showing 1 changed file with 4 additions and 6 deletions.
10 changes: 4 additions & 6 deletions ibis/backends/base/sql/compiler/translator.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -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]
Expand All @@ -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)

Expand Down

0 comments on commit 04a4aa5

Please sign in to comment.