Skip to content

Commit

Permalink
core: fix initialization of sum vdbe
Browse files Browse the repository at this point in the history
Signed-off-by: Pere Diaz Bou <[email protected]>
  • Loading branch information
pereman2 committed Jul 1, 2024
1 parent 903998e commit 75d97b7
Showing 1 changed file with 10 additions and 6 deletions.
16 changes: 10 additions & 6 deletions core/vdbe.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 => {
Expand All @@ -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;
Expand Down

0 comments on commit 75d97b7

Please sign in to comment.