MCPcopy
hub / github.com/sqlalchemy/sqlalchemy / find_left_clause_that_matches_given

Function find_left_clause_that_matches_given

lib/sqlalchemy/sql/util.py:159–200  ·  view source on GitHub ↗

Given a list of FROM clauses and a selectable, return the indexes from the list of clauses which is derived from the selectable.

(
    clauses: Sequence[FromClause], join_from: FromClause
)

Source from the content-addressed store, hash-verified

157
158
159def find_left_clause_that_matches_given(
160 clauses: Sequence[FromClause], join_from: FromClause
161) -> List[int]:
162 """Given a list of FROM clauses and a selectable,
163 return the indexes from the list of
164 clauses which is derived from the selectable.
165
166 """
167
168 selectables = list(_from_objects(join_from))
169 liberal_idx = []
170 for i, f in enumerate(clauses):
171 for s in selectables:
172 # basic check, if f is derived from s.
173 # this can be joins containing a table, or an aliased table
174 # or select statement matching to a table. This check
175 # will match a table to a selectable that is adapted from
176 # that table. With Query, this suits the case where a join
177 # is being made to an adapted entity
178 if f.is_derived_from(s):
179 liberal_idx.append(i)
180 break
181
182 # in an extremely small set of use cases, a join is being made where
183 # there are multiple FROM clauses where our target table is represented
184 # in more than one, such as embedded or similar. in this case, do
185 # another pass where we try to get a more exact match where we aren't
186 # looking at adaption relationships.
187 if len(liberal_idx) > 1:
188 conservative_idx = []
189 for idx in liberal_idx:
190 f = clauses[idx]
191 for s in selectables:
192 if set(surface_selectables(f)).intersection(
193 surface_selectables(s)
194 ):
195 conservative_idx.append(idx)
196 break
197 if conservative_idx:
198 return conservative_idx
199
200 return liberal_idx
201
202
203def find_left_clause_to_join_from(

Callers

nothing calls this directly

Calls 5

_from_objectsFunction · 0.85
surface_selectablesFunction · 0.85
is_derived_fromMethod · 0.45
appendMethod · 0.45
intersectionMethod · 0.45

Tested by

no test coverage detected