(
cond: expr.ColumnExpression, left: Table, right: Table
)
| 1135 | |
| 1136 | |
| 1137 | def validate_join_condition( |
| 1138 | cond: expr.ColumnExpression, left: Table, right: Table |
| 1139 | ) -> tuple[expr.ColumnReference, expr.ColumnReference, expr.ColumnBinaryOpExpression]: |
| 1140 | cond = validate_shape(cond) |
| 1141 | try: |
| 1142 | eval_type(cond) |
| 1143 | except TypeError: |
| 1144 | raise TypeError( |
| 1145 | "Incompatible types in a join condition.\n" |
| 1146 | + f"The types are: {eval_type(cond._left)} and {eval_type(cond._right)}. " |
| 1147 | + "You might try casting the respective columns to Any type to circumvent this," |
| 1148 | + " but this is most probably an error." |
| 1149 | ) |
| 1150 | cond_left = cast(expr.ColumnReference, cond._left) |
| 1151 | cond_right = cast(expr.ColumnReference, cond._right) |
| 1152 | if cond_left.table == right and cond_right.table == left: |
| 1153 | raise ValueError( |
| 1154 | "The boolean condition is not properly ordered.\n" |
| 1155 | + "The left part should refer to left joinable and the right one should refer to the right joinable," |
| 1156 | + " e.g. t1.join(t2, t1.bar==t2.foo)." |
| 1157 | ) |
| 1158 | if cond_left.table != left: |
| 1159 | raise ValueError( |
| 1160 | "Left part of a join condition has to be a reference to a table " |
| 1161 | + "on the left side of a join" |
| 1162 | ) |
| 1163 | if cond_right.table != right: |
| 1164 | raise ValueError( |
| 1165 | "Right part of a join condition has to be a reference to a table " |
| 1166 | + "on the right side of a join" |
| 1167 | ) |
| 1168 | return cond_left, cond_right, cond |
| 1169 | |
| 1170 | |
| 1171 | def join( |
no test coverage detected