{"record":{"id":"64925d8bec502778","repo":"risingwavelabs/risingwave","slug":"failed-to-parse-source-definition-sql","errorCode":null,"errorMessage":"Failed to parse source definition SQL","messagePattern":"Failed to parse source definition SQL","errorType":"exception","errorClass":"ConnectorError","httpStatus":null,"severity":"error","filePath":"src/meta/src/controller/streaming_job.rs","lineNumber":2941,"sourceCode":"            options_with_secret\n        );\n        // check if the alter-ed props are valid for each Connector\n        let _ = ConnectorProperties::extract(options_with_secret.clone(), true)?;\n        // todo: validate via source manager\n\n        let mut associate_table_id = None;\n\n        // can be source_id or table_id\n        // if updating an associated source, the preferred_id is the table_id\n        // otherwise, it is the source_id\n        let mut preferred_id = source_id.as_object_id();\n        let rewrite_sql = {\n            let definition = source.definition.clone();\n\n            let [mut stmt]: [_; 1] = Parser::parse_sql(&definition)\n                .map_err(|e| {\n                    MetaError::from(MetaErrorInner::Connector(ConnectorError::from(\n                        anyhow!(e).context(\"Failed to parse source definition SQL\"),\n                    )))\n                })?\n                .try_into()\n                .unwrap();\n\n            /// Formats SQL options with secret values properly resolved\n            ///\n            /// This function processes configuration options that may contain sensitive data:\n            /// - Plaintext options are directly converted to `SqlOption`\n            /// - Secret options are retrieved from the database and formatted as \"SECRET {name}\"\n            ///   without exposing the actual secret value\n            ///\n            /// # Arguments\n            /// * `txn` - Database transaction for retrieving secrets\n            /// * `options_with_secret` - Container of options with both plaintext and secret values\n            ///\n            /// # Returns\n            /// * `MetaResult<Vec<SqlOption>>` - List of formatted SQL options or error","sourceCodeStart":2923,"sourceCodeEnd":2959,"githubUrl":"https://github.com/risingwavelabs/risingwave/blob/6469eb736d691e8e9b8a419a57edd6429ca77417/src/meta/src/controller/streaming_job.rs#L2923-L2959","documentation":"During `ALTER SOURCE ... ALTER_CONNECTOR_PROPS`, the meta node re-parses the source's stored definition SQL (src/meta/src/controller/streaming_job.rs:2938-2945) so it can rewrite the WITH options. If `Parser::parse_sql` fails on that stored definition, the parse error is wrapped with context 'Failed to parse source definition SQL' and returned as a Connector MetaError. This means the catalog contains a definition string that is no longer valid SQL (corruption, manual DB edit, or an upgrade that changed the SQL dialect/parser).","triggerScenarios":"Calling ALTER SOURCE / alter_connector_props on a source whose `definition` column fails to parse into exactly one SQL statement (zero or multiple statements, or syntax the parser rejects).","commonSituations":"Definitions hand-edited directly in the meta catalog database; definitions stored by an older RisingWave version whose syntax the current parser no longer accepts; truncated/corrupted catalog rows after a failed migration or restore.","solutions":["Run `SHOW SOURCE <name>` / `SELECT definition FROM ...` and inspect the stored definition for syntax problems.","Recreate the source: DROP SOURCE and CREATE SOURCE with fresh, valid SQL, then re-apply the ALTER.","Check whether the definition was hand-modified in the metadata DB and restore it to the statement originally issued by CREATE SOURCE.","If a version upgrade introduced the incompatibility, upgrade/roll back consistently or re-create affected sources."],"exampleFix":"-- before: ALTER SOURCE src ALTER_CONNECTOR_PROPS ... fails because catalog definition is corrupt\n-- after\nDROP SOURCE src;\nCREATE SOURCE src (...) WITH (connector = 'kafka', ...);\nALTER SOURCE src ALTER_CONNECTOR_PROPS (properties.add = 'x');","handlingStrategy":"try-catch","validationCode":"-- before altering, verify the stored definition parses\nSHOW SOURCE my_source; -- confirm the definition is a valid single CREATE SOURCE statement","typeGuard":null,"tryCatchPattern":"match client.alter_source_connector_props(...).await {\n    Err(e) if e.to_string().contains(\"Failed to parse source definition SQL\") => {\n        // recover by dropping and recreating the source\n    }\n    other => other?,\n}","preventionTips":["Never hand-edit catalog definition columns in the meta database.","Recreate sources after failed migrations or restores that may corrupt definitions.","Upgrade meta and frontend components together so the parser matches stored syntax."],"tags":["sql","meta","source","catalog"],"backgroundTag":"sql-query-failed","analyzedSha":"6469eb736d691e8e9b8a419a57edd6429ca77417","analyzedAt":"2026-09-11T21:06:21.487Z","contentChangedAt":"2026-09-11T21:06:21.487Z","schemaVersion":2},"datasetVersion":"2026-09-14T11:17:12.474Z"}