Extract the bucket interval from a time_bucket() call. Handles both argument orders: - `time_bucket('1 hour', timestamp)` — interval first - `time_bucket(timestamp, '1 hour')` — timestamp first - `time_bucket(3600, timestamp)` — integer seconds
(func: &ast::Function)
| 218 | /// - `time_bucket(timestamp, '1 hour')` — timestamp first |
| 219 | /// - `time_bucket(3600, timestamp)` — integer seconds |
| 220 | fn extract_bucket_interval(func: &ast::Function) -> Result<i64> { |
| 221 | let args = match &func.args { |
| 222 | ast::FunctionArguments::List(args) => &args.args, |
| 223 | _ => return Ok(0), |
| 224 | }; |
| 225 | // Try each argument position for the interval literal. |
| 226 | for arg in args { |
| 227 | if let ast::FunctionArg::Unnamed(ast::FunctionArgExpr::Expr(ast::Expr::Value(v))) = arg { |
| 228 | match &v.value { |
| 229 | ast::Value::SingleQuotedString(s) => { |
| 230 | let ms = parse_interval_to_ms(s); |
| 231 | if ms > 0 { |
| 232 | return Ok(ms); |
| 233 | } |
| 234 | } |
| 235 | ast::Value::Number(n, _) => { |
| 236 | if let Ok(secs) = n.parse::<i64>() |
| 237 | && secs > 0 |
| 238 | { |
| 239 | return Ok(secs * 1000); |
| 240 | } |
| 241 | } |
| 242 | _ => {} |
| 243 | } |
| 244 | } |
| 245 | } |
| 246 | Ok(0) |
| 247 | } |
| 248 | |
| 249 | /// Parse an interval string to milliseconds. |
| 250 | /// |
no test coverage detected