org.apache.flink.api.common.typeutils.CompositeTypeSerializerUtil Java Examples

The following examples show how to use org.apache.flink.api.common.typeutils.CompositeTypeSerializerUtil. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: EitherSerializerConfigSnapshot.java    From flink with Apache License 2.0 6 votes vote down vote up
@Override
@SuppressWarnings("unchecked")
public TypeSerializerSchemaCompatibility<Either<L, R>> resolveSchemaCompatibility(
		TypeSerializer<Either<L, R>> newSerializer) {

	// this class was shared between the Java Either Serializer and the
	// Scala Either serializer
	if (newSerializer.getClass() == EitherSerializer.class) {
		List<Tuple2<TypeSerializer<?>, TypeSerializerSnapshot<?>>> nestedSerializersAndConfigs = getNestedSerializersAndConfigs();
		return CompositeTypeSerializerUtil.delegateCompatibilityCheckToNewSnapshot(
			newSerializer,
			new JavaEitherSerializerSnapshot<>(),
			nestedSerializersAndConfigs.get(0).f1,
			nestedSerializersAndConfigs.get(1).f1);
	}
	else {
		// fall back to the backwards compatibility path
		return super.resolveSchemaCompatibility(newSerializer);
	}
}
 
Example #2
Source File: ArrayListSerializer.java    From flink with Apache License 2.0 6 votes vote down vote up
/**
 * We need to implement this method as a {@link TypeSerializerConfigSnapshot.SelfResolvingTypeSerializer}
 * because this serializer was previously returning a shared {@link CollectionSerializerConfigSnapshot}
 * as its snapshot.
 *
 * <p>When the {@link CollectionSerializerConfigSnapshot} is restored, it is incapable of redirecting
 * the compatibility check to {@link ArrayListSerializerSnapshot}, so we do it here.
 */
@Override
public TypeSerializerSchemaCompatibility<ArrayList<T>> resolveSchemaCompatibilityViaRedirectingToNewSnapshotClass(
		TypeSerializerConfigSnapshot<ArrayList<T>> deprecatedConfigSnapshot) {

	if (deprecatedConfigSnapshot instanceof CollectionSerializerConfigSnapshot) {
		CollectionSerializerConfigSnapshot<ArrayList<T>, T> castedLegacySnapshot =
			(CollectionSerializerConfigSnapshot<ArrayList<T>, T>) deprecatedConfigSnapshot;

		ArrayListSerializerSnapshot<T> newSnapshot = new ArrayListSerializerSnapshot<>();
		return CompositeTypeSerializerUtil.delegateCompatibilityCheckToNewSnapshot(
			this,
			newSnapshot,
			castedLegacySnapshot.getNestedSerializerSnapshots());
	}

	return TypeSerializerSchemaCompatibility.incompatible();
}
 
Example #3
Source File: MapSerializerConfigSnapshot.java    From Flink-CEPplus with Apache License 2.0 6 votes vote down vote up
@Override
public TypeSerializerSchemaCompatibility<Map<K, V>> resolveSchemaCompatibility(TypeSerializer<Map<K, V>> newSerializer) {
	if (newSerializer instanceof MapSerializer) {
		List<Tuple2<TypeSerializer<?>, TypeSerializerSnapshot<?>>> nestedSerializersAndConfigs = getNestedSerializersAndConfigs();

		// redirect the compatibility check to the new MapSerializerSnapshot
		return CompositeTypeSerializerUtil.delegateCompatibilityCheckToNewSnapshot(
			newSerializer,
			new MapSerializerSnapshot<>(),
			nestedSerializersAndConfigs.get(0).f1,
			nestedSerializersAndConfigs.get(1).f1);
	}
	else {
		return super.resolveSchemaCompatibility(newSerializer);
	}
}
 
Example #4
Source File: Lockable.java    From Flink-CEPplus with Apache License 2.0 6 votes vote down vote up
@Override
@SuppressWarnings("unchecked")
public <U> TypeSerializerSnapshot<Lockable<E>> transformLegacySerializerSnapshot(TypeSerializerSnapshot<U> legacySnapshot) {
	if (legacySnapshot instanceof LockableTypeSerializerSnapshot) {
		return (TypeSerializerSnapshot<Lockable<E>>) legacySnapshot;
	}

	// In Flink 1.6, this serializer was directly returning the elementSerializer's snapshot
	// instead of wrapping it in a LockableTypeSerializer(Config)Snapshot.
	// This caused state information to be written as <LockableTypeSerializer, SomeArbitrarySerializerSnapshot>,
	// Therefore we need to preform the following transformation:
	// 	1. set the prior serializer on the legacySnapshot to be the elementSerializer
	// 	2. return a LockableTypeSerializerSnapshot that has the legacySnapshot as a nested snapshot.
	if (legacySnapshot instanceof TypeSerializerConfigSnapshot) {
		setElementSerializerAsPriorSerializer(legacySnapshot, this.elementSerializer);
	}
	LockableTypeSerializerSnapshot<E> lockableSnapshot = new LockableTypeSerializerSnapshot<>();
	CompositeTypeSerializerUtil.setNestedSerializersSnapshots(lockableSnapshot, legacySnapshot);
	return lockableSnapshot;
}
 
Example #5
Source File: TtlStateFactory.java    From flink with Apache License 2.0 6 votes vote down vote up
@Override
public TypeSerializerSchemaCompatibility<TtlValue<T>> resolveSchemaCompatibilityViaRedirectingToNewSnapshotClass(
		TypeSerializerConfigSnapshot<TtlValue<T>> deprecatedConfigSnapshot) {

	if (deprecatedConfigSnapshot instanceof ConfigSnapshot) {
		ConfigSnapshot castedLegacyConfigSnapshot = (ConfigSnapshot) deprecatedConfigSnapshot;
		TtlSerializerSnapshot<T> newSnapshot = new TtlSerializerSnapshot<>();

		return CompositeTypeSerializerUtil.delegateCompatibilityCheckToNewSnapshot(
			this,
			newSnapshot,
			castedLegacyConfigSnapshot.getNestedSerializerSnapshots());
	}

	return TypeSerializerSchemaCompatibility.incompatible();
}
 
Example #6
Source File: PojoSerializerSnapshot.java    From Flink-CEPplus with Apache License 2.0 6 votes vote down vote up
/**
 * Finds which registered subclasses exists both in the new {@link PojoSerializer} as well as in the previous one
 * (represented by this snapshot), and returns an {@link IntermediateCompatibilityResult}
 * of the serializers of this preexisting registered subclasses.
 */
private static <T> IntermediateCompatibilityResult<T> getCompatibilityOfPreExistingRegisteredSubclasses(
		PojoSerializer<T> newPojoSerializer,
		LinkedOptionalMap<Class<?>, TypeSerializerSnapshot<?>> registeredSubclassSerializerSnapshots) {

	final LinkedHashMap<Class<?>, TypeSerializerSnapshot<?>> unwrappedSerializerSnapshots = registeredSubclassSerializerSnapshots.unwrapOptionals();

	final ArrayList<TypeSerializerSnapshot<?>> associatedSubclassSerializerSnapshots = new ArrayList<>();
	final ArrayList<TypeSerializer<?>> associatedNewSubclassSerializers = new ArrayList<>();

	final LinkedHashMap<Class<?>, TypeSerializer<?>> newSubclassSerializerRegistry = newPojoSerializer.getBundledSubclassSerializerRegistry();

	for (Map.Entry<Class<?>, TypeSerializerSnapshot<?>> entry : unwrappedSerializerSnapshots.entrySet()) {
		TypeSerializer<?> newRegisteredSerializer = newSubclassSerializerRegistry.get(entry.getKey());
		if (newRegisteredSerializer != null) {
			associatedSubclassSerializerSnapshots.add(entry.getValue());
			associatedNewSubclassSerializers.add(newRegisteredSerializer);
		}
	}

	return CompositeTypeSerializerUtil.constructIntermediateCompatibilityResult(
		associatedNewSubclassSerializers.toArray(new TypeSerializer<?>[associatedNewSubclassSerializers.size()]),
		associatedSubclassSerializerSnapshots.toArray(new TypeSerializerSnapshot<?>[associatedSubclassSerializerSnapshots.size()]));
}
 
Example #7
Source File: RowDataSerializer.java    From flink with Apache License 2.0 6 votes vote down vote up
@Override
public TypeSerializerSchemaCompatibility<RowData> resolveSchemaCompatibility(TypeSerializer<RowData> newSerializer) {
	if (!(newSerializer instanceof RowDataSerializer)) {
		return TypeSerializerSchemaCompatibility.incompatible();
	}

	RowDataSerializer newRowSerializer = (RowDataSerializer) newSerializer;
	if (!Arrays.equals(previousTypes, newRowSerializer.types)) {
		return TypeSerializerSchemaCompatibility.incompatible();
	}

	CompositeTypeSerializerUtil.IntermediateCompatibilityResult<RowData> intermediateResult =
		CompositeTypeSerializerUtil.constructIntermediateCompatibilityResult(
			newRowSerializer.fieldSerializers,
			nestedSerializersSnapshotDelegate.getNestedSerializerSnapshots()
		);

	if (intermediateResult.isCompatibleWithReconfiguredSerializer()) {
		RowDataSerializer reconfiguredCompositeSerializer = restoreSerializer();
		return TypeSerializerSchemaCompatibility.compatibleWithReconfiguredSerializer(
			reconfiguredCompositeSerializer);
	}

	return intermediateResult.getFinalResult();
}
 
Example #8
Source File: EitherSerializerSnapshot.java    From Flink-CEPplus with Apache License 2.0 6 votes vote down vote up
@Override
public TypeSerializerSchemaCompatibility<Either<L, R>> resolveSchemaCompatibility(
		TypeSerializer<Either<L, R>> newSerializer) {
	checkState(nestedSnapshot != null);

	if (newSerializer instanceof EitherSerializer) {
		// delegate compatibility check to the new snapshot class
		return CompositeTypeSerializerUtil.delegateCompatibilityCheckToNewSnapshot(
			newSerializer,
			new JavaEitherSerializerSnapshot<>(),
			nestedSnapshot.getNestedSerializerSnapshots());
	}
	else {
		return TypeSerializerSchemaCompatibility.incompatible();
	}
}
 
Example #9
Source File: EitherSerializerConfigSnapshot.java    From Flink-CEPplus with Apache License 2.0 6 votes vote down vote up
@Override
@SuppressWarnings("unchecked")
public TypeSerializerSchemaCompatibility<Either<L, R>> resolveSchemaCompatibility(
		TypeSerializer<Either<L, R>> newSerializer) {

	// this class was shared between the Java Either Serializer and the
	// Scala Either serializer
	if (newSerializer.getClass() == EitherSerializer.class) {
		List<Tuple2<TypeSerializer<?>, TypeSerializerSnapshot<?>>> nestedSerializersAndConfigs = getNestedSerializersAndConfigs();
		return CompositeTypeSerializerUtil.delegateCompatibilityCheckToNewSnapshot(
			newSerializer,
			new JavaEitherSerializerSnapshot<>(),
			nestedSerializersAndConfigs.get(0).f1,
			nestedSerializersAndConfigs.get(1).f1);
	}
	else {
		// fall back to the backwards compatibility path
		return super.resolveSchemaCompatibility(newSerializer);
	}
}
 
Example #10
Source File: ArrayListSerializer.java    From flink with Apache License 2.0 6 votes vote down vote up
/**
 * We need to implement this method as a {@link TypeSerializerConfigSnapshot.SelfResolvingTypeSerializer}
 * because this serializer was previously returning a shared {@link CollectionSerializerConfigSnapshot}
 * as its snapshot.
 *
 * <p>When the {@link CollectionSerializerConfigSnapshot} is restored, it is incapable of redirecting
 * the compatibility check to {@link ArrayListSerializerSnapshot}, so we do it here.
 */
@Override
public TypeSerializerSchemaCompatibility<ArrayList<T>> resolveSchemaCompatibilityViaRedirectingToNewSnapshotClass(
		TypeSerializerConfigSnapshot<ArrayList<T>> deprecatedConfigSnapshot) {

	if (deprecatedConfigSnapshot instanceof CollectionSerializerConfigSnapshot) {
		CollectionSerializerConfigSnapshot<ArrayList<T>, T> castedLegacySnapshot =
			(CollectionSerializerConfigSnapshot<ArrayList<T>, T>) deprecatedConfigSnapshot;

		ArrayListSerializerSnapshot<T> newSnapshot = new ArrayListSerializerSnapshot<>();
		return CompositeTypeSerializerUtil.delegateCompatibilityCheckToNewSnapshot(
			this,
			newSnapshot,
			castedLegacySnapshot.getNestedSerializerSnapshots());
	}

	return TypeSerializerSchemaCompatibility.incompatible();
}
 
Example #11
Source File: TtlStateFactory.java    From flink with Apache License 2.0 6 votes vote down vote up
@Override
public TypeSerializerSchemaCompatibility<TtlValue<T>> resolveSchemaCompatibilityViaRedirectingToNewSnapshotClass(
		TypeSerializerConfigSnapshot<TtlValue<T>> deprecatedConfigSnapshot) {

	if (deprecatedConfigSnapshot instanceof ConfigSnapshot) {
		ConfigSnapshot castedLegacyConfigSnapshot = (ConfigSnapshot) deprecatedConfigSnapshot;
		TtlSerializerSnapshot<T> newSnapshot = new TtlSerializerSnapshot<>();

		return CompositeTypeSerializerUtil.delegateCompatibilityCheckToNewSnapshot(
			this,
			newSnapshot,
			castedLegacyConfigSnapshot.getNestedSerializerSnapshots());
	}

	return TypeSerializerSchemaCompatibility.incompatible();
}
 
Example #12
Source File: Lockable.java    From flink with Apache License 2.0 6 votes vote down vote up
@Override
@SuppressWarnings("unchecked")
public <U> TypeSerializerSnapshot<Lockable<E>> transformLegacySerializerSnapshot(TypeSerializerSnapshot<U> legacySnapshot) {
	if (legacySnapshot instanceof LockableTypeSerializerSnapshot) {
		return (TypeSerializerSnapshot<Lockable<E>>) legacySnapshot;
	}

	// In Flink 1.6, this serializer was directly returning the elementSerializer's snapshot
	// instead of wrapping it in a LockableTypeSerializer(Config)Snapshot.
	// This caused state information to be written as <LockableTypeSerializer, SomeArbitrarySerializerSnapshot>,
	// Therefore we need to preform the following transformation:
	// 	1. set the prior serializer on the legacySnapshot to be the elementSerializer
	// 	2. return a LockableTypeSerializerSnapshot that has the legacySnapshot as a nested snapshot.
	if (legacySnapshot instanceof TypeSerializerConfigSnapshot) {
		setElementSerializerAsPriorSerializer(legacySnapshot, this.elementSerializer);
	}
	LockableTypeSerializerSnapshot<E> lockableSnapshot = new LockableTypeSerializerSnapshot<>();
	CompositeTypeSerializerUtil.setNestedSerializersSnapshots(lockableSnapshot, legacySnapshot);
	return lockableSnapshot;
}
 
Example #13
Source File: TtlStateFactory.java    From Flink-CEPplus with Apache License 2.0 6 votes vote down vote up
@Override
public TypeSerializerSchemaCompatibility<TtlValue<T>> resolveSchemaCompatibilityViaRedirectingToNewSnapshotClass(
		TypeSerializerConfigSnapshot<TtlValue<T>> deprecatedConfigSnapshot) {

	if (deprecatedConfigSnapshot instanceof ConfigSnapshot) {
		ConfigSnapshot castedLegacyConfigSnapshot = (ConfigSnapshot) deprecatedConfigSnapshot;
		TtlSerializerSnapshot<T> newSnapshot = new TtlSerializerSnapshot<>();

		return CompositeTypeSerializerUtil.delegateCompatibilityCheckToNewSnapshot(
			this,
			newSnapshot,
			castedLegacyConfigSnapshot.getNestedSerializerSnapshots());
	}

	return TypeSerializerSchemaCompatibility.incompatible();
}
 
Example #14
Source File: ArrayListSerializer.java    From Flink-CEPplus with Apache License 2.0 6 votes vote down vote up
/**
 * We need to implement this method as a {@link TypeSerializerConfigSnapshot.SelfResolvingTypeSerializer}
 * because this serializer was previously returning a shared {@link CollectionSerializerConfigSnapshot}
 * as its snapshot.
 *
 * <p>When the {@link CollectionSerializerConfigSnapshot} is restored, it is incapable of redirecting
 * the compatibility check to {@link ArrayListSerializerSnapshot}, so we do it here.
 */
@Override
public TypeSerializerSchemaCompatibility<ArrayList<T>> resolveSchemaCompatibilityViaRedirectingToNewSnapshotClass(
		TypeSerializerConfigSnapshot<ArrayList<T>> deprecatedConfigSnapshot) {

	if (deprecatedConfigSnapshot instanceof CollectionSerializerConfigSnapshot) {
		CollectionSerializerConfigSnapshot<ArrayList<T>, T> castedLegacySnapshot =
			(CollectionSerializerConfigSnapshot<ArrayList<T>, T>) deprecatedConfigSnapshot;

		ArrayListSerializerSnapshot<T> newSnapshot = new ArrayListSerializerSnapshot<>();
		return CompositeTypeSerializerUtil.delegateCompatibilityCheckToNewSnapshot(
			this,
			newSnapshot,
			castedLegacySnapshot.getNestedSerializerSnapshots());
	}

	return TypeSerializerSchemaCompatibility.incompatible();
}
 
Example #15
Source File: EitherSerializerSnapshot.java    From flink with Apache License 2.0 6 votes vote down vote up
@Override
public TypeSerializerSchemaCompatibility<Either<L, R>> resolveSchemaCompatibility(
		TypeSerializer<Either<L, R>> newSerializer) {
	checkState(nestedSnapshot != null);

	if (newSerializer instanceof EitherSerializer) {
		// delegate compatibility check to the new snapshot class
		return CompositeTypeSerializerUtil.delegateCompatibilityCheckToNewSnapshot(
			newSerializer,
			new JavaEitherSerializerSnapshot<>(),
			nestedSnapshot.getNestedSerializerSnapshots());
	}
	else {
		return TypeSerializerSchemaCompatibility.incompatible();
	}
}
 
Example #16
Source File: RowDataSerializer.java    From flink with Apache License 2.0 6 votes vote down vote up
@Override
public TypeSerializerSchemaCompatibility<RowData> resolveSchemaCompatibility(TypeSerializer<RowData> newSerializer) {
	if (!(newSerializer instanceof RowDataSerializer)) {
		return TypeSerializerSchemaCompatibility.incompatible();
	}

	RowDataSerializer newRowSerializer = (RowDataSerializer) newSerializer;
	if (!Arrays.equals(previousTypes, newRowSerializer.fieldTypes)) {
		return TypeSerializerSchemaCompatibility.incompatible();
	}

	CompositeTypeSerializerUtil.IntermediateCompatibilityResult<RowData> intermediateResult =
		CompositeTypeSerializerUtil.constructIntermediateCompatibilityResult(
			newRowSerializer.fieldSerializers,
			nestedSerializersSnapshotDelegate.getNestedSerializerSnapshots()
		);

	if (intermediateResult.isCompatibleWithReconfiguredSerializer()) {
		RowDataSerializer reconfiguredCompositeSerializer = restoreSerializer();
		return TypeSerializerSchemaCompatibility.compatibleWithReconfiguredSerializer(
			reconfiguredCompositeSerializer);
	}

	return intermediateResult.getFinalResult();
}
 
Example #17
Source File: PojoSerializerSnapshot.java    From flink with Apache License 2.0 6 votes vote down vote up
/**
 * Finds which registered subclasses exists both in the new {@link PojoSerializer} as well as in the previous one
 * (represented by this snapshot), and returns an {@link IntermediateCompatibilityResult}
 * of the serializers of this preexisting registered subclasses.
 */
private static <T> IntermediateCompatibilityResult<T> getCompatibilityOfPreExistingRegisteredSubclasses(
		PojoSerializer<T> newPojoSerializer,
		LinkedOptionalMap<Class<?>, TypeSerializerSnapshot<?>> registeredSubclassSerializerSnapshots) {

	final LinkedHashMap<Class<?>, TypeSerializerSnapshot<?>> unwrappedSerializerSnapshots = registeredSubclassSerializerSnapshots.unwrapOptionals();

	final ArrayList<TypeSerializerSnapshot<?>> associatedSubclassSerializerSnapshots = new ArrayList<>();
	final ArrayList<TypeSerializer<?>> associatedNewSubclassSerializers = new ArrayList<>();

	final LinkedHashMap<Class<?>, TypeSerializer<?>> newSubclassSerializerRegistry = newPojoSerializer.getBundledSubclassSerializerRegistry();

	for (Map.Entry<Class<?>, TypeSerializerSnapshot<?>> entry : unwrappedSerializerSnapshots.entrySet()) {
		TypeSerializer<?> newRegisteredSerializer = newSubclassSerializerRegistry.get(entry.getKey());
		if (newRegisteredSerializer != null) {
			associatedSubclassSerializerSnapshots.add(entry.getValue());
			associatedNewSubclassSerializers.add(newRegisteredSerializer);
		}
	}

	return CompositeTypeSerializerUtil.constructIntermediateCompatibilityResult(
		associatedNewSubclassSerializers.toArray(new TypeSerializer<?>[associatedNewSubclassSerializers.size()]),
		associatedSubclassSerializerSnapshots.toArray(new TypeSerializerSnapshot<?>[associatedSubclassSerializerSnapshots.size()]));
}
 
Example #18
Source File: EitherSerializerConfigSnapshot.java    From flink with Apache License 2.0 6 votes vote down vote up
@Override
@SuppressWarnings("unchecked")
public TypeSerializerSchemaCompatibility<Either<L, R>> resolveSchemaCompatibility(
		TypeSerializer<Either<L, R>> newSerializer) {

	// this class was shared between the Java Either Serializer and the
	// Scala Either serializer
	if (newSerializer.getClass() == EitherSerializer.class) {
		List<Tuple2<TypeSerializer<?>, TypeSerializerSnapshot<?>>> nestedSerializersAndConfigs = getNestedSerializersAndConfigs();
		return CompositeTypeSerializerUtil.delegateCompatibilityCheckToNewSnapshot(
			newSerializer,
			new JavaEitherSerializerSnapshot<>(),
			nestedSerializersAndConfigs.get(0).f1,
			nestedSerializersAndConfigs.get(1).f1);
	}
	else {
		// fall back to the backwards compatibility path
		return super.resolveSchemaCompatibility(newSerializer);
	}
}
 
Example #19
Source File: EitherSerializerSnapshot.java    From flink with Apache License 2.0 6 votes vote down vote up
@Override
public TypeSerializerSchemaCompatibility<Either<L, R>> resolveSchemaCompatibility(
		TypeSerializer<Either<L, R>> newSerializer) {
	checkState(nestedSnapshot != null);

	if (newSerializer instanceof EitherSerializer) {
		// delegate compatibility check to the new snapshot class
		return CompositeTypeSerializerUtil.delegateCompatibilityCheckToNewSnapshot(
			newSerializer,
			new JavaEitherSerializerSnapshot<>(),
			nestedSnapshot.getNestedSerializerSnapshots());
	}
	else {
		return TypeSerializerSchemaCompatibility.incompatible();
	}
}
 
Example #20
Source File: BaseRowSerializer.java    From flink with Apache License 2.0 6 votes vote down vote up
@Override
public TypeSerializerSchemaCompatibility<BaseRow> resolveSchemaCompatibility(TypeSerializer<BaseRow> newSerializer) {
	if (!(newSerializer instanceof BaseRowSerializer)) {
		return TypeSerializerSchemaCompatibility.incompatible();
	}

	BaseRowSerializer newRowSerializer = (BaseRowSerializer) newSerializer;
	if (!Arrays.equals(previousTypes, newRowSerializer.types)) {
		return TypeSerializerSchemaCompatibility.incompatible();
	}

	CompositeTypeSerializerUtil.IntermediateCompatibilityResult<BaseRow> intermediateResult =
			CompositeTypeSerializerUtil.constructIntermediateCompatibilityResult(
					newRowSerializer.fieldSerializers,
					nestedSerializersSnapshotDelegate.getNestedSerializerSnapshots()
			);

	if (intermediateResult.isCompatibleWithReconfiguredSerializer()) {
		BaseRowSerializer reconfiguredCompositeSerializer = restoreSerializer();
		return TypeSerializerSchemaCompatibility.compatibleWithReconfiguredSerializer(
				reconfiguredCompositeSerializer);
	}

	return intermediateResult.getFinalResult();
}
 
Example #21
Source File: PojoSerializerSnapshot.java    From flink with Apache License 2.0 6 votes vote down vote up
/**
 * Finds which registered subclasses exists both in the new {@link PojoSerializer} as well as in the previous one
 * (represented by this snapshot), and returns an {@link IntermediateCompatibilityResult}
 * of the serializers of this preexisting registered subclasses.
 */
private static <T> IntermediateCompatibilityResult<T> getCompatibilityOfPreExistingRegisteredSubclasses(
		PojoSerializer<T> newPojoSerializer,
		LinkedOptionalMap<Class<?>, TypeSerializerSnapshot<?>> registeredSubclassSerializerSnapshots) {

	final LinkedHashMap<Class<?>, TypeSerializerSnapshot<?>> unwrappedSerializerSnapshots = registeredSubclassSerializerSnapshots.unwrapOptionals();

	final ArrayList<TypeSerializerSnapshot<?>> associatedSubclassSerializerSnapshots = new ArrayList<>();
	final ArrayList<TypeSerializer<?>> associatedNewSubclassSerializers = new ArrayList<>();

	final LinkedHashMap<Class<?>, TypeSerializer<?>> newSubclassSerializerRegistry = newPojoSerializer.getBundledSubclassSerializerRegistry();

	for (Map.Entry<Class<?>, TypeSerializerSnapshot<?>> entry : unwrappedSerializerSnapshots.entrySet()) {
		TypeSerializer<?> newRegisteredSerializer = newSubclassSerializerRegistry.get(entry.getKey());
		if (newRegisteredSerializer != null) {
			associatedSubclassSerializerSnapshots.add(entry.getValue());
			associatedNewSubclassSerializers.add(newRegisteredSerializer);
		}
	}

	return CompositeTypeSerializerUtil.constructIntermediateCompatibilityResult(
		associatedNewSubclassSerializers.toArray(new TypeSerializer<?>[associatedNewSubclassSerializers.size()]),
		associatedSubclassSerializerSnapshots.toArray(new TypeSerializerSnapshot<?>[associatedSubclassSerializerSnapshots.size()]));
}
 
Example #22
Source File: MapSerializerConfigSnapshot.java    From flink with Apache License 2.0 6 votes vote down vote up
@Override
public TypeSerializerSchemaCompatibility<Map<K, V>> resolveSchemaCompatibility(TypeSerializer<Map<K, V>> newSerializer) {
	if (newSerializer instanceof MapSerializer) {
		List<Tuple2<TypeSerializer<?>, TypeSerializerSnapshot<?>>> nestedSerializersAndConfigs = getNestedSerializersAndConfigs();

		// redirect the compatibility check to the new MapSerializerSnapshot
		return CompositeTypeSerializerUtil.delegateCompatibilityCheckToNewSnapshot(
			newSerializer,
			new MapSerializerSnapshot<>(),
			nestedSerializersAndConfigs.get(0).f1,
			nestedSerializersAndConfigs.get(1).f1);
	}
	else {
		return super.resolveSchemaCompatibility(newSerializer);
	}
}
 
Example #23
Source File: MapSerializerConfigSnapshot.java    From flink with Apache License 2.0 6 votes vote down vote up
@Override
public TypeSerializerSchemaCompatibility<Map<K, V>> resolveSchemaCompatibility(TypeSerializer<Map<K, V>> newSerializer) {
	if (newSerializer instanceof MapSerializer) {
		List<Tuple2<TypeSerializer<?>, TypeSerializerSnapshot<?>>> nestedSerializersAndConfigs = getNestedSerializersAndConfigs();

		// redirect the compatibility check to the new MapSerializerSnapshot
		return CompositeTypeSerializerUtil.delegateCompatibilityCheckToNewSnapshot(
			newSerializer,
			new MapSerializerSnapshot<>(),
			nestedSerializersAndConfigs.get(0).f1,
			nestedSerializersAndConfigs.get(1).f1);
	}
	else {
		return super.resolveSchemaCompatibility(newSerializer);
	}
}
 
Example #24
Source File: Lockable.java    From flink with Apache License 2.0 6 votes vote down vote up
@Override
@SuppressWarnings("unchecked")
public <U> TypeSerializerSnapshot<Lockable<E>> transformLegacySerializerSnapshot(TypeSerializerSnapshot<U> legacySnapshot) {
	if (legacySnapshot instanceof LockableTypeSerializerSnapshot) {
		return (TypeSerializerSnapshot<Lockable<E>>) legacySnapshot;
	}

	// In Flink 1.6, this serializer was directly returning the elementSerializer's snapshot
	// instead of wrapping it in a LockableTypeSerializer(Config)Snapshot.
	// This caused state information to be written as <LockableTypeSerializer, SomeArbitrarySerializerSnapshot>,
	// Therefore we need to preform the following transformation:
	// 	1. set the prior serializer on the legacySnapshot to be the elementSerializer
	// 	2. return a LockableTypeSerializerSnapshot that has the legacySnapshot as a nested snapshot.
	if (legacySnapshot instanceof TypeSerializerConfigSnapshot) {
		setElementSerializerAsPriorSerializer(legacySnapshot, this.elementSerializer);
	}
	LockableTypeSerializerSnapshot<E> lockableSnapshot = new LockableTypeSerializerSnapshot<>();
	CompositeTypeSerializerUtil.setNestedSerializersSnapshots(lockableSnapshot, legacySnapshot);
	return lockableSnapshot;
}
 
Example #25
Source File: ScalaTrySerializerConfigSnapshot.java    From flink with Apache License 2.0 5 votes vote down vote up
@Override
public TypeSerializerSchemaCompatibility<Try<E>> resolveSchemaCompatibility(TypeSerializer<Try<E>> newSerializer) {

	return CompositeTypeSerializerUtil.delegateCompatibilityCheckToNewSnapshot(
		newSerializer,
		new ScalaTrySerializerSnapshot<>(),
		getNestedSerializersAndConfigs().get(0).f1,
		getNestedSerializersAndConfigs().get(1).f1);
}
 
Example #26
Source File: StreamElementSerializer.java    From flink with Apache License 2.0 5 votes vote down vote up
@Override
public TypeSerializerSchemaCompatibility<StreamElement> resolveSchemaCompatibility(TypeSerializer<StreamElement> newSerializer) {
	return CompositeTypeSerializerUtil.delegateCompatibilityCheckToNewSnapshot(
		newSerializer,
		new StreamElementSerializerSnapshot<>(),
		getSingleNestedSerializerAndConfig().f1);
}
 
Example #27
Source File: StreamElementSerializer.java    From flink with Apache License 2.0 5 votes vote down vote up
@Override
public TypeSerializerSchemaCompatibility<StreamElement> resolveSchemaCompatibility(TypeSerializer<StreamElement> newSerializer) {
	return CompositeTypeSerializerUtil.delegateCompatibilityCheckToNewSnapshot(
		newSerializer,
		new StreamElementSerializerSnapshot<>(),
		getSingleNestedSerializerAndConfig().f1);
}
 
Example #28
Source File: ListViewSerializer.java    From flink with Apache License 2.0 5 votes vote down vote up
/**
 * We need to override this as a {@link LegacySerializerSnapshotTransformer}
 * because in Flink 1.6.x and below, this serializer was incorrectly returning
 * directly the snapshot of the nested list serializer as its own snapshot.
 *
 * <p>This method transforms the incorrect list serializer snapshot
 * to be a proper {@link ListViewSerializerSnapshot}.
 */
@Override
public <U> TypeSerializerSnapshot<ListView<T>> transformLegacySerializerSnapshot(
		TypeSerializerSnapshot<U> legacySnapshot) {
	if (legacySnapshot instanceof ListViewSerializerSnapshot) {
		return (TypeSerializerSnapshot<ListView<T>>) legacySnapshot;
	} else if (legacySnapshot instanceof CollectionSerializerConfigSnapshot) {
		// first, transform the incorrect list serializer's snapshot
		// into a proper ListSerializerSnapshot
		ListSerializerSnapshot<T> transformedNestedListSerializerSnapshot = new ListSerializerSnapshot<>();
		CollectionSerializerConfigSnapshot<List<T>, T> snapshot =
				(CollectionSerializerConfigSnapshot<List<T>, T>) legacySnapshot;
		CompositeTypeSerializerUtil.setNestedSerializersSnapshots(
				transformedNestedListSerializerSnapshot,
				(TypeSerializerSnapshot<?>) (snapshot.getSingleNestedSerializerAndConfig().f1));

		// then, wrap the transformed ListSerializerSnapshot
		// as a nested snapshot in the final resulting ListViewSerializerSnapshot
		ListViewSerializerSnapshot<T> transformedListViewSerializerSnapshot = new ListViewSerializerSnapshot<>();
		CompositeTypeSerializerUtil.setNestedSerializersSnapshots(
				transformedListViewSerializerSnapshot,
				transformedNestedListSerializerSnapshot);

		return transformedListViewSerializerSnapshot;
	} else {
		throw new UnsupportedOperationException(
				legacySnapshot.getClass().getCanonicalName() + " is not supported.");
	}
}
 
Example #29
Source File: TraversableSerializerConfigSnapshot.java    From flink with Apache License 2.0 5 votes vote down vote up
@Override
public TypeSerializerSchemaCompatibility<T> resolveSchemaCompatibility(TypeSerializer<T> newSerializer) {
	TraversableSerializer<T, E> previousSerializer = (TraversableSerializer<T, E>) restoreSerializer();
	TraversableSerializerSnapshot<T, E> newCompositeSnapshot =
			new TraversableSerializerSnapshot<>(previousSerializer.cbfCode());

	return CompositeTypeSerializerUtil.delegateCompatibilityCheckToNewSnapshot(
			newSerializer,
			newCompositeSnapshot,
			getSingleNestedSerializerAndConfig().f1
	);
}
 
Example #30
Source File: TwoPhaseCommitSinkFunction.java    From flink with Apache License 2.0 5 votes vote down vote up
@Override
public TypeSerializerSchemaCompatibility<State<TXN, CONTEXT>> resolveSchemaCompatibility(
		TypeSerializer<State<TXN, CONTEXT>> newSerializer) {

	final TypeSerializerSnapshot<?>[] nestedSnapshots = getNestedSerializersAndConfigs()
		.stream()
		.map(t -> t.f1)
		.toArray(TypeSerializerSnapshot[]::new);

	return CompositeTypeSerializerUtil.delegateCompatibilityCheckToNewSnapshot(
		newSerializer,
		new StateSerializerSnapshot<>(),
		nestedSnapshots
	);
}