(
left: Joinable,
right: Joinable,
*on: expr.ColumnExpression,
mode: JoinMode,
id: expr.ColumnReference | None = None,
left_instance: expr.ColumnReference | None = None,
right_instance: expr.ColumnReference | None = None,
exact_match: bool = False, # if True do not optionalize output columns even if other than inner join is used
left_exactly_once: bool = False,
right_exactly_once: bool = False,
)
| 994 | |
| 995 | @staticmethod |
| 996 | def _table_join( |
| 997 | left: Joinable, |
| 998 | right: Joinable, |
| 999 | *on: expr.ColumnExpression, |
| 1000 | mode: JoinMode, |
| 1001 | id: expr.ColumnReference | None = None, |
| 1002 | left_instance: expr.ColumnReference | None = None, |
| 1003 | right_instance: expr.ColumnReference | None = None, |
| 1004 | exact_match: bool = False, # if True do not optionalize output columns even if other than inner join is used |
| 1005 | left_exactly_once: bool = False, |
| 1006 | right_exactly_once: bool = False, |
| 1007 | ) -> JoinResult: |
| 1008 | if left == right: |
| 1009 | raise ValueError( |
| 1010 | "Cannot join table with itself. Use <table>.copy() as one of the arguments of the join." |
| 1011 | ) |
| 1012 | |
| 1013 | left_table, left_substitutions = left._substitutions() |
| 1014 | right_table, right_substitutions = right._substitutions() |
| 1015 | |
| 1016 | chained_join_desugaring = SubstitutionDesugaring( |
| 1017 | {**left_substitutions, **right_substitutions} |
| 1018 | ) |
| 1019 | |
| 1020 | if id is not None: |
| 1021 | id = chained_join_desugaring.eval_expression(id) |
| 1022 | id_column = id._column |
| 1023 | else: |
| 1024 | id_column = None |
| 1025 | |
| 1026 | common_column_names: StableSet[str] = StableSet() |
| 1027 | if left_instance is not None and right_instance is not None: |
| 1028 | on = (*on, left_instance == right_instance) |
| 1029 | last_column_is_instance = True |
| 1030 | else: |
| 1031 | assert left_instance is None and right_instance is None |
| 1032 | last_column_is_instance = False |
| 1033 | |
| 1034 | on_ = tuple(validate_shape(cond) for cond in on) |
| 1035 | |
| 1036 | for cond in on_: |
| 1037 | cond_left = cast(expr.ColumnReference, cond._left) |
| 1038 | cond_right = cast(expr.ColumnReference, cond._right) |
| 1039 | if cond_left.name == cond_right.name: |
| 1040 | common_column_names.add(cond_left.name) |
| 1041 | |
| 1042 | on_ = tuple(chained_join_desugaring.eval_expression(cond) for cond in on_) |
| 1043 | |
| 1044 | for cond in on_: |
| 1045 | validate_join_condition(cond, left_table, right_table) |
| 1046 | |
| 1047 | on_left = tuple( |
| 1048 | left_table._eval(cond._left, left_table._table_restricted_context) |
| 1049 | for cond in on_ |
| 1050 | ) |
| 1051 | on_right = tuple( |
| 1052 | right_table._eval(cond._right, right_table._table_restricted_context) |
| 1053 | for cond in on_ |
no test coverage detected