1
0
Fork 0

Merging upstream version 7.1.3.

Signed-off-by: Daniel Baumann <daniel@debian.org>
This commit is contained in:
Daniel Baumann 2025-02-13 14:46:58 +01:00
parent 964bd62de9
commit e6b3d2fe54
Signed by: daniel
GPG key ID: FBB4F0E80A80222F
42 changed files with 1430 additions and 253 deletions

View file

@ -1,4 +1,5 @@
import itertools
from collections import defaultdict
from enum import Enum, auto
from sqlglot import exp
@ -314,6 +315,16 @@ class Scope:
self._external_columns = [c for c in self.columns if c.table not in self.selected_sources]
return self._external_columns
@property
def unqualified_columns(self):
"""
Unqualified columns in the current scope.
Returns:
list[exp.Column]: Unqualified columns
"""
return [c for c in self.columns if not c.table]
@property
def join_hints(self):
"""
@ -403,6 +414,21 @@ class Scope:
yield from child_scope.traverse()
yield self
def ref_count(self):
"""
Count the number of times each scope in this tree is referenced.
Returns:
dict[int, int]: Mapping of Scope instance ID to reference count
"""
scope_ref_count = defaultdict(lambda: 0)
for scope in self.traverse():
for _, source in scope.selected_sources.values():
scope_ref_count[id(source)] += 1
return scope_ref_count
def traverse_scope(expression):
"""