34
34
def compile_aggregate (
35
35
aggregate : ex .Aggregation ,
36
36
bindings : typing .Dict [str , ibis_types .Value ],
37
- agg_order_by : typing .Sequence [ibis_types .Value ] = [],
37
+ order_by : typing .Sequence [ibis_types .Value ] = [],
38
38
) -> ibis_types .Value :
39
39
if isinstance (aggregate , ex .UnaryAggregation ):
40
40
input = scalar_compiler .compile_expression (aggregate .arg , bindings = bindings )
41
- return compile_unary_agg (aggregate .op , input , agg_order_by = agg_order_by )
41
+ return compile_unary_agg (aggregate .op , input , order_by = order_by )
42
42
elif isinstance (aggregate , ex .BinaryAggregation ):
43
43
left = scalar_compiler .compile_expression (aggregate .left , bindings = bindings )
44
44
right = scalar_compiler .compile_expression (aggregate .right , bindings = bindings )
@@ -76,7 +76,7 @@ def compile_unary_agg(
76
76
op : agg_ops .WindowOp ,
77
77
input : ibis_types .Column ,
78
78
window : Optional [window_spec .WindowSpec ] = None ,
79
- agg_order_by : typing .Sequence [ibis_types .Value ] = [],
79
+ order_by : typing .Sequence [ibis_types .Value ] = [],
80
80
) -> ibis_types .Value :
81
81
raise ValueError (f"Can't compile unrecognized operation: { op } " )
82
82
@@ -87,7 +87,7 @@ def constrained_op(
87
87
op ,
88
88
column : ibis_types .Column ,
89
89
window = None ,
90
- agg_order_by : typing .Sequence [ibis_types .Value ] = [],
90
+ order_by : typing .Sequence [ibis_types .Value ] = [],
91
91
):
92
92
if column .type ().is_boolean ():
93
93
column = typing .cast (
@@ -112,7 +112,7 @@ def _(
112
112
op : agg_ops .SumOp ,
113
113
column : ibis_types .NumericColumn ,
114
114
window = None ,
115
- agg_order_by : typing .Sequence [ibis_types .Value ] = [],
115
+ order_by : typing .Sequence [ibis_types .Value ] = [],
116
116
) -> ibis_types .NumericValue :
117
117
# Will be null if all inputs are null. Pandas defaults to zero sum though.
118
118
bq_sum = _apply_window_if_present (column .sum (), window )
@@ -127,7 +127,7 @@ def _(
127
127
op : agg_ops .MedianOp ,
128
128
column : ibis_types .NumericColumn ,
129
129
window = None ,
130
- agg_order_by : typing .Sequence [ibis_types .Value ] = [],
130
+ order_by : typing .Sequence [ibis_types .Value ] = [],
131
131
) -> ibis_types .NumericValue :
132
132
# PERCENTILE_CONT has very few allowed windows. For example, "window
133
133
# framing clause is not allowed for analytic function percentile_cont".
@@ -148,7 +148,7 @@ def _(
148
148
op : agg_ops .ApproxQuartilesOp ,
149
149
column : ibis_types .NumericColumn ,
150
150
window = None ,
151
- agg_order_by : typing .Sequence [ibis_types .Value ] = [],
151
+ order_by : typing .Sequence [ibis_types .Value ] = [],
152
152
) -> ibis_types .NumericValue :
153
153
# PERCENTILE_CONT has very few allowed windows. For example, "window
154
154
# framing clause is not allowed for analytic function percentile_cont".
@@ -168,7 +168,7 @@ def _(
168
168
op : agg_ops .QuantileOp ,
169
169
column : ibis_types .NumericColumn ,
170
170
window = None ,
171
- agg_order_by : typing .Sequence [ibis_types .Value ] = [],
171
+ order_by : typing .Sequence [ibis_types .Value ] = [],
172
172
) -> ibis_types .NumericValue :
173
173
return _apply_window_if_present (column .quantile (op .q ), window )
174
174
@@ -179,7 +179,7 @@ def _(
179
179
op : agg_ops .MeanOp ,
180
180
column : ibis_types .NumericColumn ,
181
181
window = None ,
182
- agg_order_by : typing .Sequence [ibis_types .Value ] = [],
182
+ order_by : typing .Sequence [ibis_types .Value ] = [],
183
183
) -> ibis_types .NumericValue :
184
184
return _apply_window_if_present (column .mean (), window )
185
185
@@ -190,7 +190,7 @@ def _(
190
190
op : agg_ops .ProductOp ,
191
191
column : ibis_types .NumericColumn ,
192
192
window = None ,
193
- agg_order_by : typing .Sequence [ibis_types .Value ] = [],
193
+ order_by : typing .Sequence [ibis_types .Value ] = [],
194
194
) -> ibis_types .NumericValue :
195
195
# Need to short-circuit as log with zeroes is illegal sql
196
196
is_zero = cast (ibis_types .BooleanColumn , (column == 0 ))
@@ -229,7 +229,7 @@ def _(
229
229
op : agg_ops .MaxOp ,
230
230
column : ibis_types .Column ,
231
231
window = None ,
232
- agg_order_by : typing .Sequence [ibis_types .Value ] = [],
232
+ order_by : typing .Sequence [ibis_types .Value ] = [],
233
233
) -> ibis_types .Value :
234
234
return _apply_window_if_present (column .max (), window )
235
235
@@ -239,7 +239,7 @@ def _(
239
239
op : agg_ops .MinOp ,
240
240
column : ibis_types .Column ,
241
241
window = None ,
242
- agg_order_by : typing .Sequence [ibis_types .Value ] = [],
242
+ order_by : typing .Sequence [ibis_types .Value ] = [],
243
243
) -> ibis_types .Value :
244
244
return _apply_window_if_present (column .min (), window )
245
245
@@ -250,7 +250,7 @@ def _(
250
250
op : agg_ops .StdOp ,
251
251
x : ibis_types .Column ,
252
252
window = None ,
253
- agg_order_by : typing .Sequence [ibis_types .Value ] = [],
253
+ order_by : typing .Sequence [ibis_types .Value ] = [],
254
254
) -> ibis_types .Value :
255
255
return _apply_window_if_present (cast (ibis_types .NumericColumn , x ).std (), window )
256
256
@@ -261,7 +261,7 @@ def _(
261
261
op : agg_ops .VarOp ,
262
262
x : ibis_types .Column ,
263
263
window = None ,
264
- agg_order_by : typing .Sequence [ibis_types .Value ] = [],
264
+ order_by : typing .Sequence [ibis_types .Value ] = [],
265
265
) -> ibis_types .Value :
266
266
return _apply_window_if_present (cast (ibis_types .NumericColumn , x ).var (), window )
267
267
@@ -272,7 +272,7 @@ def _(
272
272
op : agg_ops .PopVarOp ,
273
273
x : ibis_types .Column ,
274
274
window = None ,
275
- agg_order_by : typing .Sequence [ibis_types .Value ] = [],
275
+ order_by : typing .Sequence [ibis_types .Value ] = [],
276
276
) -> ibis_types .Value :
277
277
return _apply_window_if_present (
278
278
cast (ibis_types .NumericColumn , x ).var (how = "pop" ), window
@@ -284,7 +284,7 @@ def _(
284
284
op : agg_ops .CountOp ,
285
285
column : ibis_types .Column ,
286
286
window = None ,
287
- agg_order_by : typing .Sequence [ibis_types .Value ] = [],
287
+ order_by : typing .Sequence [ibis_types .Value ] = [],
288
288
) -> ibis_types .IntegerValue :
289
289
return _apply_window_if_present (column .count (), window )
290
290
@@ -294,7 +294,7 @@ def _(
294
294
op : agg_ops .ArrayAggOp ,
295
295
column : ibis_types .Column ,
296
296
window = None ,
297
- agg_order_by : typing .Sequence [ibis_types .Value ] = [],
297
+ order_by : typing .Sequence [ibis_types .Value ] = [],
298
298
) -> ibis_types .ArrayValue :
299
299
# BigQuery doesn't currently support using ARRAY_AGG with both window and aggregate
300
300
# functions simultaneously. Some aggregate functions (or its equivalent syntax)
@@ -310,7 +310,7 @@ def _(
310
310
311
311
return vendored_ibis_ops .ArrayAggregate (
312
312
column ,
313
- order_by_columns = agg_order_by ,
313
+ order_by = order_by ,
314
314
).to_expr ()
315
315
316
316
@@ -319,7 +319,7 @@ def _(
319
319
op : agg_ops .CutOp ,
320
320
x : ibis_types .Column ,
321
321
window = None ,
322
- agg_order_by : typing .Sequence [ibis_types .Value ] = [],
322
+ order_by : typing .Sequence [ibis_types .Value ] = [],
323
323
):
324
324
out = ibis .case ()
325
325
if isinstance (op .bins , int ):
@@ -376,7 +376,7 @@ def _(
376
376
self : agg_ops .QcutOp ,
377
377
column : ibis_types .Column ,
378
378
window = None ,
379
- agg_order_by : typing .Sequence [ibis_types .Value ] = [],
379
+ order_by : typing .Sequence [ibis_types .Value ] = [],
380
380
) -> ibis_types .IntegerValue :
381
381
if isinstance (self .quantiles , int ):
382
382
quantiles_ibis = dtypes .literal_to_ibis_scalar (self .quantiles )
@@ -409,7 +409,7 @@ def _(
409
409
op : agg_ops .NuniqueOp ,
410
410
column : ibis_types .Column ,
411
411
window = None ,
412
- agg_order_by : typing .Sequence [ibis_types .Value ] = [],
412
+ order_by : typing .Sequence [ibis_types .Value ] = [],
413
413
) -> ibis_types .IntegerValue :
414
414
return _apply_window_if_present (column .nunique (), window )
415
415
@@ -419,7 +419,7 @@ def _(
419
419
op : agg_ops .AnyValueOp ,
420
420
column : ibis_types .Column ,
421
421
window = None ,
422
- agg_order_by : typing .Sequence [ibis_types .Value ] = [],
422
+ order_by : typing .Sequence [ibis_types .Value ] = [],
423
423
) -> ibis_types .IntegerValue :
424
424
return _apply_window_if_present (column .arbitrary (), window )
425
425
@@ -429,7 +429,7 @@ def _(
429
429
op : agg_ops .RankOp ,
430
430
column : ibis_types .Column ,
431
431
window = None ,
432
- agg_order_by : typing .Sequence [ibis_types .Value ] = [],
432
+ order_by : typing .Sequence [ibis_types .Value ] = [],
433
433
) -> ibis_types .IntegerValue :
434
434
# Ibis produces 0-based ranks, while pandas creates 1-based ranks
435
435
return _apply_window_if_present (ibis .rank (), window ) + 1
@@ -440,7 +440,7 @@ def _(
440
440
op : agg_ops .DenseRankOp ,
441
441
column : ibis_types .Column ,
442
442
window = None ,
443
- agg_order_by : typing .Sequence [ibis_types .Value ] = [],
443
+ order_by : typing .Sequence [ibis_types .Value ] = [],
444
444
) -> ibis_types .IntegerValue :
445
445
# Ibis produces 0-based ranks, while pandas creates 1-based ranks
446
446
return _apply_window_if_present (column .dense_rank (), window ) + 1
@@ -456,7 +456,7 @@ def _(
456
456
op : agg_ops .FirstNonNullOp ,
457
457
column : ibis_types .Column ,
458
458
window = None ,
459
- agg_order_by : typing .Sequence [ibis_types .Value ] = [],
459
+ order_by : typing .Sequence [ibis_types .Value ] = [],
460
460
) -> ibis_types .Value :
461
461
return _apply_window_if_present (
462
462
vendored_ibis_ops .FirstNonNullValue (column ).to_expr (), window # type: ignore
@@ -468,7 +468,7 @@ def _(
468
468
op : agg_ops .LastOp ,
469
469
column : ibis_types .Column ,
470
470
window = None ,
471
- agg_order_by : typing .Sequence [ibis_types .Value ] = [],
471
+ order_by : typing .Sequence [ibis_types .Value ] = [],
472
472
) -> ibis_types .Value :
473
473
return _apply_window_if_present (column .last (), window )
474
474
@@ -478,7 +478,7 @@ def _(
478
478
op : agg_ops .LastNonNullOp ,
479
479
column : ibis_types .Column ,
480
480
window = None ,
481
- agg_order_by : typing .Sequence [ibis_types .Value ] = [],
481
+ order_by : typing .Sequence [ibis_types .Value ] = [],
482
482
) -> ibis_types .Value :
483
483
return _apply_window_if_present (
484
484
vendored_ibis_ops .LastNonNullValue (column ).to_expr (), window # type: ignore
@@ -490,7 +490,7 @@ def _(
490
490
op : agg_ops .ShiftOp ,
491
491
column : ibis_types .Column ,
492
492
window = None ,
493
- agg_order_by : typing .Sequence [ibis_types .Value ] = [],
493
+ order_by : typing .Sequence [ibis_types .Value ] = [],
494
494
) -> ibis_types .Value :
495
495
if op .periods == 0 : # No-op
496
496
return column
@@ -504,7 +504,7 @@ def _(
504
504
op : agg_ops .DiffOp ,
505
505
column : ibis_types .Column ,
506
506
window = None ,
507
- agg_order_by : typing .Sequence [ibis_types .Value ] = [],
507
+ order_by : typing .Sequence [ibis_types .Value ] = [],
508
508
) -> ibis_types .Value :
509
509
shifted = compile_unary_agg (agg_ops .ShiftOp (op .periods ), column , window )
510
510
if column .type ().is_boolean ():
@@ -524,7 +524,7 @@ def _(
524
524
op : agg_ops .AllOp ,
525
525
column : ibis_types .Column ,
526
526
window = None ,
527
- agg_order_by : typing .Sequence [ibis_types .Value ] = [],
527
+ order_by : typing .Sequence [ibis_types .Value ] = [],
528
528
) -> ibis_types .BooleanValue :
529
529
# BQ will return null for empty column, result would be true in pandas.
530
530
result = _is_true (column ).all ()
@@ -539,7 +539,7 @@ def _(
539
539
op : agg_ops .AnyOp ,
540
540
column : ibis_types .Column ,
541
541
window = None ,
542
- agg_order_by : typing .Sequence [ibis_types .Value ] = [],
542
+ order_by : typing .Sequence [ibis_types .Value ] = [],
543
543
) -> ibis_types .BooleanValue :
544
544
# BQ will return null for empty column, result would be false in pandas.
545
545
result = _is_true (column ).any ()
0 commit comments