MCPcopy Create free account
hub / github.com/NodeDB-Lab/nodedb / extract_f64

Function extract_f64

nodedb-sql/src/planner/select/entry_ann.rs:248–267  ·  view source on GitHub ↗

Extract a float from a function argument expression.

(expr: &ast::Expr, option: &str)

Source from the content-addressed store, hash-verified

246
247/// Extract a float from a function argument expression.
248fn extract_f64(expr: &ast::Expr, option: &str) -> Result<f64> {
249 match expr {
250 ast::Expr::Value(v) => match &v.value {
251 ast::Value::Number(n, _) => n.parse::<f64>().map_err(|_| SqlError::Unsupported {
252 detail: format!("ANN option '{option}' expects a number, got: {n}"),
253 }),
254 _ => Err(SqlError::Unsupported {
255 detail: format!("ANN option '{option}' expects a number, got: {expr}"),
256 }),
257 },
258 // Handle negative floats: -0.5 parses as UnaryOp { Minus, 0.5 }
259 ast::Expr::UnaryOp {
260 op: ast::UnaryOperator::Minus,
261 expr: inner,
262 } => extract_f64(inner, option).map(|f| -f),
263 _ => Err(SqlError::Unsupported {
264 detail: format!("ANN option '{option}' expects a number, got: {expr}"),
265 }),
266 }
267}
268
269#[cfg(test)]
270mod tests {

Callers 1

parse_ann_optionsFunction · 0.70

Calls

no outgoing calls

Tested by

no test coverage detected