{"record":{"id":"b876bf5177a87595","repo":"risingwavelabs/risingwave","slug":"primary-key-column-index-out-of-range-in-sink-s","errorCode":null,"errorMessage":"primary key column index {} out of range in sink schema","messagePattern":"primary key column index (.+?) out of range in sink schema","errorType":"validation","errorClass":"SinkError::Config","httpStatus":null,"severity":"error","filePath":"src/connector/src/sink/iceberg/mod.rs","lineNumber":190,"sourceCode":"                let pk_indices = param\n                    .downstream_pk\n                    .as_ref()\n                    .filter(|pk| !pk.is_empty())\n                    .ok_or_else(|| {\n                        SinkError::Config(anyhow!(\n                            \"primary key must be specified for upsert iceberg sink\"\n                        ))\n                    })?;\n                Some(\n                    pk_indices\n                        .iter()\n                        .map(|&idx| {\n                            param\n                                .columns\n                                .get(idx)\n                                .map(|column| column.name.clone())\n                                .ok_or_else(|| {\n                                    SinkError::Config(anyhow!(\n                                        \"primary key column index {} out of range in sink schema\",\n                                        idx\n                                    ))\n                                })\n                        })\n                        .collect::<Result<Vec<_>>>()?,\n                )\n            } else {\n                None\n            };\n        Ok(Self {\n            config,\n            param,\n            upsert_primary_key_column_names,\n        })\n    }\n}\n","sourceCodeStart":172,"sourceCodeEnd":208,"githubUrl":"https://github.com/risingwavelabs/risingwave/blob/6469eb736d691e8e9b8a419a57edd6429ca77417/src/connector/src/sink/iceberg/mod.rs#L172-L208","documentation":"After obtaining upsert primary key indices, each index is resolved to a column name in the sink's column list. An index beyond the column vector's length fails with this error, indicating an internal mismatch between the declared PK and the sink schema.","triggerScenarios":"Sink construction where param.downstream_pk contains an index >= param.columns.len(), e.g. after schema changes to the source MV without recreating the sink, or a planner/connector bug.","commonSituations":"Altering/recreating upstream tables leaving stale sink definitions; rare internal bugs where downstream_pk was computed against a different schema.","solutions":["Drop and recreate the sink so the PK and schema are rebuilt consistently","Verify the upstream MV's primary key matches the sink's primary_key option","If reproducible on a fresh sink, file a bug with the DDL and schema"],"exampleFix":null,"handlingStrategy":"validation","validationCode":"for idx in pk_indices {\n    if *idx as usize >= columns.len() { return Err(format!(\"pk index {idx} out of range\")); }\n}","typeGuard":"fn pk_in_range(pk: &[usize], cols_len: usize) -> bool { pk.iter().all(|i| *i < cols_len) }","tryCatchPattern":"match result {\n    Err(e) if e.to_string().contains(\"out of range in sink schema\") => recreate_sink_with_current_schema()?,\n    other => other?,\n}","preventionTips":["Recreate sinks after upstream schema changes","Keep downstream_pk and sink columns generated from the same schema snapshot","Report reproducible index mismatches as bugs"],"tags":["iceberg","sink","primary-key","index-out-of-range"],"backgroundTag":"index-out-of-range","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"}