mirror of
https://github.com/tursodatabase/limbo.git
synced 2025-12-23 08:21:09 +00:00
extensions: Improve error handling in percentile extension
Eliminate unwrap() where we can, replace with expect() where we can't.
This commit is contained in:
parent
96e63b4556
commit
eb07a5164b
1 changed files with 7 additions and 7 deletions
|
|
@ -25,7 +25,7 @@ impl AggFunc for Median {
|
|||
}
|
||||
|
||||
let mut sorted = state;
|
||||
sorted.sort_by(|a, b| a.partial_cmp(b).unwrap());
|
||||
sorted.sort_by(|a, b| a.total_cmp(b));
|
||||
|
||||
let len = sorted.len();
|
||||
if len % 2 == 1 {
|
||||
|
|
@ -82,8 +82,8 @@ impl AggFunc for Percentile {
|
|||
return Ok(Value::from_float(values[0]));
|
||||
}
|
||||
|
||||
let p = p_value.unwrap();
|
||||
values.sort_by(|a, b| a.partial_cmp(b).unwrap());
|
||||
let p = p_value.ok_or("percentile value must be provided")?;
|
||||
values.sort_by(|a, b| a.total_cmp(b));
|
||||
let n = values.len() as f64;
|
||||
let index = p * (n - 1.0) / 100.0;
|
||||
let lower = index.floor() as usize;
|
||||
|
|
@ -144,8 +144,8 @@ impl AggFunc for PercentileCont {
|
|||
return Ok(Value::from_float(values[0]));
|
||||
}
|
||||
|
||||
let p = p_value.unwrap();
|
||||
values.sort_by(|a, b| a.partial_cmp(b).unwrap());
|
||||
let p = p_value.ok_or("percentile value must be provided")?;
|
||||
values.sort_by(|a, b| a.total_cmp(b));
|
||||
let n = values.len() as f64;
|
||||
let index = p * (n - 1.0);
|
||||
let lower = index.floor() as usize;
|
||||
|
|
@ -184,8 +184,8 @@ impl AggFunc for PercentileDisc {
|
|||
return Err(err);
|
||||
}
|
||||
|
||||
let p = p_value.unwrap();
|
||||
values.sort_by(|a, b| a.partial_cmp(b).unwrap());
|
||||
let p = p_value.ok_or("percentile value must be provided")?;
|
||||
values.sort_by(|a, b| a.total_cmp(b));
|
||||
let n = values.len() as f64;
|
||||
let index = (p * (n - 1.0)).floor() as usize;
|
||||
Ok(Value::from_float(values[index]))
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue