{"record":{"id":"0a443b1605e153db","repo":"risingwavelabs/risingwave","slug":"expression-must-be-a-constant-value","errorCode":null,"errorMessage":"expression must be a constant value","messagePattern":"expression must be a constant value","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"src/frontend/src/optimizer/rule/table_function_to_internal_get_channel_delta_stats.rs","lineNumber":56,"sourceCode":"            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.\npub struct TableFunctionToInternalGetChannelDeltaStatsRule {}\nimpl FallibleRule<Logical> for TableFunctionToInternalGetChannelDeltaStatsRule {\n    fn apply(&self, plan: PlanRef) -> ApplyResult<PlanRef> {\n        let logical_table_function: &LogicalTableFunction = plan.as_logical_table_function()?;\n        if logical_table_function.table_function().function_type\n            != TableFunctionType::InternalGetChannelDeltaStats\n        {\n            return ApplyResult::NotApplicable;\n        }\n        let plan = Self::build_plan(plan.ctx(), logical_table_function.table_function())?;\n        ApplyResult::Ok(plan)\n    }","sourceCodeStart":38,"sourceCodeEnd":74,"githubUrl":"https://github.com/risingwavelabs/risingwave/blob/6469eb736d691e8e9b8a419a57edd6429ca77417/src/frontend/src/optimizer/rule/table_function_to_internal_get_channel_delta_stats.rs#L38-L74","documentation":"`expr_impl_to_u64_fn` requires each argument's constant-folded value to exist. When the fold yields `None` (expression is not constant), the function errors with `expression must be a constant value` because time parameters must be known at plan time.","triggerScenarios":"Calling `internal_get_channel_delta_stats` with arguments that depend on columns, parameters, or non-constant expressions, e.g. `internal_get_channel_delta_stats(some_col, 0)`.","commonSituations":"Attempting to parameterize the dashboard stats function with runtime values, or using session variables/non-deterministic expressions as arguments.","solutions":["Inline literal int64 constants for both arguments.","Precompute the value in the client and pass it as a literal.","Remove column references or subqueries from the arguments.","Use a supported API (dashboard service) if runtime-parameterized stats are needed."],"exampleFix":"-- before\nSELECT * FROM internal_get_channel_delta_stats(my_offset_col, 0);\n-- after\nSELECT * FROM internal_get_channel_delta_stats(3600, 0);","handlingStrategy":"validation","validationCode":"-- Arguments must be literals\nSELECT * FROM internal_get_channel_delta_stats(3600, 0);","typeGuard":null,"tryCatchPattern":"match expr_impl_to_u64_fn(expr) {\n    Ok(v) => /* proceed */,\n    Err(e) => eprintln!(\"arguments must be constants: {e:#}\"),\n}","preventionTips":["Never reference columns, parameters, or session variables in arguments","Compute values in the client and inline them","Remember these are plan-time constants, not runtime parameters"],"tags":["rust","optimizer","constant-folding"],"backgroundTag":"invalid-argument-value","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"}