DUE TO SPAM, SIGN-UP IS DISABLED. Goto Selfserve wiki signup and request an account.
Motivation
Flink SQL and Table API jobs frequently need to evolve their input schemas as business requirements change. Today, even when the SQL logic is unchanged, a job can fail to restore from a savepoint after a backward-compatible schema change, because Flink's state migration mechanism does not support schema evolution for `RowData`. The `RowData` state serializer (`RowDataSerializer`) treats any change to its field types as incompatible, so the restore aborts with a `StateMigrationException`.
This blocks safe, backward-compatible changes such as:
- Adding nullable fields to an existing structure
- Reordering fields within a row while preserving field names
- Evolving nested `ROW` structures following the same rules
The impact is concrete: when an upstream source (a Kafka topic, a database CDC stream) evolves its schema by adding a nullable column — a change the source format itself considers backward-compatible — a Flink SQL job that consumes it can no longer restore its state. Users are forced either to freeze their input schema or to discard state and reprocess from scratch.
This FLIP proposes an opt-in, name-based, backward-compatible schema-evolution path for `RowData` state, so these jobs can restore from a savepoint and continue without losing state.
Primary Use Case: SQL Unchanged, Input Schema Evolves
The primary and safest scenario this FLIP targets is: The SQL/Table program is unchanged, and the input schema evolves in a backward-compatible way.
This is the common production case. When a source schema gains a new nullable column and the query does not reference it, Flink's planner prunes the unused column before it reaches any stateful operator — so most operator state is unaffected. Schema evolution becomes relevant specifically when the query references a `ROW`-typed column whose nested structure evolves, so that the evolved `ROW` is what an operator stores in state.
A secondary, riskier scenario — the SQL itself changes in a way that keeps the underlying state mapping valid — is supported only behind the opt-in configuration described below, because a SQL change can silently alter the internal layout of operator state (see Safety and Boundaries).
End-to-end connector example
The evolving `ROW` must actually be stored in state for migration to matter — if the query only reads a leaf field of a `ROW` (e.g. `metadata.userId`), the planner prunes the rest and the evolved fields never reach state. A streaming join is a clear case where whole rows, including a nested `ROW` column, are buffered in operator state. Consider a Kafka fact stream joined with a database-CDC dimension whose row carries a nested `profile` `ROW`:
CREATE TABLE Clicks (
clickId BIGINT,
userId INT
) WITH ('connector' = 'kafka', ...);
CREATE TABLE Users (
userId INT,
profile ROW<name STRING, country STRING>
) WITH ('connector' = 'mysql-cdc', ...);
-- Output carries the whole profile ROW, so the join buffers it in state.
SELECT c.clickId, u.profile
FROM Clicks c JOIN Users u ON c.userId = u.userId;
The regular (non-lookup) join keeps the `Users` rows — including the `profile ROW` — in keyed join state so it can emit updates. The CDC source's table then gains a nullable column, evolving the dimension to `profile ROW<name STRING, country STRING, city STRING>`. The Flink SQL is unchanged.
Today, restoring this job from a savepoint fails: the join state's `RowData` serializer for the `Users` side no longer matches the snapshot, because the nested `profile` `ROW` changed. With this FLIP (and `table.exec.state.schema-evolution.enabled = true`), migration maps the existing nested fields by name (`name`, `country`), initializes the new `city` field to null in the buffered rows, and the job resumes without rebuilding the dimension state. The same shape applies to a Kafka source whose Avro schema adds a nullable field to a `ROW` column that is buffered downstream (for example by a deduplication or a join), as long as the SQL keeps storing that `ROW`.
Problem Example
Assume a stateful query that buffers the whole `metadata ROW` in state — for example a streaming join that outputs it, or a deduplication that keeps the latest row per key — so that a change to the `ROW` actually changes the state serializer.
Initial schema
CREATE TABLE Events ( eventId BIGINT, metadata ROW< userId INT, eventTs BIGINT, deviceType STRING > ) WITH (...);
Evolved schema (supported)
CREATE TABLE Events ( eventId BIGINT, metadata ROW< deviceType STRING, -- reordered (name preserved) region STRING, -- new nullable field userId INT, -- original field eventTs BIGINT, -- original field appVersion STRING, -- new nullable field sessionId BIGINT -- new nullable field > ) WITH (...);
Current behavior
When the job is restored with the evolved schema, it fails:
Caused by: org.apache.flink.util.StateMigrationException: The new state serializer (...) must not be incompatible with the old state serializer (...).
This FLIP introduces backward-compatible schema evolution for `RowData` so the job can restore from the savepoint when the change is safe.
Unsupported schema changes (rejected at restore time)
These differences are genuinely incompatible and are rejected during restore with a clear error:
- Removing fields — a previously stored field has no destination.
- Renaming fields — name-based mapping cannot correlate old and new fields.
- Changing field types (e.g. `BIGINT` → `TIMESTAMP`) — values cannot be reinterpreted.
Removing a field:
CREATE TABLE Events ( eventId BIGINT, metadata ROW< deviceType STRING, eventTs BIGINT -- userId field removed > ) WITH (...);
Changing a field type:
CREATE TABLE Events ( eventId BIGINT, metadata ROW< userId INT, eventTs TIMESTAMP(3), -- Changed from BIGINT to TIMESTAMP deviceType STRING > ) WITH (...);
A different, non-rejected risk — a SQL change that silently moves operator-internal state buffers (e.g. inserting `SUM(d)` before `SUM(c)`) — is what the opt-in guards against; see Safety and Boundaries.
Safety and Boundaries
Name-based mapping is safe for the primary use case but must be bounded:
- `RowData` used as a map-state key is out of scope. Some operators (for example, joins on an input side with no unique key) use the entire record as a map-state key. The state backend migrates map values, never keys, so key-schema changes remain incompatible regardless of this FLIP. In the SQL-unchanged case this is naturally safe because column pruning keeps the key schema stable.
- SQL changes can move internal state buffers. For example, changing `SELECT a, b, SUM(c) ...` to `SELECT a, b, SUM(d), SUM(c) ...` shifts the accumulator for `SUM(c)` from the first aggregate buffer to the second. Field names at the operator-internal level may appear to match while the data they hold has moved. This is exactly why the feature is opt-in: the user must confirm that their change preserves state mapping before enabling it.
- Accumulator state is independent of input schema. Aggregate accumulators are typed by the aggregation functions, not by the input row. When the SQL is unchanged, accumulator schemas do not change even as the input schema evolves.
- RowData nested below a composite serializer is out of scope. When RowData sits below a List or Tuple serializer in operator state (for example interval- and outer-join buffers), migration is not propagated into the nested RowData, so such state is treated as incompatible and rejected on restore. This fails closed and never mis-migrates; propagating migration through composite serializers is a planned follow-up.
Summary
This FLIP introduces opt-in, backward-compatible schema-migration support for `RowData` state.
Schema migration works for:
- Adding new nullable fields (initialized to null for existing records)
- Reordering existing fields (mapped by field name)
- Evolving nested `ROW` types following the same rules
Schema migration does not work for:
- Removing fields
- Renaming fields (name-based mapping fails)
- Changing field types (e.g. `BIGINT` → `TIMESTAMP`)
- `RowData` used as a state key
- SQL changes that alter operator state layout
Unsupported changes trigger restore-time validation errors.
Public Interfaces
New configuration option
A new Table configuration option gates the feature:
- Key: `table.exec.state.schema-evolution.enabled`
- Type: `Boolean`
- Default: `false`
The key is scoped under `table.exec.state.*` to make clear that it currently applies to the Table/`RowData` layer, leaving room for other state types to add their own opt-ins later. It is disabled by default for safety; users enable it only after confirming their change preserves state mapping.
How the option takes effect. A `TypeSerializerSnapshot` cannot read job configuration at restore time, so the option is consumed where the configuration is available — when the Table runtime constructs the `RowData` state serializer at restore. The serializer records the option as an in-memory flag that reflects the current job's configuration; this flag is not persisted. The compatibility and migration logic reads this flag — not the presence of field names — to decide whether a backward-compatible field-type difference is migrated (`compatibleAfterMigration()`) or rejected (`incompatible()`, today's behavior). Field names are persisted unconditionally, independent of the option, so the option gates whether migration is permitted rather than whether names are available. This keeps the opt-in a table-layer concern and avoids plumbing configuration into the serialization layer.
The schema-evolution flag is applied uniformly to the RowData state serializers the Table runtime builds, without distinguishing key serializers from value serializers. The "RowData as a state key is out of scope" boundary is enforced by the state backend, which rejects key-schema changes on restore, rather than by excluding keys from naming, so a key is never migrated.
`TypeSerializerSnapshot` enhancements
A single default method is added to `TypeSerializerSnapshot<T>`. Consistent with the `resolveSchemaCompatibility(TypeSerializerSnapshot<T> oldSerializerSnapshot)` direction (FLIP-263), it is invoked on the new snapshot and receives the old snapshot. It operates on the already-deserialized value object and returns the migrated value; the default returns the value unchanged, so the change is fully backward compatible — only serializers that need structural migration (i.e. RowData) override it. Because the hook works on the object rather than on raw bytes, the same method covers value, list-element, and map-value migration uniformly, so no separate per-element hook is needed.
public interface TypeSerializerSnapshot<T> {
// ... existing methods ...
/**
* Migrates a value written by a prior, compatible serializer into the value this serializer expects. The default returns the value unchanged; only serializers that need structural migration (e.g. RowData) override it.
*/
default T migrate(TypeSerializerSnapshot<T> oldSerializerSnapshot, T value) {
return value;
}
}
Because the hook works on the deserialized object, list state (whose elements are stored individually) and map state (whose values are stored per entry) are migrated by applying the same migrate method to each element or value as it is read — there is no separate element hook.
`RowDataSerializer` enhancements
- Add `String[] fieldNames` to `RowDataSerializer` to carry the top-level field names for name-based mapping — a lightweight alternative to storing the full `RowType`. Nested-row field names are recovered from the nested logical types, so only the top-level names are persisted. The field is `null` only for snapshots written before field names were persisted, in which case migration falls back to position-based mapping.
- Extend the snapshot format to persist the field names alongside the existing field-types section, written unconditionally (independent of the schema-evolution option). Readers of the new format remain able to read older snapshots that lack names (field names absent → `null`).
- Override `resolveSchemaCompatibility` and `migrate` in `RowDataSerializerSnapshot` to support adding nullable fields, reordering by name, and nested-ROW evolution following the same rules.
Proposed Changes
Compatibility check
`RowDataSerializer.resolveSchemaCompatibility` is extended so that, when the field types differ but the difference is a supported backward-compatible change and the serializer's schema-evolution flag is set (see How the option takes effect), it returns `TypeSerializerSchemaCompatibility.compatibleAfterMigration()` instead of `incompatible()`. When the flag is not set, the current `incompatible()` behavior is preserved unchanged. Returning `compatibleAfterMigration()` is what drives the state backend to invoke the migration path during restore.
The supported-change check (name-based) is:
- Every old field must still exist in the new schema (by name) with the same type — otherwise the change is a removal or a type change, which is rejected.
- Every field present only in the new schema must be nullable — new fields are initialized to null for existing records.
- Nested `ROW` fields are checked recursively under the same rules.
Migration
`RowDataSerializerSnapshot` overrides `migrate` to remap the deserialized value by name rather than returning it unchanged. Given the value deserialized with the old serializer, it:
- Builds a `newPos → oldPos` field mapping by name (position-based fallback when a side lacks field names).
- Copies existing fields into a `GenericRowData` of the new arity, preserving `RowKind`; initializes added fields to null; recurses into nested `ROW` fields.
- Returns the remapped row, which the caller serializes with the new serializer.
The surrounding deserialize/serialize is performed by the migration caller, so the hook itself is a pure value-to-value transform.
State backend integration
On restore, when the compatibility check reports a value is compatible after migration, the state backend drives migration through its existing value-migration path, into which the RowData migrate hook plugs. Migration composes with the state-TTL layer in a single pass — the TTL timestamp is preserved and the underlying RowData is remapped — so enabling TTL does not bypass evolution. Dispatch is polymorphic, so the runtime state layer needs no dependency on the Table module and no existing backend state classes change. Map keys are never migrated (key-schema changes remain incompatible; see Safety and Boundaries).
The schema-evolution flag reaches the serializer through the opt-in: the Table runtime sets it on the `RowData` serializer for top-level `ROW`-typed state when the feature is enabled, and leaves it unset otherwise (behaving exactly as today). Coverage follows one rule — a `RowData` value can evolve only when its serializer is a top-level `ROW`, so the compatibility check runs against a serializer that carries the flag. Where `RowData` is nested below a composite serializer (List or Tuple), as in interval and outer joins, or where an operator pre-builds its state serializer, the `RowData` serializer does not carry the schema-evolution flag and fails closed: an evolving schema is rejected on restore, never silently mis-migrated. Extending coverage to those paths — including migration propagation through composite serializers — is a follow-up.
RocksDB is the initial target backend. The ForSt sync backend shares the same migration path and can be supported as a follow-up; ForSt's async (v2) state API does not support state migration, so it is out of scope.
Documentation
User-facing documentation is part of this change: which schema changes are supported versus rejected, the `table.exec.state.schema-evolution.enabled` option (whose description is also surfaced automatically in the generated configuration tables), the savepoint → evolve-schema → restore workflow, and worked examples of supported and unsupported changes.
User Workflow
- Set `table.exec.state.schema-evolution.enabled = true` in the job configuration.
- Take a savepoint of the running job.
- Update the job with the new input schema, limited to supported changes.
- Restore from the savepoint — Flink migrates the state automatically when the change is safe, and rejects it with a clear error otherwise.
Compatibility, Deprecation, and Migration Plan
- The change is backward compatible and does not alter existing behavior. The new `TypeSerializerSnapshot` method is a default method whose default returns the value unchanged, so existing serializers behave exactly as today.
- Jobs that do not enable the configuration are entirely unaffected; the default is `false`.
- Snapshot format: the format is extended, backward-compatibly, to persist field names. Readers of the new format read older snapshots that lack names (position-based fallback), so existing savepoints continue to restore.
- Only backward-compatible schema changes are supported (adding nullable fields, reordering with preserved names, nested-`ROW` changes under the same rules). All other changes fail safely with a clear error message.
- Migration is a one-time, restore-time operation: the first restore after the schema change reads and rewrites the affected `RowData` state, so that restore is slower in proportion to the migrated state size. Subsequent checkpoints and restores are unaffected.
Test Plan
- Unit tests over schema-evolution scenarios: adding nullable fields at different positions, reordering, nested-`ROW` evolution, and combinations; plus rejection of removals, renames, and type changes.
- Snapshot compatibility tests: restoring an older, name-less snapshot with a new serializer (position-based fallback) and a new-format, named snapshot (name-based).
- Schema evolution with state TTL enabled: verify the TTL wrapper is preserved through migration — the value's timestamp survives and the inner `RowData` is remapped — for value and map-value state.
- Integration tests with savepoint/restore on the RocksDB backend, verifying that compatible changes succeed and incompatible changes are rejected.
Rejected Alternatives
- A separate `SchemaEvolutionRowDataSerializer`. Users would have to opt into a distinct serializer instead of getting automatic support, it would introduce divergent code paths and maintenance overhead, and it would not integrate cleanly with Flink's existing serialization framework. Enhancing the existing serializer keeps the experience seamless and preserves backward compatibility.
- Returning a migration serializer from `TypeSerializerSchemaCompatibility`. An alternative is to express migration as a serializer carried on the compatibility result (e.g. `compatibleAfterMigration(TypeSerializer<T>)`), paralleling how `compatibleWithReconfiguredSerializer` already carries a reconfigured serializer. The difference is one of role: a reconfigured serializer is used directly for all subsequent reads and writes, whereas a migration here must transform old serialized bytes into the new layout (insert nulls for added fields, reorder by name) — a distinct, migration-only role. Introducing that as a new serializer kind means a new concept plus rewiring the existing `migrateSerializedValue` / `TtlAwareSerializer` migration path to drive it. A default method on `TypeSerializerSnapshot` keeps migration co-located with the snapshot-based compatibility logic and adds no surface for the many serializers that don't need it — their inherited default reproduces today's behavior exactly, which also answers the concern that a common interface shouldn't gain methods most implementations won't use.
- Relying solely on `resolveSchemaCompatibility` with no new methods. The standard migration path performs deserialize-old / serialize-new. `RowData`'s in-memory representation is schema-coupled (a fixed-width layout sized to the exact field count), so deserializing N fields and re-serializing into an M-field schema cannot insert nulls for added fields or reorder by name without an explicit transformation step. The `migrate` hook provides that step while leaving the default behavior unchanged for every other type.