{"record":{"id":"f401550b261d3dcf","repo":"risingwavelabs/risingwave","slug":"should-contains-only-one-statement","errorCode":null,"errorMessage":"should contains only one statement","messagePattern":"should contains only one statement","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"critical","filePath":"src/meta/src/controller/rename.rs","lineNumber":40,"sourceCode":"    FunctionArgList, Ident, ObjectName, Query, SelectItem, SetExpr, Statement, TableAlias,\n    TableFactor, TableWithJoins, Window,\n};\nuse risingwave_sqlparser::parser::Parser;\n\n/// `alter_relation_rename` renames a relation to a new name in its `Create` statement, and returns\n/// the updated definition raw sql. Note that the `definition` must be a `Create` statement and the\n/// `new_name` must be a valid identifier, it should be validated before calling this function. To\n/// update all relations that depend on the renamed one, use `alter_relation_rename_refs`.\npub fn alter_relation_rename(definition: &str, new_name: &str) -> String {\n    // This happens when we try to rename a table that's created by `CREATE TABLE AS`. Remove it\n    // when we support `SHOW CREATE TABLE` for `CREATE TABLE AS`.\n    if definition.is_empty() {\n        tracing::warn!(\"found empty definition when renaming relation, ignored.\");\n        return definition.into();\n    }\n    let ast = Parser::parse_sql(definition).expect(\"failed to parse relation definition\");\n    let mut stmt =\n        Itertools::exactly_one(ast.into_iter()).expect(\"should contains only one statement\");\n\n    match &mut stmt {\n        Statement::CreateTable { name, .. }\n        | Statement::CreateView { name, .. }\n        | Statement::CreateIndex { name, .. }\n        | Statement::CreateSource {\n            stmt: CreateSourceStatement {\n                source_name: name, ..\n            },\n        }\n        | Statement::CreateSubscription {\n            stmt:\n                CreateSubscriptionStatement {\n                    subscription_name: name,\n                    ..\n                },\n        }\n        | Statement::CreateSink {","sourceCodeStart":22,"sourceCodeEnd":58,"githubUrl":"https://github.com/risingwavelabs/risingwave/blob/6469eb736d691e8e9b8a419a57edd6429ca77417/src/meta/src/controller/rename.rs#L22-L58","documentation":"After successfully parsing the relation definition, alter_relation_rename asserts exactly one statement via Itertools::exactly_one().expect(\"should contains only one statement\"). Stored definitions are expected to be a single CREATE statement; multiple statements indicate corrupt or malformed stored state.","triggerScenarios":"alter_relation_rename when the stored definition parses into 0 or 2+ SQL statements (e.g. concatenated statements, semicolon-terminated extra text in the definition column).","commonSituations":"Manual meta store tampering, buggy definition serialization from an older version, pasting multi-statement SQL into a definition.","solutions":["Inspect the stored definition; ensure it is a single CREATE TABLE/VIEW/INDEX/SOURCE statement.","Normalize the definition to one statement, or drop/recreate the relation.","If produced by tooling, fix the tool to write a single statement."],"exampleFix":null,"handlingStrategy":"validation","validationCode":"let n = Parser::parse_sql(definition).map_err(|e| anyhow!(e))?.len();\nif n != 1 { bail!(\"expected exactly one statement, got {}\", n); }","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Store only single-statement CREATE definitions","Validate definitions at write time","Run catalog integrity checks before ALTER RENAME","Avoid custom tooling that concatenates statements into definitions"],"tags":["panic","sql-parser","meta","rename"],"backgroundTag":"unexpected-response-shape","analyzedSha":"6469eb736d691e8e9b8a419a57edd6429ca77417","analyzedAt":"2026-09-11T21:06:21.487Z","contentChangedAt":"2026-09-11T21:06:21.487Z","schemaVersion":2},"datasetVersion":"2026-09-14T16:17:12.679Z"}