Skip to content

Commit 870c865

Browse files
committed
Specialize Distinct Sum
1 parent 1fd74c8 commit 870c865

File tree

4 files changed

+109
-95
lines changed

4 files changed

+109
-95
lines changed

datafusion/physical-expr/src/aggregate/average.rs

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -547,6 +547,7 @@ mod tests {
547547
assert_aggregate(
548548
array,
549549
AggregateFunction::Avg,
550+
false,
550551
ScalarValue::Decimal128(Some(35000), 14, 4),
551552
);
552553
}
@@ -563,6 +564,7 @@ mod tests {
563564
assert_aggregate(
564565
array,
565566
AggregateFunction::Avg,
567+
false,
566568
ScalarValue::Decimal128(Some(32500), 14, 4),
567569
);
568570
}
@@ -580,14 +582,15 @@ mod tests {
580582
assert_aggregate(
581583
array,
582584
AggregateFunction::Avg,
585+
false,
583586
ScalarValue::Decimal128(None, 14, 4),
584587
);
585588
}
586589

587590
#[test]
588591
fn avg_i32() {
589592
let a: ArrayRef = Arc::new(Int32Array::from(vec![1, 2, 3, 4, 5]));
590-
assert_aggregate(a, AggregateFunction::Avg, ScalarValue::from(3_f64));
593+
assert_aggregate(a, AggregateFunction::Avg, false, ScalarValue::from(3_f64));
591594
}
592595

593596
#[test]
@@ -599,33 +602,33 @@ mod tests {
599602
Some(4),
600603
Some(5),
601604
]));
602-
assert_aggregate(a, AggregateFunction::Avg, ScalarValue::from(3.25f64));
605+
assert_aggregate(a, AggregateFunction::Avg, false, ScalarValue::from(3.25f64));
603606
}
604607

605608
#[test]
606609
fn avg_i32_all_nulls() {
607610
let a: ArrayRef = Arc::new(Int32Array::from(vec![None, None]));
608-
assert_aggregate(a, AggregateFunction::Avg, ScalarValue::Float64(None));
611+
assert_aggregate(a, AggregateFunction::Avg, false, ScalarValue::Float64(None));
609612
}
610613

611614
#[test]
612615
fn avg_u32() {
613616
let a: ArrayRef =
614617
Arc::new(UInt32Array::from(vec![1_u32, 2_u32, 3_u32, 4_u32, 5_u32]));
615-
assert_aggregate(a, AggregateFunction::Avg, ScalarValue::from(3.0f64));
618+
assert_aggregate(a, AggregateFunction::Avg, false, ScalarValue::from(3.0f64));
616619
}
617620

618621
#[test]
619622
fn avg_f32() {
620623
let a: ArrayRef =
621624
Arc::new(Float32Array::from(vec![1_f32, 2_f32, 3_f32, 4_f32, 5_f32]));
622-
assert_aggregate(a, AggregateFunction::Avg, ScalarValue::from(3_f64));
625+
assert_aggregate(a, AggregateFunction::Avg, false, ScalarValue::from(3_f64));
623626
}
624627

625628
#[test]
626629
fn avg_f64() {
627630
let a: ArrayRef =
628631
Arc::new(Float64Array::from(vec![1_f64, 2_f64, 3_f64, 4_f64, 5_f64]));
629-
assert_aggregate(a, AggregateFunction::Avg, ScalarValue::from(3_f64));
632+
assert_aggregate(a, AggregateFunction::Avg, false, ScalarValue::from(3_f64));
630633
}
631634
}

datafusion/physical-expr/src/aggregate/sum.rs

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,7 @@ macro_rules! downcast_sum {
7676
}
7777
};
7878
}
79+
pub(crate) use downcast_sum;
7980

8081
impl AggregateExpr for Sum {
8182
/// Return a reference to Any that can be used for downcasting
@@ -302,6 +303,7 @@ mod tests {
302303
assert_aggregate(
303304
array,
304305
AggregateFunction::Sum,
306+
false,
305307
ScalarValue::Decimal128(Some(15), 20, 0),
306308
);
307309
}
@@ -320,6 +322,7 @@ mod tests {
320322
assert_aggregate(
321323
array,
322324
AggregateFunction::Sum,
325+
false,
323326
ScalarValue::Decimal128(Some(13), 38, 0),
324327
);
325328
}
@@ -339,14 +342,15 @@ mod tests {
339342
assert_aggregate(
340343
array,
341344
AggregateFunction::Sum,
345+
false,
342346
ScalarValue::Decimal128(None, 20, 0),
343347
);
344348
}
345349

346350
#[test]
347351
fn sum_i32() {
348352
let a: ArrayRef = Arc::new(Int32Array::from(vec![1, 2, 3, 4, 5]));
349-
assert_aggregate(a, AggregateFunction::Sum, ScalarValue::from(15i64));
353+
assert_aggregate(a, AggregateFunction::Sum, false, ScalarValue::from(15i64));
350354
}
351355

352356
#[test]
@@ -358,33 +362,33 @@ mod tests {
358362
Some(4),
359363
Some(5),
360364
]));
361-
assert_aggregate(a, AggregateFunction::Sum, ScalarValue::from(13i64));
365+
assert_aggregate(a, AggregateFunction::Sum, false, ScalarValue::from(13i64));
362366
}
363367

364368
#[test]
365369
fn sum_i32_all_nulls() {
366370
let a: ArrayRef = Arc::new(Int32Array::from(vec![None, None]));
367-
assert_aggregate(a, AggregateFunction::Sum, ScalarValue::Int64(None));
371+
assert_aggregate(a, AggregateFunction::Sum, false, ScalarValue::Int64(None));
368372
}
369373

370374
#[test]
371375
fn sum_u32() {
372376
let a: ArrayRef =
373377
Arc::new(UInt32Array::from(vec![1_u32, 2_u32, 3_u32, 4_u32, 5_u32]));
374-
assert_aggregate(a, AggregateFunction::Sum, ScalarValue::from(15u64));
378+
assert_aggregate(a, AggregateFunction::Sum, false, ScalarValue::from(15u64));
375379
}
376380

377381
#[test]
378382
fn sum_f32() {
379383
let a: ArrayRef =
380384
Arc::new(Float32Array::from(vec![1_f32, 2_f32, 3_f32, 4_f32, 5_f32]));
381-
assert_aggregate(a, AggregateFunction::Sum, ScalarValue::from(15_f64));
385+
assert_aggregate(a, AggregateFunction::Sum, false, ScalarValue::from(15_f64));
382386
}
383387

384388
#[test]
385389
fn sum_f64() {
386390
let a: ArrayRef =
387391
Arc::new(Float64Array::from(vec![1_f64, 2_f64, 3_f64, 4_f64, 5_f64]));
388-
assert_aggregate(a, AggregateFunction::Sum, ScalarValue::from(15_f64));
392+
assert_aggregate(a, AggregateFunction::Sum, false, ScalarValue::from(15_f64));
389393
}
390394
}

0 commit comments

Comments
 (0)