@@ -202,7 +202,12 @@ def _aggregate_base(
202
202
)
203
203
# Must have deterministic ordering, so order by the unique "by" column
204
204
ordering = TotalOrdering (
205
- tuple ([OrderingExpression (column_id ) for column_id in by_column_ids ]),
205
+ tuple (
206
+ [
207
+ OrderingExpression (ex .DerefOp (ref .id .local_normalized ))
208
+ for ref in by_column_ids
209
+ ]
210
+ ),
206
211
total_ordering_columns = frozenset (
207
212
[ex .DerefOp (ref .id .local_normalized ) for ref in by_column_ids ]
208
213
),
@@ -266,31 +271,26 @@ def peek_sql(self, n: int):
266
271
def to_sql (
267
272
self ,
268
273
offset_column : typing .Optional [str ] = None ,
269
- col_id_overrides : typing .Mapping [str , str ] = {},
270
274
ordered : bool = False ,
271
275
) -> str :
272
276
if offset_column or ordered :
273
277
raise ValueError ("Cannot produce sorted sql in partial ordering mode" )
274
- sql = ibis_bigquery .Backend ().compile (
275
- self ._to_ibis_expr (
276
- col_id_overrides = col_id_overrides ,
277
- )
278
- )
278
+ sql = ibis_bigquery .Backend ().compile (self ._to_ibis_expr ())
279
279
return typing .cast (str , sql )
280
280
281
- def row_count (self ) -> OrderedIR :
281
+ def row_count (self , name : str ) -> OrderedIR :
282
282
original_table = self ._to_ibis_expr ()
283
283
ibis_table = original_table .agg (
284
284
[
285
- original_table .count ().name ("count" ),
285
+ original_table .count ().name (name ),
286
286
]
287
287
)
288
288
return OrderedIR (
289
289
ibis_table ,
290
- (ibis_table ["count" ],),
290
+ (ibis_table [name ],),
291
291
ordering = TotalOrdering (
292
- ordering_value_columns = (ascending_over ("count" ),),
293
- total_ordering_columns = frozenset ([ex .deref ("count" )]),
292
+ ordering_value_columns = (ascending_over (name ),),
293
+ total_ordering_columns = frozenset ([ex .deref (name )]),
294
294
),
295
295
)
296
296
@@ -299,7 +299,6 @@ def _to_ibis_expr(
299
299
* ,
300
300
expose_hidden_cols : bool = False ,
301
301
fraction : Optional [float ] = None ,
302
- col_id_overrides : typing .Mapping [str , str ] = {},
303
302
):
304
303
"""
305
304
Creates an Ibis table expression representing the DataFrame.
@@ -320,8 +319,6 @@ def _to_ibis_expr(
320
319
If True, include the hidden ordering columns in the results.
321
320
Only compatible with `order_by` and `unordered`
322
321
``ordering_mode``.
323
- col_id_overrides:
324
- overrides the column ids for the result
325
322
Returns:
326
323
An ibis expression representing the data help by the ArrayValue object.
327
324
"""
@@ -346,10 +343,6 @@ def _to_ibis_expr(
346
343
if self ._reduced_predicate is not None :
347
344
table = table .filter (base_table [PREDICATE_COLUMN ])
348
345
table = table .drop (* columns_to_drop )
349
- if col_id_overrides :
350
- table = table .rename (
351
- {value : key for key , value in col_id_overrides .items ()}
352
- )
353
346
if fraction is not None :
354
347
table = table .filter (ibis .random () < ibis .literal (fraction ))
355
348
return table
@@ -941,7 +934,6 @@ def _reproject_to_table(self) -> OrderedIR:
941
934
942
935
def to_sql (
943
936
self ,
944
- col_id_overrides : typing .Mapping [str , str ] = {},
945
937
ordered : bool = False ,
946
938
limit : Optional [int ] = None ,
947
939
) -> str :
@@ -951,17 +943,13 @@ def to_sql(
951
943
sql = ibis_bigquery .Backend ().compile (
952
944
baked_ir ._to_ibis_expr (
953
945
ordering_mode = "unordered" ,
954
- col_id_overrides = col_id_overrides ,
955
946
expose_hidden_cols = True ,
956
947
)
957
948
)
958
- output_columns = [
959
- col_id_overrides .get (col , col ) for col in baked_ir .column_ids
960
- ]
961
949
sql = (
962
950
bigframes .core .compile .googlesql .Select ()
963
951
.from_ (sql )
964
- .select (output_columns )
952
+ .select (self . column_ids )
965
953
.sql ()
966
954
)
967
955
@@ -979,24 +967,26 @@ def to_sql(
979
967
sql = ibis_bigquery .Backend ().compile (
980
968
self ._to_ibis_expr (
981
969
ordering_mode = "unordered" ,
982
- col_id_overrides = col_id_overrides ,
983
970
expose_hidden_cols = False ,
984
971
)
985
972
)
986
973
return typing .cast (str , sql )
987
974
988
975
def raw_sql_and_schema (
989
976
self ,
977
+ column_ids : typing .Sequence [str ],
990
978
) -> typing .Tuple [str , typing .Sequence [google .cloud .bigquery .SchemaField ]]:
991
979
"""Return sql with all hidden columns. Used to cache with ordering information.
992
980
993
981
Also returns schema, as the extra ordering columns are determined compile-time.
994
982
"""
983
+ col_id_overrides = dict (zip (self .column_ids , column_ids ))
995
984
all_columns = (* self .column_ids , * self ._hidden_ordering_column_names .keys ())
996
985
as_ibis = self ._to_ibis_expr (
997
986
ordering_mode = "unordered" ,
998
987
expose_hidden_cols = True ,
999
- ).select (all_columns )
988
+ )
989
+ as_ibis = as_ibis .select (all_columns ).rename (col_id_overrides )
1000
990
1001
991
# Ibis will produce non-nullable schema types, but bigframes should always be nullable
1002
992
fixed_ibis_schema = ibis_schema .Schema .from_tuples (
@@ -1013,7 +1003,6 @@ def _to_ibis_expr(
1013
1003
* ,
1014
1004
expose_hidden_cols : bool = False ,
1015
1005
fraction : Optional [float ] = None ,
1016
- col_id_overrides : typing .Mapping [str , str ] = {},
1017
1006
ordering_mode : Literal ["string_encoded" , "unordered" ],
1018
1007
order_col_name : Optional [str ] = ORDER_ID_COLUMN ,
1019
1008
):
@@ -1043,8 +1032,6 @@ def _to_ibis_expr(
1043
1032
order_col_name:
1044
1033
If the ordering mode outputs a single ordering or offsets
1045
1034
column, use this as the column name.
1046
- col_id_overrides:
1047
- overrides the column ids for the result
1048
1035
Returns:
1049
1036
An ibis expression representing the data help by the ArrayValue object.
1050
1037
"""
@@ -1086,10 +1073,6 @@ def _to_ibis_expr(
1086
1073
if self ._reduced_predicate is not None :
1087
1074
table = table .filter (base_table [PREDICATE_COLUMN ])
1088
1075
table = table .drop (* columns_to_drop )
1089
- if col_id_overrides :
1090
- table = table .rename (
1091
- {value : key for key , value in col_id_overrides .items ()}
1092
- )
1093
1076
if fraction is not None :
1094
1077
table = table .filter (ibis .random () < ibis .literal (fraction ))
1095
1078
return table
0 commit comments