Parse named arguments of a vector distance function call into [`VectorAnnOptions`]. Positional args at positions 0 and 1 (field name and query vector) are ignored — this function only reads named args. Positional args at position ≥ 2 are rejected (old JSON-string form). Returns `VectorAnnOptions::default()` when no named options are present.
(func_args: &[ast::FunctionArg])
| 28 | /// |
| 29 | /// Returns `VectorAnnOptions::default()` when no named options are present. |
| 30 | pub fn parse_ann_options(func_args: &[ast::FunctionArg]) -> Result<VectorAnnOptions> { |
| 31 | let mut opts = VectorAnnOptions::default(); |
| 32 | let mut seen = [false; 6]; // indexed by option slot |
| 33 | |
| 34 | let mut positional_idx: usize = 0; |
| 35 | |
| 36 | for arg in func_args { |
| 37 | // Resolve the named arg to (key, value_expr, operator), or handle |
| 38 | // positional/unsupported forms. |
| 39 | let (key, value_expr, operator) = match arg { |
| 40 | ast::FunctionArg::Unnamed(_) => { |
| 41 | // First two positional args (field, query vector) are fine. |
| 42 | if positional_idx >= 2 { |
| 43 | return Err(SqlError::Unsupported { |
| 44 | detail: "vector_distance: JSON-string options are no longer supported. \ |
| 45 | Use named arguments instead: \ |
| 46 | vector_distance(field, query, quantization => 'rabitq', ef_search => 100, oversample => 3)" |
| 47 | .into(), |
| 48 | }); |
| 49 | } |
| 50 | positional_idx += 1; |
| 51 | continue; |
| 52 | } |
| 53 | |
| 54 | ast::FunctionArg::Named { |
| 55 | name, |
| 56 | arg, |
| 57 | operator, |
| 58 | } => { |
| 59 | let key = name.value.to_ascii_lowercase(); |
| 60 | let expr = match arg { |
| 61 | ast::FunctionArgExpr::Expr(e) => e, |
| 62 | _ => { |
| 63 | return Err(SqlError::Unsupported { |
| 64 | detail: format!("ANN option '{key}': expected a value expression"), |
| 65 | }); |
| 66 | } |
| 67 | }; |
| 68 | (key, expr, operator) |
| 69 | } |
| 70 | |
| 71 | // sqlparser may parse `ident => value` as ExprNamed when the name |
| 72 | // is an identifier expression. Accept simple identifier names. |
| 73 | ast::FunctionArg::ExprNamed { |
| 74 | name: ast::Expr::Identifier(ident), |
| 75 | arg, |
| 76 | operator, |
| 77 | } => { |
| 78 | let key = ident.value.to_ascii_lowercase(); |
| 79 | let expr = match arg { |
| 80 | ast::FunctionArgExpr::Expr(e) => e, |
| 81 | _ => { |
| 82 | return Err(SqlError::Unsupported { |
| 83 | detail: format!("ANN option '{key}': expected a value expression"), |
| 84 | }); |
| 85 | } |
| 86 | }; |
| 87 | (key, expr, operator) |
no test coverage detected