{"record":{"id":"286ea1193bdceb61","repo":"risingwavelabs/risingwave","slug":"time-parameter-cannot-be-negative-got","errorCode":null,"errorMessage":"time parameter cannot be negative, got {}","messagePattern":"time parameter cannot be negative, got (.+?)","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"src/frontend/src/optimizer/rule/table_function_to_internal_get_channel_delta_stats.rs","lineNumber":44,"sourceCode":"\n/// Helper function to extract a constant u64 value from an `ExprImpl`.\n/// Returns `Ok(Some(value))` if the expression can be folded to a constant u64,\n/// `Ok(None)` if the expression is null, or an error if folding fails.\n/// Negative values are rejected as they are not valid for time parameters.\nfn expr_impl_to_u64_fn(arg: &crate::expr::ExprImpl) -> anyhow::Result<Option<u64>> {\n    match arg\n        .clone()\n        .cast_implicit(&DataType::Int64)?\n        .try_fold_const()\n    {\n        Some(Ok(value)) => {\n            let Some(scalar) = value else {\n                return Ok(None);\n            };\n            match scalar {\n                ScalarImpl::Int64(value) => {\n                    if value < 0 {\n                        Err(anyhow::anyhow!(\n                            \"time parameter cannot be negative, got {}\",\n                            value\n                        ))\n                    } else {\n                        Ok(Some(value as u64))\n                    }\n                }\n                _ => Err(anyhow::anyhow!(\"expected int64, got {:?}\", scalar)),\n            }\n        }\n        Some(Err(err)) => Err(anyhow!(err).context(\"failed to fold constant\")),\n        None => Err(anyhow::anyhow!(\"expression must be a constant value\")),\n    }\n}\n\n/// Transform the `internal_get_channel_delta_stats()` table function\n/// into a plan graph which will return channel statistics from the dashboard API.\n/// It will return channel stats with `upstream_fragment_id` and `downstream_fragment_id` as primary key.","sourceCodeStart":26,"sourceCodeEnd":62,"githubUrl":"https://github.com/risingwavelabs/risingwave/blob/6469eb736d691e8e9b8a419a57edd6429ca77417/src/frontend/src/optimizer/rule/table_function_to_internal_get_channel_delta_stats.rs#L26-L62","documentation":"`expr_impl_to_u64_fn` converts a constant expression argument of `internal_get_channel_delta_stats` to u64. Int64 arguments are rejected if negative because a time parameter (at_time / time offset) cannot be negative.","triggerScenarios":"`build_plan` for `internal_get_channel_delta_stats(at_time, time_offset)` folds an argument to a constant Int64 whose value is < 0, e.g. `internal_get_channel_delta_stats(-100, 200)`.","commonSituations":"Passing negative relative offsets by mistake, or computing offsets with expressions that evaluate to negative values (clock skew calculations).","solutions":["Pass non-negative int64 values for both time arguments.","If a relative offset, use the absolute difference or clamp negatives to 0.","Wrap the argument expression so constant folding yields a non-negative value.","Check unit semantics (seconds vs millis) which may have led to the negative value."],"exampleFix":"-- before\nSELECT * FROM internal_get_channel_delta_stats(-60, 0);\n-- after\nSELECT * FROM internal_get_channel_delta_stats(60, 0);","handlingStrategy":"validation","validationCode":"-- Guard in SQL before calling\n-- Ensure args are >= 0: use GREATEST(0, x) or check in client code","typeGuard":"fn as_non_neg_i64(v: i64) -> Option<u64> {\n    if v < 0 { None } else { Some(v as u64) }\n}","tryCatchPattern":"match expr_impl_to_u64_fn(expr) {\n    Ok(v) => /* use v */,\n    Err(e) => eprintln!(\"time parameter rejected: {e:#}\"),\n}","preventionTips":["Clamp computed offsets with GREATEST(0, ...)","Validate offsets client-side before issuing queries","Double-check unit conversions that can produce negatives"],"tags":["rust","optimizer","arguments","validation"],"backgroundTag":"value-out-of-range","analyzedSha":"6469eb736d691e8e9b8a419a57edd6429ca77417","analyzedAt":"2026-09-11T21:06:21.487Z","contentChangedAt":"2026-09-11T21:06:21.487Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}