Skip to content

Commit 970d693

Browse files
committed
sum_ansi_mode_checks_fix_tests
1 parent 1068f75 commit 970d693

File tree

1 file changed

+8
-13
lines changed

1 file changed

+8
-13
lines changed

native/spark-expr/src/agg_funcs/sum_int.rs

Lines changed: 8 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -33,9 +33,7 @@ use std::{any::Any, sync::Arc};
3333

3434
#[derive(Debug, PartialEq, Eq, Hash)]
3535
pub struct SumInteger {
36-
/// Aggregate function signature
3736
signature: Signature,
38-
/// eval mode : ANSI, Legacy, Try
3937
eval_mode: EvalMode,
4038
}
4139

@@ -110,13 +108,13 @@ impl SumIntegerAccumulator {
110108
Self {
111109
// Try mode starts with 0 (because if this is init to None we cant say if it is none due to all nulls or due to an overflow
112110
sum: Some(0),
113-
has_all_nulls: true, // true = no non-null values yet
111+
has_all_nulls: true,
114112
eval_mode,
115113
}
116114
} else {
117115
Self {
118-
sum: None, // Legacy/ANSI start with None
119-
has_all_nulls: false, // not used for Legacy/ANSI
116+
sum: None,
117+
has_all_nulls: false,
120118
eval_mode,
121119
}
122120
}
@@ -125,7 +123,7 @@ impl SumIntegerAccumulator {
125123

126124
impl Accumulator for SumIntegerAccumulator {
127125
fn update_batch(&mut self, values: &[ArrayRef]) -> DFResult<()> {
128-
// accumulator internal to add sum and return is_null: true if there is an overflow in Try Eval mode
126+
// accumulator internal to add sum and return null sum (and has_nulls false) if there is an overflow in Try Eval mode
129127
fn update_sum_internal<T>(
130128
int_array: &PrimitiveArray<T>,
131129
eval_mode: EvalMode,
@@ -171,7 +169,7 @@ impl Accumulator for SumIntegerAccumulator {
171169
if values.len() == values.null_count() {
172170
Ok(())
173171
} else {
174-
// No nulls so there should be a non-null sum. (null incase overflow in Try eval)
172+
// No nulls so there should be a non-null sum / null incase overflow in Try eval
175173
let running_sum = self.sum.unwrap_or(0);
176174
let sum = match values.data_type() {
177175
DataType::Int64 => update_sum_internal(
@@ -207,7 +205,7 @@ impl Accumulator for SumIntegerAccumulator {
207205
running_sum,
208206
)?,
209207
_ => {
210-
panic!("Unsupported data type")
208+
panic!("Unsupported data type {}", values.data_type())
211209
}
212210
};
213211
self.sum = sum;
@@ -335,7 +333,7 @@ impl GroupsAccumulator for SumIntGroupsAccumulator {
335333
{
336334
for (i, &group_index) in group_indices.iter().enumerate() {
337335
if !int_array.is_null(i) {
338-
// there is an overflow in prev group in try eval . Skip processing
336+
// there is an overflow in prev group in try eval. Skip processing
339337
if eval_mode == EvalMode::Try
340338
&& !has_all_nulls[group_index]
341339
&& sums[group_index].is_none()
@@ -437,7 +435,6 @@ impl GroupsAccumulator for SumIntGroupsAccumulator {
437435
fn evaluate(&mut self, emit_to: EmitTo) -> DFResult<ArrayRef> {
438436
match emit_to {
439437
EmitTo::All => {
440-
// Create an Int64Array with nullability from has_nulls
441438
let result = Arc::new(Int64Array::from_iter(
442439
self.sums
443440
.iter()
@@ -481,7 +478,6 @@ impl GroupsAccumulator for SumIntGroupsAccumulator {
481478
) -> DFResult<()> {
482479
assert!(opt_filter.is_none(), "opt_filter is not supported yet");
483480

484-
// Extract incoming sums array
485481
let that_sums = values[0].as_primitive::<Int64Type>();
486482

487483
if self.eval_mode == EvalMode::Try {
@@ -499,7 +495,6 @@ impl GroupsAccumulator for SumIntGroupsAccumulator {
499495
};
500496

501497
for (idx, &group_index) in group_indices.iter().enumerate() {
502-
// Extract incoming sum value (handle nulls)
503498
let that_sum = if that_sums.is_null(idx) {
504499
None
505500
} else {
@@ -557,7 +552,7 @@ impl GroupsAccumulator for SumIntGroupsAccumulator {
557552
"integer",
558553
)));
559554
} else {
560-
// overflow . update flag accordingly
555+
// overflow. update flag accordingly
561556
self.sums[group_index] = None;
562557
self.has_all_nulls[group_index] = false;
563558
}

0 commit comments

Comments
 (0)