@@ -44,7 +44,6 @@ def join_by_column(
44
44
"right" ,
45
45
],
46
46
sort : bool = False ,
47
- coalesce_join_keys : bool = True ,
48
47
allow_row_identity_join : bool = True ,
49
48
) -> Tuple [
50
49
core .ArrayValue ,
@@ -59,8 +58,6 @@ def join_by_column(
59
58
right: Expression for right table to join.
60
59
right_column_ids: Column IDs (not label) to join by.
61
60
how: The type of join to perform.
62
- coalesce_join_keys: if set to False, returned column ids will contain
63
- both left and right join key columns.
64
61
allow_row_identity_join (bool):
65
62
If True, allow matching by row identity. Set to False to always
66
63
perform a true JOIN in generated SQL.
@@ -71,8 +68,6 @@ def join_by_column(
71
68
* Sequence[str]: Column IDs of the coalesced join columns. Sometimes either the
72
69
left/right table will have missing rows. This column pulls the
73
70
non-NULL value from either left/right.
74
- If coalesce_join_keys is False, will return uncombined left and
75
- right key columns.
76
71
* Tuple[Callable, Callable]: For a given column ID from left or right,
77
72
respectively, return the new column id from the combined expression.
78
73
"""
@@ -100,9 +95,7 @@ def join_by_column(
100
95
right_join_keys = [
101
96
combined_expr .get_column (get_column_right (col )) for col in right_column_ids
102
97
]
103
- join_key_cols = get_join_cols (
104
- left_join_keys , right_join_keys , how , coalesce_join_keys
105
- )
98
+ join_key_cols = get_coalesced_join_cols (left_join_keys , right_join_keys , how )
106
99
join_key_ids = [col .get_name () for col in join_key_cols ]
107
100
combined_expr = combined_expr .projection (
108
101
[* join_key_cols , * combined_expr .columns ]
@@ -182,9 +175,7 @@ def get_column_right(col_id):
182
175
right_join_keys = [
183
176
combined_table [get_column_right (col )] for col in right_column_ids
184
177
]
185
- join_key_cols = get_join_cols (
186
- left_join_keys , right_join_keys , how , coalesce_join_keys
187
- )
178
+ join_key_cols = get_coalesced_join_cols (left_join_keys , right_join_keys , how )
188
179
# We could filter out the original join columns, but predicates/ordering
189
180
# might still reference them in implicit joins.
190
181
columns = (
@@ -226,46 +217,35 @@ def get_column_right(col_id):
226
217
)
227
218
228
219
229
- def get_join_cols (
220
+ def get_coalesced_join_cols (
230
221
left_join_cols : typing .Iterable [ibis_types .Value ],
231
222
right_join_cols : typing .Iterable [ibis_types .Value ],
232
223
how : str ,
233
- coalesce_join_keys : bool = True ,
234
224
) -> typing .List [ibis_types .Value ]:
235
225
join_key_cols : list [ibis_types .Value ] = []
236
226
for left_col , right_col in zip (left_join_cols , right_join_cols ):
237
- if not coalesce_join_keys :
227
+ if how == "left" or how == "inner" :
238
228
join_key_cols .append (left_col .name (guid .generate_guid (prefix = "index_" )))
229
+ elif how == "right" :
239
230
join_key_cols .append (right_col .name (guid .generate_guid (prefix = "index_" )))
240
- else :
241
- if how == "left" or how == "inner" :
231
+ elif how == "outer" :
232
+ # The left index and the right index might contain null values, for
233
+ # example due to an outer join with different numbers of rows. Coalesce
234
+ # these to take the index value from either column.
235
+ # Use a random name in case the left index and the right index have the
236
+ # same name. In such a case, _x and _y suffixes will already be used.
237
+ # Don't need to coalesce if they are exactly the same column.
238
+ if left_col .name ("index" ).equals (right_col .name ("index" )):
242
239
join_key_cols .append (left_col .name (guid .generate_guid (prefix = "index_" )))
243
- elif how == "right" :
244
- join_key_cols .append (
245
- right_col .name (guid .generate_guid (prefix = "index_" ))
246
- )
247
- elif how == "outer" :
248
- # The left index and the right index might contain null values, for
249
- # example due to an outer join with different numbers of rows. Coalesce
250
- # these to take the index value from either column.
251
- # Use a random name in case the left index and the right index have the
252
- # same name. In such a case, _x and _y suffixes will already be used.
253
- # Don't need to coalesce if they are exactly the same column.
254
- if left_col .name ("index" ).equals (right_col .name ("index" )):
255
- join_key_cols .append (
256
- left_col .name (guid .generate_guid (prefix = "index_" ))
257
- )
258
- else :
259
- join_key_cols .append (
260
- ibis .coalesce (
261
- left_col ,
262
- right_col ,
263
- ).name (guid .generate_guid (prefix = "index_" ))
264
- )
265
240
else :
266
- raise ValueError (
267
- f"Unexpected join type: { how } . { constants .FEEDBACK_LINK } "
241
+ join_key_cols .append (
242
+ ibis .coalesce (
243
+ left_col ,
244
+ right_col ,
245
+ ).name (guid .generate_guid (prefix = "index_" ))
268
246
)
247
+ else :
248
+ raise ValueError (f"Unexpected join type: { how } . { constants .FEEDBACK_LINK } " )
269
249
return join_key_cols
270
250
271
251
0 commit comments