risingwavelabs/risingwave · error · SinkError

Cannot find '{KEY_FORMAT}',please set it.

Error message

Cannot find '{KEY_FORMAT}',please set it.

What it means

For `redis_value_type = 'stream'` sinks WITHOUT a primary key, after `value_format` the builder requires the `key_format` option (the template for the stream key). A missing `key_format` aborts the sink build with this SinkError::Config.

Source

Thrown at src/connector/src/sink/formatter/mod.rs:414

                            "`{STREAM}` and `{STREAM_COLUMN}` only one can be set"
                        )));
                    }
                    TemplateEncoder::new_pubsub_stream_key(
                        b.schema,
                        pk_indices,
                        stream,
                        stream_column,
                    )
                }
                None => {
                    let value_template =
                        b.format_desc.options.get(VALUE_FORMAT).ok_or_else(|| {
                            SinkError::Config(anyhow!(
                                "Cannot find '{VALUE_FORMAT}',please set it."
                            ))
                        })?;
                    let key_template = b.format_desc.options.get(KEY_FORMAT).ok_or_else(|| {
                        SinkError::Config(anyhow!("Cannot find '{KEY_FORMAT}',please set it."))
                    })?;

                    Ok(TemplateEncoder::new_stream_value(
                        b.schema,
                        pk_indices,
                        key_template.clone(),
                        value_template.clone(),
                    ))
                }
            },
            _ => Err(SinkError::Config(anyhow!(
                "The value type {} is not supported",
                redis_value_type
            ))),
        }
    }
}

View on GitHub (pinned to 6469eb736d)

Solutions

  1. Add `key_format = '<template>'` to the WITH options.
  2. Keep `value_format` set as well — both templates are required together in this branch.
  3. Ensure the stream target option (`stream` or `stream_column`) matches the table's primary key situation.

Example fix

// before
WITH (redis_value_type='stream', stream='events', value_format='{"v": %s}');
// after
WITH (redis_value_type='stream', stream='events', value_format='{"v": %s}', key_format='%s');
Defensive patterns

Strategy: validation

Validate before calling

if value_type == "stream" && !has_pk && !with_options.contains_key("key_format") {
    return Err("PK-less Redis stream sink requires `key_format`".into());
}

Try / catch

match result {
    Err(e) if e.to_string().contains("`key_format`") => {
        eprintln!("Add `key_format = '<template>'` to WITH options: {}", e);
    }
    other => other?,
}

Prevention

When it happens

Trigger: Creating a Redis stream sink without a primary key, providing `value_format` but not `key_format` in the WITH options.

Common situations: Users supply the value template only and overlook that stream sinks also need the key template, unlike `string` sinks without a primary key which need only `value_format`.

Understand the failure class

Background: "Must pass :limit option" / "Missing required option" — required option errors explained — this error's family across 41 libraries.

Related errors


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