From 75d97b7a7d127946829c241a8421e83f3b231e7d Mon Sep 17 00:00:00 2001 From: Pere Diaz Bou Date: Mon, 1 Jul 2024 20:30:45 +0200 Subject: [PATCH] core: fix initialization of sum vdbe Signed-off-by: Pere Diaz Bou --- core/vdbe.rs | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/core/vdbe.rs b/core/vdbe.rs index 5a4f68ab..058173d8 100644 --- a/core/vdbe.rs +++ b/core/vdbe.rs @@ -369,10 +369,15 @@ impl Program { }, Insn::AggStep { acc_reg, col, func } => { if let OwnedValue::Null = &state.registers[*acc_reg] { - state.registers[*acc_reg] = OwnedValue::Agg(Box::new(AggContext::Avg( - OwnedValue::Float(0.0), - OwnedValue::Integer(0), - ))); + state.registers[*acc_reg] = match func { + AggFunc::Avg => OwnedValue::Agg(Box::new(AggContext::Avg( + OwnedValue::Float(0.0), + OwnedValue::Integer(0), + ))), + AggFunc::Sum => { + OwnedValue::Agg(Box::new(AggContext::Sum(OwnedValue::Float(0.0)))) + } + }; } match func { AggFunc::Avg => { @@ -393,11 +398,10 @@ impl Program { else { unreachable!(); }; - let AggContext::Avg(acc, count) = agg.borrow_mut() else { + let AggContext::Sum(acc) = agg.borrow_mut() else { unreachable!(); }; *acc += col; - *count += 1; } }; state.pc += 1;