{"record":{"id":"c64a9f9ba0602b8a","repo":"risingwavelabs/risingwave","slug":"column-id-not-found-in-sink","errorCode":null,"errorMessage":"column id {} not found in sink","messagePattern":"column id (.+?) not found in sink","errorType":"error_code","errorClass":null,"httpStatus":null,"severity":"error","filePath":"src/meta/src/rpc/ddl_controller.rs","lineNumber":2542,"sourceCode":"            .iter()\n            .enumerate()\n            .map(|(idx, col)| {\n                let column_id = col.column_desc.as_ref().unwrap().column_id;\n                (column_id, idx as u32)\n            })\n            .collect::<HashMap<_, _>>();\n        target_table\n            .distribution_key\n            .iter()\n            .map(|dist_idx| {\n                let column_id = target_table.columns[*dist_idx as usize]\n                    .column_desc\n                    .as_ref()\n                    .unwrap()\n                    .column_id;\n                let sink_idx = sink_idx_by_col_id\n                    .get(&column_id)\n                    .ok_or_else(|| anyhow::anyhow!(\"column id {} not found in sink\", column_id))?;\n                Ok(*sink_idx)\n            })\n            .collect::<anyhow::Result<Vec<_>>>()?\n    };\n    let dist_key_indices =\n        dist_key_indices.map_err(|e| e.context(\"failed to get distribution key indices\"))?;\n    let downstream_fragment_id = target_fragment_id as _;\n    let new_downstream_relation = DownstreamFragmentRelation {\n        downstream_fragment_id,\n        dispatcher_type: DispatcherType::Hash,\n        dist_key_indices,\n        output_mapping: PbDispatchOutputMapping::simple(output_indices),\n    };\n    let current_target_columns = target_table.get_columns();\n    let project_exprs = build_select_node_list(&sink_columns, current_target_columns)?;\n    Ok(UpstreamSinkInfo {\n        sink_id,\n        sink_fragment_id: sink_fragment_id as _,","sourceCodeStart":2524,"sourceCodeEnd":2560,"githubUrl":"https://github.com/risingwavelabs/risingwave/blob/6469eb736d691e8e9b8a419a57edd6429ca77417/src/meta/src/rpc/ddl_controller.rs#L2524-L2560","documentation":"During sink distribution key planning, the meta node maps each requested distribution column (by column id) to its index among the sink's visible columns. This error is thrown when a column id present in the table's distribution key does not exist in the sink's column list, i.e. the sink schema and the table schema have diverged. It protects against building a sink whose downstream key columns reference nonexistent columns.","triggerScenarios":"CREATE SINK / ALTER operations where the sink's downstream column_desc lacks a column id that the source table's distribution key references; typically after schema changes (dropped/renamed columns) between table and sink, or a partially planned sink descriptor.","commonSituations":"Altering a table's distribution key or dropping a column while a sink depends on it; creating a sink with an explicit distribution key on a column filtered out of the sink; version-skew where an older sink schema is stored in meta while the table was migrated.","solutions":["Inspect the sink definition and ensure every distribution key column of the source table is included in the sink's columns (check the sink's SELECT/output list).","Recreate the sink so its schema is rebuilt from the current table schema: DROP SINK then CREATE SINK.","If a column was dropped/altered, update the table distribution key to reference existing columns before creating the sink.","If neither table nor sink was recently changed, check for meta-store schema corruption or a version upgrade mismatch and consult the RisingWave issue tracker."],"exampleFix":"// before: sink output omits the distribution column\nCREATE SINK s FROM t WITH (...) DISTRIBUTION KEY (id);\n-- table t distributed by (id, tenant_id), sink dropped tenant_id\n\n// after: include all distribution key columns in the sink\nCREATE SINK s AS SELECT id, tenant_id, v FROM t WITH (...) DISTRIBUTION KEY (id, tenant_id);","handlingStrategy":"validation","validationCode":"-- before CREATE SINK, ensure every table distribution column appears in the sink output\nSELECT c.name\nFROM rw_catalog.rw_tables t,\n     unnest(t.distribution_key) AS dk(col_id)\nJOIN rw_catalog.rw_columns c ON c.table_id = t.id AND c.column_id = dk.col_id\nWHERE t.name = 'my_table'\n  AND c.name NOT IN (/* sink output column list */);","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Keep the sink's output list a superset of the table's distribution key columns.","After ALTER TABLE ... SET DISTRIBUTED BY / DROP COLUMN, recreate dependent sinks.","Test sink DDL against a staging table with the same schema before production."],"tags":["sink","distribution-key","schema","ddl"],"backgroundTag":"schema-validation-failed","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"}