Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,32 @@ void readSnapshot(int readVersion, DataInputView in, ClassLoader userCodeClassLo
TypeSerializerSchemaCompatibility<T> resolveSchemaCompatibility(
TypeSerializerSnapshot<T> oldSerializerSnapshot);

/**
* Migrates a single state value from the schema described by {@code oldSerializerSnapshot} to
* the schema described by this (new) snapshot. Like {@link
* #resolveSchemaCompatibility(TypeSerializerSnapshot)}, this is invoked on the new snapshot and
* receives the old snapshot as its argument.
*
* <p>The default implementation returns the value unchanged: a value already deserialized with
* the prior serializer is structurally compatible with the current serializer, so the caller
* can re-serialize it as-is. A serializer whose in-memory representation is coupled to its
* schema should override this to transform the value into the new layout -- for example by
* inserting nulls for added fields or reordering fields by name. An implementation may return
* the given value or a new instance.
*
* <p>The migration is not applied recursively to nested serializers. The snapshot of a
* composite type returns its value unchanged unless it overrides this method to decompose the
* value and migrate each part, so a caller that needs a nested value migrated must reach the
* nested snapshot itself.
*
* @param oldSerializerSnapshot snapshot of the serializer that wrote the value.
* @param value the value, already deserialized with the prior serializer.
* @return the value adapted to the schema of the current serializer.
*/
default T migrate(TypeSerializerSnapshot<T> oldSerializerSnapshot, T value) {
return value;
}

// ------------------------------------------------------------------------
// read / write utilities
// ------------------------------------------------------------------------
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,15 @@ public TypeSerializerSchemaCompatibility<Integer> resolveSchemaCompatibility(
.isTrue();
}

@Test
void testMigrateReturnsValueUnchangedByDefault() {
TypeSerializerSnapshot<Integer> oldSnapshot = new NotCompletedTypeSerializerSnapshot();
TypeSerializerSnapshot<Integer> newSnapshot = new NotCompletedTypeSerializerSnapshot();
Integer value = 1000;

assertThat(newSnapshot.migrate(oldSnapshot, value)).isSameAs(value);
}

private static class NotCompletedTypeSerializer extends TypeSerializer<Integer> {

@Override
Expand Down