pvary commented on code in PR #14880:
URL: https://github.com/apache/iceberg/pull/14880#discussion_r2634138239
##########
flink/v2.1/flink/src/main/java/org/apache/iceberg/flink/sink/dynamic/DynamicRecordInternalSerializer.java:
##########
@@ -274,22 +306,59 @@ public void writeSnapshot(DataOutputView out) throws
IOException {
@Override
public void readSnapshot(int readVersion, DataInputView in, ClassLoader
userCodeClassLoader)
throws IOException {
+ this.version = readVersion;
this.writeSchemaAndSpec = in.readBoolean();
}
@Override
public TypeSerializerSchemaCompatibility<DynamicRecordInternal>
resolveSchemaCompatibility(
TypeSerializerSnapshot<DynamicRecordInternal> oldSerializerSnapshot) {
- return TypeSerializerSchemaCompatibility.compatibleAsIs();
+ if (oldSerializerSnapshot.getCurrentVersion() == getCurrentVersion()) {
+ return TypeSerializerSchemaCompatibility.compatibleAsIs();
+ }
+ // Old TypeSerializerSnapshots do not contain the serializer cache, but
the newest one does.
+ // This will also ensure that we always use the up-to-date cache
alongside with its catalog
+ // configuration.
+ Preconditions.checkNotNull(serializerCache, "serializerCache should not
be null");
+ try {
+ DynMethods.builder("initializeSerializerCache")
+ .hiddenImpl(
+ DynamicRecordInternalTypeSerializerSnapshot.class,
TableSerializerCache.class)
+ .build()
+ .invoke(oldSerializerSnapshot, serializerCache);
+ } catch (Exception e) {
+ throw new RuntimeException(
+ "Failed to initialize serializerCache for reading data with old
serializer", e);
+ }
+ // This will first read data with the old serializer, then switch to the
most recent one.
+ return TypeSerializerSchemaCompatibility.compatibleAfterMigration();
}
@Override
public TypeSerializer<DynamicRecordInternal> restoreSerializer() {
- // Note: We pass in a null serializer cache which would create issues if
we tried to use this
- // restored serializer, but since we are using {@code
- // TypeSerializerSchemaCompatibility.compatibleAsIs()} above, this
serializer will never be
- // used. A new one will be created via {@code DynamicRecordInternalType}.
- return new DynamicRecordInternalSerializer(null, writeSchemaAndSpec);
+ if (getCurrentVersion() < MOST_RECENT_VERSION) {
+ // If this serializer is not the most recent one, we need to read old
data with the correct
+ // parameters.
+ return new DynamicRecordInternalSerializer(serializerCache,
writeSchemaAndSpec, false);
+ }
Review Comment:
nit: newline
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]