risingwavelabs/risingwave · error · SinkError::Config

primary key column index {} out of range in sink schema

Error message

primary key column index {} out of range in sink schema

What it means

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.

Source

Thrown at src/connector/src/sink/iceberg/mod.rs:190

                let pk_indices = param
                    .downstream_pk
                    .as_ref()
                    .filter(|pk| !pk.is_empty())
                    .ok_or_else(|| {
                        SinkError::Config(anyhow!(
                            "primary key must be specified for upsert iceberg sink"
                        ))
                    })?;
                Some(
                    pk_indices
                        .iter()
                        .map(|&idx| {
                            param
                                .columns
                                .get(idx)
                                .map(|column| column.name.clone())
                                .ok_or_else(|| {
                                    SinkError::Config(anyhow!(
                                        "primary key column index {} out of range in sink schema",
                                        idx
                                    ))
                                })
                        })
                        .collect::<Result<Vec<_>>>()?,
                )
            } else {
                None
            };
        Ok(Self {
            config,
            param,
            upsert_primary_key_column_names,
        })
    }
}

View on GitHub (pinned to 6469eb736d)

Solutions

  1. Drop and recreate the sink so the PK and schema are rebuilt consistently
  2. Verify the upstream MV's primary key matches the sink's primary_key option
  3. If reproducible on a fresh sink, file a bug with the DDL and schema
Defensive patterns

Strategy: validation

Validate before calling

for idx in pk_indices {
    if *idx as usize >= columns.len() { return Err(format!("pk index {idx} out of range")); }
}

Type guard

fn pk_in_range(pk: &[usize], cols_len: usize) -> bool { pk.iter().all(|i| *i < cols_len) }

Try / catch

match result {
    Err(e) if e.to_string().contains("out of range in sink schema") => recreate_sink_with_current_schema()?,
    other => other?,
}

Prevention

When it happens

Trigger: 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.

Common situations: Altering/recreating upstream tables leaving stale sink definitions; rare internal bugs where downstream_pk was computed against a different schema.

Related errors


AI-assisted analysis of risingwavelabs/risingwave@6469eb736d (2026-09-11). Data as JSON: /api/errors/b876bf5177a87595. Report an issue: GitHub.