(self, from_clause, table_exprs)
| 1153 | allow_with_clause=self.profile.use_nested_with())) |
| 1154 | |
| 1155 | def _create_join_clause(self, from_clause, table_exprs): |
| 1156 | join_type = self.profile.choose_join_type(JoinClause.JOINS_TYPES) |
| 1157 | use_lateral = self.profile.use_lateral_join() |
| 1158 | correlated_collections = from_clause.collections |
| 1159 | if use_lateral and correlated_collections: |
| 1160 | # TODO: Add correlated collections from ancestor queries |
| 1161 | if self.allow_more_nested_queries and self.profile.use_inline_view(): |
| 1162 | collection = self._create_inline_view(correlated_collections) |
| 1163 | else: |
| 1164 | collection = deepcopy(choice(correlated_collections)) |
| 1165 | join_clause = JoinClause(join_type, table_expr=collection) |
| 1166 | join_clause.is_lateral_join = True |
| 1167 | for _ in range(self.profile.get_num_boolean_exprs_for_lateral_join()): |
| 1168 | predicate = self._create_single_join_condition(collection, from_clause.table_exprs) |
| 1169 | if not predicate: |
| 1170 | break |
| 1171 | join_clause.boolean_expr = And.create_from_args(join_clause.boolean_expr, |
| 1172 | predicate) if join_clause.boolean_expr else predicate |
| 1173 | return join_clause |
| 1174 | else: |
| 1175 | candidate_table_exprs = TableExprList(table_exprs) |
| 1176 | candidate_table_exprs.extend(candidate_table_exprs.collections) |
| 1177 | if join_type == 'CROSS': |
| 1178 | table_expr = self._create_table_expr(candidate_table_exprs) |
| 1179 | else: |
| 1180 | available_join_expr_types = set(from_clause.table_exprs.joinable_cols_by_type) \ |
| 1181 | & set(candidate_table_exprs.col_types) |
| 1182 | if not available_join_expr_types: |
| 1183 | raise Exception('No tables have any columns eligible for joining') |
| 1184 | join_expr_type = self.profile.choose_type(tuple(available_join_expr_types)) |
| 1185 | table_expr = self._create_table_expr( |
| 1186 | candidate_table_exprs, required_type=join_expr_type) |
| 1187 | |
| 1188 | if join_type in ('LEFT ANTI', 'LEFT SEMI'): |
| 1189 | table_expr.is_visible = False |
| 1190 | |
| 1191 | join_clause = JoinClause(join_type, table_expr) |
| 1192 | |
| 1193 | if join_type == 'CROSS': |
| 1194 | return join_clause |
| 1195 | |
| 1196 | join_table_expr_candidates = from_clause.table_exprs.by_col_type[join_expr_type] |
| 1197 | if not join_table_expr_candidates: |
| 1198 | raise Exception('table_expr has no common joinable columns') |
| 1199 | join_clause.boolean_expr = self._create_relational_join_condition( |
| 1200 | table_expr, join_table_expr_candidates) |
| 1201 | return join_clause |
| 1202 | |
| 1203 | def _get_joinable_cols_in_common(self, table_expr, other_table_expr): |
| 1204 | common_col_types = set(table_expr.joinable_cols_by_type) \ |
no test coverage detected