16
16
17
17
from __future__ import annotations
18
18
19
+ import itertools
19
20
import typing
20
21
from typing import Callable , Literal , Tuple
21
22
25
26
26
27
import bigframes .constants as constants
27
28
import bigframes .core as core
28
- import bigframes .core .guid
29
+ import bigframes .core .guid as guid
29
30
import bigframes .core .joins .row_identity
30
31
import bigframes .core .ordering
31
32
@@ -122,17 +123,38 @@ def join_by_column(
122
123
),
123
124
)
124
125
else :
126
+ lmapping = {
127
+ col_id : guid .generate_guid ()
128
+ for col_id in itertools .chain (
129
+ left .column_names , left ._hidden_ordering_column_names
130
+ )
131
+ }
132
+ rmapping = {
133
+ col_id : guid .generate_guid ()
134
+ for col_id in itertools .chain (
135
+ right .column_names , right ._hidden_ordering_column_names
136
+ )
137
+ }
138
+
139
+ def get_column_left (col_id ):
140
+ return lmapping [col_id ]
141
+
142
+ def get_column_right (col_id ):
143
+ return rmapping [col_id ]
144
+
125
145
left_table = left ._to_ibis_expr (
126
146
ordering_mode = "unordered" ,
127
147
expose_hidden_cols = True ,
148
+ col_id_overrides = lmapping ,
128
149
)
129
150
right_table = right ._to_ibis_expr (
130
151
ordering_mode = "unordered" ,
131
152
expose_hidden_cols = True ,
153
+ col_id_overrides = rmapping ,
132
154
)
133
155
join_conditions = [
134
- value_to_join_key (left_table [left_index ])
135
- == value_to_join_key (right_table [right_index ])
156
+ value_to_join_key (left_table [lmapping [ left_index ] ])
157
+ == value_to_join_key (right_table [rmapping [ right_index ] ])
136
158
for left_index , right_index in zip (left_column_ids , right_column_ids )
137
159
]
138
160
@@ -145,38 +167,6 @@ def join_by_column(
145
167
rname = "{name}_y" ,
146
168
)
147
169
148
- def get_column_left (key : str ) -> str :
149
- if (
150
- how == "inner"
151
- and key in left_column_ids
152
- and key in combined_table .columns
153
- ):
154
- # Ibis doesn't rename the column if the values are guaranteed
155
- # to be equal on left and right (because they're part of an
156
- # inner join condition). See:
157
- # https://github.com/ibis-project/ibis/pull/4651
158
- pass
159
- elif key in right_table .columns :
160
- key = f"{ key } _x"
161
-
162
- return key
163
-
164
- def get_column_right (key : str ) -> str :
165
- if (
166
- how == "inner"
167
- and key in right_column_ids
168
- and key in combined_table .columns
169
- ):
170
- # Ibis doesn't rename the column if the values are guaranteed
171
- # to be equal on left and right (because they're part of an
172
- # inner join condition). See:
173
- # https://github.com/ibis-project/ibis/pull/4651
174
- pass
175
- elif key in left_table .columns :
176
- key = f"{ key } _y"
177
-
178
- return key
179
-
180
170
# Preserve ordering accross joins.
181
171
ordering = join_orderings (
182
172
left ._ordering ,
@@ -245,20 +235,14 @@ def get_join_cols(
245
235
join_key_cols : list [ibis_types .Value ] = []
246
236
for left_col , right_col in zip (left_join_cols , right_join_cols ):
247
237
if not coalesce_join_keys :
248
- join_key_cols .append (
249
- left_col .name (bigframes .core .guid .generate_guid (prefix = "index_" ))
250
- )
251
- join_key_cols .append (
252
- right_col .name (bigframes .core .guid .generate_guid (prefix = "index_" ))
253
- )
238
+ join_key_cols .append (left_col .name (guid .generate_guid (prefix = "index_" )))
239
+ join_key_cols .append (right_col .name (guid .generate_guid (prefix = "index_" )))
254
240
else :
255
241
if how == "left" or how == "inner" :
256
- join_key_cols .append (
257
- left_col .name (bigframes .core .guid .generate_guid (prefix = "index_" ))
258
- )
242
+ join_key_cols .append (left_col .name (guid .generate_guid (prefix = "index_" )))
259
243
elif how == "right" :
260
244
join_key_cols .append (
261
- right_col .name (bigframes . core . guid .generate_guid (prefix = "index_" ))
245
+ right_col .name (guid .generate_guid (prefix = "index_" ))
262
246
)
263
247
elif how == "outer" :
264
248
# The left index and the right index might contain null values, for
@@ -269,16 +253,14 @@ def get_join_cols(
269
253
# Don't need to coalesce if they are exactly the same column.
270
254
if left_col .name ("index" ).equals (right_col .name ("index" )):
271
255
join_key_cols .append (
272
- left_col .name (
273
- bigframes .core .guid .generate_guid (prefix = "index_" )
274
- )
256
+ left_col .name (guid .generate_guid (prefix = "index_" ))
275
257
)
276
258
else :
277
259
join_key_cols .append (
278
260
ibis .coalesce (
279
261
left_col ,
280
262
right_col ,
281
- ).name (bigframes . core . guid .generate_guid (prefix = "index_" ))
263
+ ).name (guid .generate_guid (prefix = "index_" ))
282
264
)
283
265
else :
284
266
raise ValueError (
0 commit comments