mirror of
https://github.com/tursodatabase/limbo.git
synced 2025-12-23 08:21:09 +00:00
Fix avg(), total(), count() default value on empty set
This commit is contained in:
parent
79ba53f190
commit
e377e09498
1 changed files with 29 additions and 14 deletions
43
core/vdbe.rs
43
core/vdbe.rs
|
|
@ -594,23 +594,38 @@ impl Program {
|
|||
state.pc += 1;
|
||||
}
|
||||
Insn::AggFinal { register, func } => {
|
||||
match func {
|
||||
AggFunc::Avg => {
|
||||
let OwnedValue::Agg(agg) = state.registers[*register].borrow_mut()
|
||||
else {
|
||||
unreachable!();
|
||||
match state.registers[*register].borrow_mut() {
|
||||
OwnedValue::Agg(agg) => {
|
||||
match func {
|
||||
AggFunc::Avg => {
|
||||
let AggContext::Avg(acc, count) = agg.borrow_mut() else {
|
||||
unreachable!();
|
||||
};
|
||||
*acc /= count.clone();
|
||||
}
|
||||
AggFunc::Sum | AggFunc::Total => {}
|
||||
AggFunc::Count => {}
|
||||
AggFunc::Max => {}
|
||||
AggFunc::Min => {}
|
||||
_ => {
|
||||
todo!();
|
||||
}
|
||||
};
|
||||
let AggContext::Avg(acc, count) = agg.borrow_mut() else {
|
||||
unreachable!();
|
||||
};
|
||||
*acc /= count.clone();
|
||||
}
|
||||
AggFunc::Sum | AggFunc::Total => {}
|
||||
AggFunc::Count => {}
|
||||
AggFunc::Max => {}
|
||||
AggFunc::Min => {}
|
||||
OwnedValue::Null => {
|
||||
// when the set is empty
|
||||
match func {
|
||||
AggFunc::Total => {
|
||||
state.registers[*register] = OwnedValue::Float(0.0);
|
||||
}
|
||||
AggFunc::Count => {
|
||||
state.registers[*register] = OwnedValue::Integer(0);
|
||||
}
|
||||
_ => {}
|
||||
}
|
||||
}
|
||||
_ => {
|
||||
todo!();
|
||||
unreachable!();
|
||||
}
|
||||
};
|
||||
state.pc += 1;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue