@@ -157,9 +157,8 @@ def get_source_columns(self, name: str, only_visible: bool = False) -> Sequence[
157157 ):
158158 columns = source_expr .named_selects
159159
160- # in bigquery, unnest structs are automatically scoped as tables, so you can
161- # directly select a struct field in a query.
162- # this handles the case where the unnest is statically defined.
160+ # in bigquery, unnest structs are automatically scoped as tables, so you can directly select
161+ # a struct field in a query. This handles the case where the unnest is statically defined.
163162 if self .dialect .UNNEST_COLUMN_ONLY and isinstance (source_expr , exp .Unnest ):
164163 if not source_expr .type or source_expr .type .is_type (exp .DType .UNKNOWN ):
165164 unnest_expr = seq_get (source_expr .expressions , 0 )
@@ -178,7 +177,10 @@ def get_source_columns(self, name: str, only_visible: bool = False) -> Sequence[
178177 ):
179178 explode_col = source_expr .this .this
180179
181- if isinstance (explode_col , exp .Column ) and source .parent :
180+ # If the column is unqualified at this point, it couldn't be resolved when
181+ # this scope's children were qualified; disambiguating it here would require
182+ # enumerating this very source's columns, i.e recurse without bound
183+ if isinstance (explode_col , exp .Column ) and explode_col .table and source .parent :
182184 col_type = self ._get_unnest_column_type (explode_col , source .parent )
183185 columns .extend (self ._struct_field_names (col_type ))
184186 elif isinstance (source , Scope ) and isinstance (source .expression , exp .SetOperation ):
0 commit comments