tzulitai commented on a change in pull request #7759: [FLINK-11485][FLINK-10897] POJO state schema evolution / migrate PojoSerializer to use new compatibility APIs URL: https://github.com/apache/flink/pull/7759#discussion_r258755169
########## File path: flink-core/src/main/java/org/apache/flink/api/java/typeutils/runtime/PojoSerializerSnapshotData.java ########## @@ -0,0 +1,288 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.flink.api.java.typeutils.runtime; + +import org.apache.flink.annotation.Internal; +import org.apache.flink.api.common.typeutils.TypeSerializer; +import org.apache.flink.api.common.typeutils.TypeSerializerSnapshot; +import org.apache.flink.core.memory.DataInputView; +import org.apache.flink.core.memory.DataOutputView; +import org.apache.flink.util.InstantiationUtil; +import org.apache.flink.util.LinkedOptionalMap; +import org.apache.flink.util.function.BiConsumerWithException; +import org.apache.flink.util.function.BiFunctionWithException; +import org.apache.flink.util.function.FunctionWithException; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import java.io.IOException; +import java.lang.reflect.Field; +import java.util.HashMap; +import java.util.LinkedHashMap; + +import static org.apache.flink.util.LinkedOptionalMap.optionalMapOf; +import static org.apache.flink.util.Preconditions.checkNotNull; + +/** + * This class holds the snapshot content for the {@link PojoSerializer}. + * + * <h2>Serialization Format</hr> + * + * <p>The serialization format defined by this class is as follows: + * + * <pre>{@code + * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ + * | POJO class name | + * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ + * | number of fields | (field name, field serializer snapshot) | + * | | pairs | + * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ + * | number of | (registered subclass name, subclass serializer snapshot) | + * | registered subclasses | pairs | + * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ + * | number of | (non-registered subclass name, subclass serializer snapshot) | + * | non-registered subclasses | pairs | + * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ + * }</pre> + */ +@Internal +final class PojoSerializerSnapshotData<T> { + + private static final Logger LOG = LoggerFactory.getLogger(PojoSerializerSnapshotData.class); + + // --------------------------------------------------------------------------------------------- + // Factory methods + // --------------------------------------------------------------------------------------------- + + /** + * Creates a {@link PojoSerializerSnapshotData} from configuration of a {@link PojoSerializer}. + * + * <p>This factory method is meant to be used in regular write paths, i.e. when taking a snapshot + * of the {@link PojoSerializer}. All POJO fields, registered subclass classes, and non-registered + * subclass classes are all present. + */ + static <T> PojoSerializerSnapshotData<T> createFrom( + Class<T> pojoClass, + LinkedHashMap<Field, TypeSerializer<?>> fieldSerializers, + LinkedHashMap<Class<?>, TypeSerializer<?>> registeredSubclassSerializers, + HashMap<Class<?>, TypeSerializer<?>> nonRegisteredSubclassSerializers) { + + LinkedHashMap<Field, TypeSerializerSnapshot<?>> fieldSerializerSnapshots = new LinkedHashMap<>(fieldSerializers.size()); + fieldSerializers.forEach((k, v) -> fieldSerializerSnapshots.put(k, v.snapshotConfiguration())); Review comment: good catch! Yes, we should be using `TypeSerializerUtils#snapshotBackwardsCompatible` ---------------------------------------------------------------- This is an automated message from the Apache Git Service. To respond to the message, please log on GitHub and use the URL above to go to the specific comment. For queries about this service, please contact Infrastructure at: us...@infra.apache.org With regards, Apache Git Services