mirror of
https://github.com/aljazceru/turso.git
synced 2025-12-30 14:34:22 +01:00
Fix avg(), total(), count() default value on empty set
This commit is contained in:
43
core/vdbe.rs
43
core/vdbe.rs
@@ -594,23 +594,38 @@ impl Program {
|
|||||||
state.pc += 1;
|
state.pc += 1;
|
||||||
}
|
}
|
||||||
Insn::AggFinal { register, func } => {
|
Insn::AggFinal { register, func } => {
|
||||||
match func {
|
match state.registers[*register].borrow_mut() {
|
||||||
AggFunc::Avg => {
|
OwnedValue::Agg(agg) => {
|
||||||
let OwnedValue::Agg(agg) = state.registers[*register].borrow_mut()
|
match func {
|
||||||
else {
|
AggFunc::Avg => {
|
||||||
unreachable!();
|
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 => {}
|
OwnedValue::Null => {
|
||||||
AggFunc::Count => {}
|
// when the set is empty
|
||||||
AggFunc::Max => {}
|
match func {
|
||||||
AggFunc::Min => {}
|
AggFunc::Total => {
|
||||||
|
state.registers[*register] = OwnedValue::Float(0.0);
|
||||||
|
}
|
||||||
|
AggFunc::Count => {
|
||||||
|
state.registers[*register] = OwnedValue::Integer(0);
|
||||||
|
}
|
||||||
|
_ => {}
|
||||||
|
}
|
||||||
|
}
|
||||||
_ => {
|
_ => {
|
||||||
todo!();
|
unreachable!();
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
state.pc += 1;
|
state.pc += 1;
|
||||||
|
|||||||
Reference in New Issue
Block a user