Given a list of FROM clauses, a selectable, and optional ON clause, return a list of integer indexes from the clauses list indicating the clauses that can be joined from. The presence of an "onclause" indicates that at least one clause can definitely be joined from; if the list of c
(
clauses: Sequence[FromClause],
join_to: _JoinTargetElement,
onclause: Optional[ColumnElement[Any]],
)
| 201 | |
| 202 | |
| 203 | def find_left_clause_to_join_from( |
| 204 | clauses: Sequence[FromClause], |
| 205 | join_to: _JoinTargetElement, |
| 206 | onclause: Optional[ColumnElement[Any]], |
| 207 | ) -> List[int]: |
| 208 | """Given a list of FROM clauses, a selectable, |
| 209 | and optional ON clause, return a list of integer indexes from the |
| 210 | clauses list indicating the clauses that can be joined from. |
| 211 | |
| 212 | The presence of an "onclause" indicates that at least one clause can |
| 213 | definitely be joined from; if the list of clauses is of length one |
| 214 | and the onclause is given, returns that index. If the list of clauses |
| 215 | is more than length one, and the onclause is given, attempts to locate |
| 216 | which clauses contain the same columns. |
| 217 | |
| 218 | """ |
| 219 | idx = [] |
| 220 | selectables = set(_from_objects(join_to)) |
| 221 | |
| 222 | # if we are given more than one target clause to join |
| 223 | # from, use the onclause to provide a more specific answer. |
| 224 | # otherwise, don't try to limit, after all, "ON TRUE" is a valid |
| 225 | # on clause |
| 226 | if len(clauses) > 1 and onclause is not None: |
| 227 | resolve_ambiguity = True |
| 228 | cols_in_onclause = _find_columns(onclause) |
| 229 | else: |
| 230 | resolve_ambiguity = False |
| 231 | cols_in_onclause = None |
| 232 | |
| 233 | for i, f in enumerate(clauses): |
| 234 | for s in selectables.difference([f]): |
| 235 | if resolve_ambiguity: |
| 236 | assert cols_in_onclause is not None |
| 237 | if set(f.c).union(s.c).issuperset(cols_in_onclause): |
| 238 | idx.append(i) |
| 239 | break |
| 240 | elif onclause is not None or Join._can_join(f, s): |
| 241 | idx.append(i) |
| 242 | break |
| 243 | |
| 244 | if len(idx) > 1: |
| 245 | # this is the same "hide froms" logic from |
| 246 | # Selectable._get_display_froms |
| 247 | toremove = set( |
| 248 | chain(*[_expand_cloned(f._hide_froms) for f in clauses]) |
| 249 | ) |
| 250 | idx = [i for i in idx if clauses[i] not in toremove] |
| 251 | |
| 252 | # onclause was given and none of them resolved, so assume |
| 253 | # all indexes can match |
| 254 | if not idx and onclause is not None: |
| 255 | return list(range(len(clauses))) |
| 256 | else: |
| 257 | return idx |
| 258 | |
| 259 | |
| 260 | def visit_binary_product( |
nothing calls this directly
no test coverage detected