(expr: &ast::Expr)
| 165 | } |
| 166 | |
| 167 | pub fn extract_float(expr: &ast::Expr) -> Result<f64> { |
| 168 | match expr { |
| 169 | ast::Expr::Value(v) => match &v.value { |
| 170 | ast::Value::Number(n, _) => n.parse::<f64>().map_err(|_| SqlError::TypeMismatch { |
| 171 | detail: format!("expected number: {n}"), |
| 172 | }), |
| 173 | _ => Err(SqlError::TypeMismatch { |
| 174 | detail: format!("expected number, got: {expr}"), |
| 175 | }), |
| 176 | }, |
| 177 | // Handle negative numbers: -73.9855 is parsed as UnaryOp { Minus, 73.9855 } |
| 178 | ast::Expr::UnaryOp { |
| 179 | op: ast::UnaryOperator::Minus, |
| 180 | expr: inner, |
| 181 | } => extract_float(inner).map(|f| -f), |
| 182 | _ => Err(SqlError::TypeMismatch { |
| 183 | detail: format!("expected number, got: {expr}"), |
| 184 | }), |
| 185 | } |
| 186 | } |
| 187 | |
| 188 | /// Map a vector distance function name to its `DistanceMetric`. |
| 189 | /// |
no outgoing calls
no test coverage detected