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

The following examples show how to use org.apache.flink.api.common.typeutils.CompositeTypeSerializerUtil.IntermediateCompatibilityResult. 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: CompositeTypeSerializerUtilTest.java    From Flink-CEPplus with Apache License 2.0 6 votes vote down vote up
@Test
public void testCompatibleAfterMigrationIntermediateCompatibilityResult() {
	final TypeSerializerSnapshot<?>[] testSerializerSnapshots = new TypeSerializerSnapshot<?>[] {
		SchemaCompatibilityTestingSnapshot.thatIsCompatibleWithNextSerializerAfterReconfiguration("a"),
		SchemaCompatibilityTestingSnapshot.thatIsCompatibleWithNextSerializerAfterMigration("b"),
		SchemaCompatibilityTestingSnapshot.thatIsCompatibleWithNextSerializer("c"),
	};

	final TypeSerializer<?>[] testNewSerializers = new TypeSerializer<?>[] {
		new SchemaCompatibilityTestingSerializer("a"),
		new SchemaCompatibilityTestingSerializer("b"),
		new SchemaCompatibilityTestingSerializer("c")
	};

	IntermediateCompatibilityResult<?> intermediateCompatibilityResult =
		CompositeTypeSerializerUtil.constructIntermediateCompatibilityResult(testNewSerializers, testSerializerSnapshots);

	assertTrue(intermediateCompatibilityResult.isCompatibleAfterMigration());
	assertTrue(intermediateCompatibilityResult.getFinalResult().isCompatibleAfterMigration());
}
 
Example #2
Source File: PojoSerializerSnapshot.java    From flink with Apache License 2.0 6 votes vote down vote up
/**
 * Creates a reconfigured version of the {@link PojoSerializer}.
 *
 * @param originalNewPojoSerializer the original new {@link PojoSerializer} to create a reconfigured version of.
 * @param fieldSerializerCompatibility compatibility of preexisting fields' serializers.
 * @param registeredSerializerSnapshots snapshot of previous registered subclasses' serializers.
 * @param preExistingRegistrationsCompatibility compatibility of preexisting subclasses' serializers.
 * @param nonRegisteredSubclassSerializerSnapshots snapshot of previous non-registered subclasses' serializers.
 *
 * @return a reconfigured version of the original new {@link PojoSerializer}.
 */
private static <T> PojoSerializer<T> constructReconfiguredPojoSerializer(
		PojoSerializer<T> originalNewPojoSerializer,
		IntermediateCompatibilityResult<T> fieldSerializerCompatibility,
		LinkedOptionalMap<Class<?>, TypeSerializerSnapshot<?>> registeredSerializerSnapshots,
		IntermediateCompatibilityResult<T> preExistingRegistrationsCompatibility,
		LinkedOptionalMap<Class<?>, TypeSerializerSnapshot<?>> nonRegisteredSubclassSerializerSnapshots) {

	@SuppressWarnings("unchecked")
	final TypeSerializer<Object>[] reconfiguredFieldSerializers = constructReconfiguredFieldSerializers(fieldSerializerCompatibility);

	Tuple2<LinkedHashMap<Class<?>, Integer>, TypeSerializer<Object>[]> reconfiguredSubclassRegistry = constructReconfiguredSubclassRegistry(
		originalNewPojoSerializer.getBundledSubclassSerializerRegistry(),
		registeredSerializerSnapshots,
		preExistingRegistrationsCompatibility);

	return new PojoSerializer<>(
		originalNewPojoSerializer.getPojoClass(),
		originalNewPojoSerializer.getFields(),
		reconfiguredFieldSerializers,
		reconfiguredSubclassRegistry.f0,
		reconfiguredSubclassRegistry.f1,
		restoreSerializers(nonRegisteredSubclassSerializerSnapshots.unwrapOptionals()),
		originalNewPojoSerializer.getExecutionConfig());
}
 
Example #3
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 #4
Source File: CompositeTypeSerializerUtilTest.java    From flink with Apache License 2.0 6 votes vote down vote up
@Test
public void testCompatibleAsIsIntermediateCompatibilityResult() {
	final TypeSerializerSnapshot<?>[] testSerializerSnapshots = new TypeSerializerSnapshot<?>[] {
		SchemaCompatibilityTestingSnapshot.thatIsCompatibleWithNextSerializer("first serializer"),
		SchemaCompatibilityTestingSnapshot.thatIsCompatibleWithNextSerializer("second serializer"),
	};

	final TypeSerializer<?>[] testNewSerializers = new TypeSerializer<?>[] {
		new SchemaCompatibilityTestingSerializer("first serializer"),
		new SchemaCompatibilityTestingSerializer("second serializer"),
	};

	IntermediateCompatibilityResult<?> intermediateCompatibilityResult =
		CompositeTypeSerializerUtil.constructIntermediateCompatibilityResult(testNewSerializers, testSerializerSnapshots);

	assertTrue(intermediateCompatibilityResult.isCompatibleAsIs());
	assertTrue(intermediateCompatibilityResult.getFinalResult().isCompatibleAsIs());
	assertArrayEquals(testNewSerializers, intermediateCompatibilityResult.getNestedSerializers());
}
 
Example #5
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 #6
Source File: CompositeTypeSerializerUtilTest.java    From flink with Apache License 2.0 6 votes vote down vote up
@Test
public void testCompatibleWithReconfiguredSerializerIntermediateCompatibilityResult() {
	final TypeSerializerSnapshot<?>[] testSerializerSnapshots = new TypeSerializerSnapshot<?>[] {
		SchemaCompatibilityTestingSnapshot.thatIsCompatibleWithNextSerializer("a"),
		SchemaCompatibilityTestingSnapshot.thatIsCompatibleWithNextSerializerAfterReconfiguration("b"),
	};

	final TypeSerializer<?>[] testNewSerializers = new TypeSerializer<?>[] {
		new SchemaCompatibilityTestingSerializer("a"),
		new SchemaCompatibilityTestingSerializer("b"),
	};

	IntermediateCompatibilityResult<?> intermediateCompatibilityResult =
		CompositeTypeSerializerUtil.constructIntermediateCompatibilityResult(testNewSerializers, testSerializerSnapshots);

	final TypeSerializer<?>[] expectedReconfiguredNestedSerializers = new TypeSerializer<?>[] {
		new SchemaCompatibilityTestingSerializer("a"),
		new SchemaCompatibilityTestingSerializer("b"),
	};

	assertTrue(intermediateCompatibilityResult.isCompatibleWithReconfiguredSerializer());
	assertArrayEquals(expectedReconfiguredNestedSerializers, intermediateCompatibilityResult.getNestedSerializers());
}
 
Example #7
Source File: PojoSerializerSnapshot.java    From flink with Apache License 2.0 6 votes vote down vote up
/**
 * Creates a reconfigured version of the {@link PojoSerializer}.
 *
 * @param originalNewPojoSerializer the original new {@link PojoSerializer} to create a reconfigured version of.
 * @param fieldSerializerCompatibility compatibility of preexisting fields' serializers.
 * @param registeredSerializerSnapshots snapshot of previous registered subclasses' serializers.
 * @param preExistingRegistrationsCompatibility compatibility of preexisting subclasses' serializers.
 * @param nonRegisteredSubclassSerializerSnapshots snapshot of previous non-registered subclasses' serializers.
 *
 * @return a reconfigured version of the original new {@link PojoSerializer}.
 */
private static <T> PojoSerializer<T> constructReconfiguredPojoSerializer(
		PojoSerializer<T> originalNewPojoSerializer,
		IntermediateCompatibilityResult<T> fieldSerializerCompatibility,
		LinkedOptionalMap<Class<?>, TypeSerializerSnapshot<?>> registeredSerializerSnapshots,
		IntermediateCompatibilityResult<T> preExistingRegistrationsCompatibility,
		LinkedOptionalMap<Class<?>, TypeSerializerSnapshot<?>> nonRegisteredSubclassSerializerSnapshots) {

	@SuppressWarnings("unchecked")
	final TypeSerializer<Object>[] reconfiguredFieldSerializers = constructReconfiguredFieldSerializers(fieldSerializerCompatibility);

	Tuple2<LinkedHashMap<Class<?>, Integer>, TypeSerializer<Object>[]> reconfiguredSubclassRegistry = constructReconfiguredSubclassRegistry(
		originalNewPojoSerializer.getBundledSubclassSerializerRegistry(),
		registeredSerializerSnapshots,
		preExistingRegistrationsCompatibility);

	return new PojoSerializer<>(
		originalNewPojoSerializer.getPojoClass(),
		originalNewPojoSerializer.getFields(),
		reconfiguredFieldSerializers,
		reconfiguredSubclassRegistry.f0,
		reconfiguredSubclassRegistry.f1,
		restoreSerializers(nonRegisteredSubclassSerializerSnapshots.unwrapOptionals()),
		originalNewPojoSerializer.getExecutionConfig());
}
 
Example #8
Source File: CompositeTypeSerializerUtilTest.java    From flink with Apache License 2.0 6 votes vote down vote up
@Test
public void testCompatibleAsIsIntermediateCompatibilityResult() {
	final TypeSerializerSnapshot<?>[] testSerializerSnapshots = new TypeSerializerSnapshot<?>[] {
		SchemaCompatibilityTestingSnapshot.thatIsCompatibleWithNextSerializer("first serializer"),
		SchemaCompatibilityTestingSnapshot.thatIsCompatibleWithNextSerializer("second serializer"),
	};

	final TypeSerializer<?>[] testNewSerializers = new TypeSerializer<?>[] {
		new SchemaCompatibilityTestingSerializer("first serializer"),
		new SchemaCompatibilityTestingSerializer("second serializer"),
	};

	IntermediateCompatibilityResult<?> intermediateCompatibilityResult =
		CompositeTypeSerializerUtil.constructIntermediateCompatibilityResult(testNewSerializers, testSerializerSnapshots);

	assertTrue(intermediateCompatibilityResult.isCompatibleAsIs());
	assertTrue(intermediateCompatibilityResult.getFinalResult().isCompatibleAsIs());
	assertArrayEquals(testNewSerializers, intermediateCompatibilityResult.getNestedSerializers());
}
 
Example #9
Source File: CompositeTypeSerializerUtilTest.java    From flink with Apache License 2.0 6 votes vote down vote up
@Test
public void testCompatibleWithReconfiguredSerializerIntermediateCompatibilityResult() {
	final TypeSerializerSnapshot<?>[] testSerializerSnapshots = new TypeSerializerSnapshot<?>[] {
		SchemaCompatibilityTestingSnapshot.thatIsCompatibleWithNextSerializer("a"),
		SchemaCompatibilityTestingSnapshot.thatIsCompatibleWithNextSerializerAfterReconfiguration("b"),
	};

	final TypeSerializer<?>[] testNewSerializers = new TypeSerializer<?>[] {
		new SchemaCompatibilityTestingSerializer("a"),
		new SchemaCompatibilityTestingSerializer("b"),
	};

	IntermediateCompatibilityResult<?> intermediateCompatibilityResult =
		CompositeTypeSerializerUtil.constructIntermediateCompatibilityResult(testNewSerializers, testSerializerSnapshots);

	final TypeSerializer<?>[] expectedReconfiguredNestedSerializers = new TypeSerializer<?>[] {
		new SchemaCompatibilityTestingSerializer("a"),
		new SchemaCompatibilityTestingSerializer("b"),
	};

	assertTrue(intermediateCompatibilityResult.isCompatibleWithReconfiguredSerializer());
	assertArrayEquals(expectedReconfiguredNestedSerializers, intermediateCompatibilityResult.getNestedSerializers());
}
 
Example #10
Source File: CompositeTypeSerializerUtilTest.java    From flink with Apache License 2.0 6 votes vote down vote up
@Test
public void testCompatibleAfterMigrationIntermediateCompatibilityResult() {
	final TypeSerializerSnapshot<?>[] testSerializerSnapshots = new TypeSerializerSnapshot<?>[] {
		SchemaCompatibilityTestingSnapshot.thatIsCompatibleWithNextSerializerAfterReconfiguration("a"),
		SchemaCompatibilityTestingSnapshot.thatIsCompatibleWithNextSerializerAfterMigration("b"),
		SchemaCompatibilityTestingSnapshot.thatIsCompatibleWithNextSerializer("c"),
	};

	final TypeSerializer<?>[] testNewSerializers = new TypeSerializer<?>[] {
		new SchemaCompatibilityTestingSerializer("a"),
		new SchemaCompatibilityTestingSerializer("b"),
		new SchemaCompatibilityTestingSerializer("c")
	};

	IntermediateCompatibilityResult<?> intermediateCompatibilityResult =
		CompositeTypeSerializerUtil.constructIntermediateCompatibilityResult(testNewSerializers, testSerializerSnapshots);

	assertTrue(intermediateCompatibilityResult.isCompatibleAfterMigration());
	assertTrue(intermediateCompatibilityResult.getFinalResult().isCompatibleAfterMigration());
}
 
Example #11
Source File: CompositeTypeSerializerUtilTest.java    From Flink-CEPplus with Apache License 2.0 6 votes vote down vote up
@Test
public void testIncompatibleIntermediateCompatibilityResult() {
	final TypeSerializerSnapshot<?>[] testSerializerSnapshots = new TypeSerializerSnapshot<?>[] {
		SchemaCompatibilityTestingSnapshot.thatIsCompatibleWithNextSerializer(),
		SchemaCompatibilityTestingSnapshot.thatIsIncompatibleWithTheNextSerializer(),
		SchemaCompatibilityTestingSnapshot.thatIsCompatibleWithNextSerializerAfterReconfiguration(),
		SchemaCompatibilityTestingSnapshot.thatIsCompatibleWithNextSerializerAfterMigration(),
	};

	final TypeSerializer<?>[] testNewSerializers = new TypeSerializer<?>[] {
		new SchemaCompatibilityTestingSerializer(),
		new SchemaCompatibilityTestingSerializer(),
		new SchemaCompatibilityTestingSerializer(),
		new SchemaCompatibilityTestingSerializer()
	};

	IntermediateCompatibilityResult<?> intermediateCompatibilityResult =
		CompositeTypeSerializerUtil.constructIntermediateCompatibilityResult(testNewSerializers, testSerializerSnapshots);

	assertTrue(intermediateCompatibilityResult.isIncompatible());
	assertTrue(intermediateCompatibilityResult.getFinalResult().isIncompatible());
}
 
Example #12
Source File: CompositeTypeSerializerUtilTest.java    From Flink-CEPplus with Apache License 2.0 6 votes vote down vote up
@Test
public void testCompatibleWithReconfiguredSerializerIntermediateCompatibilityResult() {
	final TypeSerializerSnapshot<?>[] testSerializerSnapshots = new TypeSerializerSnapshot<?>[] {
		SchemaCompatibilityTestingSnapshot.thatIsCompatibleWithNextSerializer("a"),
		SchemaCompatibilityTestingSnapshot.thatIsCompatibleWithNextSerializerAfterReconfiguration("b"),
	};

	final TypeSerializer<?>[] testNewSerializers = new TypeSerializer<?>[] {
		new SchemaCompatibilityTestingSerializer("a"),
		new SchemaCompatibilityTestingSerializer("b"),
	};

	IntermediateCompatibilityResult<?> intermediateCompatibilityResult =
		CompositeTypeSerializerUtil.constructIntermediateCompatibilityResult(testNewSerializers, testSerializerSnapshots);

	final TypeSerializer<?>[] expectedReconfiguredNestedSerializers = new TypeSerializer<?>[] {
		new SchemaCompatibilityTestingSerializer("a"),
		new SchemaCompatibilityTestingSerializer("b"),
	};

	assertTrue(intermediateCompatibilityResult.isCompatibleWithReconfiguredSerializer());
	assertArrayEquals(expectedReconfiguredNestedSerializers, intermediateCompatibilityResult.getNestedSerializers());
}
 
Example #13
Source File: CompositeTypeSerializerUtilTest.java    From Flink-CEPplus with Apache License 2.0 6 votes vote down vote up
@Test
public void testCompatibleAsIsIntermediateCompatibilityResult() {
	final TypeSerializerSnapshot<?>[] testSerializerSnapshots = new TypeSerializerSnapshot<?>[] {
		SchemaCompatibilityTestingSnapshot.thatIsCompatibleWithNextSerializer("first serializer"),
		SchemaCompatibilityTestingSnapshot.thatIsCompatibleWithNextSerializer("second serializer"),
	};

	final TypeSerializer<?>[] testNewSerializers = new TypeSerializer<?>[] {
		new SchemaCompatibilityTestingSerializer("first serializer"),
		new SchemaCompatibilityTestingSerializer("second serializer"),
	};

	IntermediateCompatibilityResult<?> intermediateCompatibilityResult =
		CompositeTypeSerializerUtil.constructIntermediateCompatibilityResult(testNewSerializers, testSerializerSnapshots);

	assertTrue(intermediateCompatibilityResult.isCompatibleAsIs());
	assertTrue(intermediateCompatibilityResult.getFinalResult().isCompatibleAsIs());
	assertArrayEquals(testNewSerializers, intermediateCompatibilityResult.getNestedSerializers());
}
 
Example #14
Source File: PojoSerializerSnapshot.java    From Flink-CEPplus with Apache License 2.0 6 votes vote down vote up
private static Tuple2<LinkedHashMap<Class<?>, Integer>, TypeSerializer<Object>[]> constructReconfiguredSubclassRegistry(
		LinkedHashMap<Class<?>, TypeSerializer<?>> newSubclassRegistrations,
		LinkedOptionalMap<Class<?>, TypeSerializerSnapshot<?>> registeredSerializerSnapshots,
		IntermediateCompatibilityResult<?> preExistingRegistrationsCompatibility) {

	checkArgument(!preExistingRegistrationsCompatibility.isIncompatible() && !preExistingRegistrationsCompatibility.isCompatibleAfterMigration());

	LinkedHashMap<Class<?>, TypeSerializer<?>> reconfiguredSubclassSerializerRegistry =
		restoreSerializers(registeredSerializerSnapshots.unwrapOptionals());

	Iterator<TypeSerializer<?>> serializersForPreexistingRegistrations =
		Arrays.asList(preExistingRegistrationsCompatibility.getNestedSerializers()).iterator();

	for (Map.Entry<Class<?>, TypeSerializer<?>> registration : newSubclassRegistrations.entrySet()) {
		// new registrations should simply be appended to the subclass serializer registry with their new serializers;
		// preexisting registrations should use the compatibility-checked serializer
		TypeSerializer<?> newRegistration = (reconfiguredSubclassSerializerRegistry.containsKey(registration.getKey()))
			? serializersForPreexistingRegistrations.next()
			: registration.getValue();
		reconfiguredSubclassSerializerRegistry.put(registration.getKey(), newRegistration);
	}

	return decomposeSubclassSerializerRegistry(reconfiguredSubclassSerializerRegistry);
}
 
Example #15
Source File: CompositeTypeSerializerUtilTest.java    From flink with Apache License 2.0 6 votes vote down vote up
@Test
public void testIncompatibleIntermediateCompatibilityResult() {
	final TypeSerializerSnapshot<?>[] testSerializerSnapshots = new TypeSerializerSnapshot<?>[] {
		SchemaCompatibilityTestingSnapshot.thatIsCompatibleWithNextSerializer(),
		SchemaCompatibilityTestingSnapshot.thatIsIncompatibleWithTheNextSerializer(),
		SchemaCompatibilityTestingSnapshot.thatIsCompatibleWithNextSerializerAfterReconfiguration(),
		SchemaCompatibilityTestingSnapshot.thatIsCompatibleWithNextSerializerAfterMigration(),
	};

	final TypeSerializer<?>[] testNewSerializers = new TypeSerializer<?>[] {
		new SchemaCompatibilityTestingSerializer(),
		new SchemaCompatibilityTestingSerializer(),
		new SchemaCompatibilityTestingSerializer(),
		new SchemaCompatibilityTestingSerializer()
	};

	IntermediateCompatibilityResult<?> intermediateCompatibilityResult =
		CompositeTypeSerializerUtil.constructIntermediateCompatibilityResult(testNewSerializers, testSerializerSnapshots);

	assertTrue(intermediateCompatibilityResult.isIncompatible());
	assertTrue(intermediateCompatibilityResult.getFinalResult().isIncompatible());
}
 
Example #16
Source File: PojoSerializerSnapshot.java    From Flink-CEPplus with Apache License 2.0 6 votes vote down vote up
/**
 * Creates a reconfigured version of the {@link PojoSerializer}.
 *
 * @param originalNewPojoSerializer the original new {@link PojoSerializer} to create a reconfigured version of.
 * @param fieldSerializerCompatibility compatibility of preexisting fields' serializers.
 * @param registeredSerializerSnapshots snapshot of previous registered subclasses' serializers.
 * @param preExistingRegistrationsCompatibility compatibility of preexisting subclasses' serializers.
 * @param nonRegisteredSubclassSerializerSnapshots snapshot of previous non-registered subclasses' serializers.
 *
 * @return a reconfigured version of the original new {@link PojoSerializer}.
 */
private static <T> PojoSerializer<T> constructReconfiguredPojoSerializer(
		PojoSerializer<T> originalNewPojoSerializer,
		IntermediateCompatibilityResult<T> fieldSerializerCompatibility,
		LinkedOptionalMap<Class<?>, TypeSerializerSnapshot<?>> registeredSerializerSnapshots,
		IntermediateCompatibilityResult<T> preExistingRegistrationsCompatibility,
		LinkedOptionalMap<Class<?>, TypeSerializerSnapshot<?>> nonRegisteredSubclassSerializerSnapshots) {

	@SuppressWarnings("unchecked")
	final TypeSerializer<Object>[] reconfiguredFieldSerializers = constructReconfiguredFieldSerializers(fieldSerializerCompatibility);

	Tuple2<LinkedHashMap<Class<?>, Integer>, TypeSerializer<Object>[]> reconfiguredSubclassRegistry = constructReconfiguredSubclassRegistry(
		originalNewPojoSerializer.getBundledSubclassSerializerRegistry(),
		registeredSerializerSnapshots,
		preExistingRegistrationsCompatibility);

	return new PojoSerializer<>(
		originalNewPojoSerializer.getPojoClass(),
		originalNewPojoSerializer.getFields(),
		reconfiguredFieldSerializers,
		reconfiguredSubclassRegistry.f0,
		reconfiguredSubclassRegistry.f1,
		restoreSerializers(nonRegisteredSubclassSerializerSnapshots.unwrapOptionals()),
		originalNewPojoSerializer.getExecutionConfig());
}
 
Example #17
Source File: CompositeTypeSerializerUtilTest.java    From flink with Apache License 2.0 6 votes vote down vote up
@Test
public void testCompatibleAfterMigrationIntermediateCompatibilityResult() {
	final TypeSerializerSnapshot<?>[] testSerializerSnapshots = new TypeSerializerSnapshot<?>[] {
		SchemaCompatibilityTestingSnapshot.thatIsCompatibleWithNextSerializerAfterReconfiguration("a"),
		SchemaCompatibilityTestingSnapshot.thatIsCompatibleWithNextSerializerAfterMigration("b"),
		SchemaCompatibilityTestingSnapshot.thatIsCompatibleWithNextSerializer("c"),
	};

	final TypeSerializer<?>[] testNewSerializers = new TypeSerializer<?>[] {
		new SchemaCompatibilityTestingSerializer("a"),
		new SchemaCompatibilityTestingSerializer("b"),
		new SchemaCompatibilityTestingSerializer("c")
	};

	IntermediateCompatibilityResult<?> intermediateCompatibilityResult =
		CompositeTypeSerializerUtil.constructIntermediateCompatibilityResult(testNewSerializers, testSerializerSnapshots);

	assertTrue(intermediateCompatibilityResult.isCompatibleAfterMigration());
	assertTrue(intermediateCompatibilityResult.getFinalResult().isCompatibleAfterMigration());
}
 
Example #18
Source File: CompositeTypeSerializerUtilTest.java    From flink with Apache License 2.0 6 votes vote down vote up
@Test
public void testIncompatibleIntermediateCompatibilityResult() {
	final TypeSerializerSnapshot<?>[] testSerializerSnapshots = new TypeSerializerSnapshot<?>[] {
		SchemaCompatibilityTestingSnapshot.thatIsCompatibleWithNextSerializer(),
		SchemaCompatibilityTestingSnapshot.thatIsIncompatibleWithTheNextSerializer(),
		SchemaCompatibilityTestingSnapshot.thatIsCompatibleWithNextSerializerAfterReconfiguration(),
		SchemaCompatibilityTestingSnapshot.thatIsCompatibleWithNextSerializerAfterMigration(),
	};

	final TypeSerializer<?>[] testNewSerializers = new TypeSerializer<?>[] {
		new SchemaCompatibilityTestingSerializer(),
		new SchemaCompatibilityTestingSerializer(),
		new SchemaCompatibilityTestingSerializer(),
		new SchemaCompatibilityTestingSerializer()
	};

	IntermediateCompatibilityResult<?> intermediateCompatibilityResult =
		CompositeTypeSerializerUtil.constructIntermediateCompatibilityResult(testNewSerializers, testSerializerSnapshots);

	assertTrue(intermediateCompatibilityResult.isIncompatible());
	assertTrue(intermediateCompatibilityResult.getFinalResult().isIncompatible());
}
 
Example #19
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 #20
Source File: CompositeTypeSerializerUtilTest.java    From flink with Apache License 2.0 5 votes vote down vote up
@Test(expected = IllegalStateException.class)
public void testGetNestedSerializersOnIncompatibleIntermediateCompatibilityResultFails() {
	IntermediateCompatibilityResult<Integer> intermediateCompatibilityResult =
		IntermediateCompatibilityResult.definedIncompatibleResult();

	intermediateCompatibilityResult.getNestedSerializers();
}
 
Example #21
Source File: PojoSerializerSnapshot.java    From Flink-CEPplus with Apache License 2.0 5 votes vote down vote up
/**
 * Finds which Pojo fields 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 those preexisting fields.
 */
private static <T> IntermediateCompatibilityResult<T> getCompatibilityOfPreExistingFields(
		PojoSerializer<T> newPojoSerializer,
		LinkedOptionalMap<Field, TypeSerializerSnapshot<?>> fieldSerializerSnapshots) {

	// the present entries dictates the preexisting fields, because removed fields would be
	// represented as absent keys in the optional map.
	final Set<LinkedOptionalMap.KeyValue<Field, TypeSerializerSnapshot<?>>> presentFieldSnapshots =
		fieldSerializerSnapshots.getPresentEntries();

	final ArrayList<TypeSerializerSnapshot<?>> associatedFieldSerializerSnapshots = new ArrayList<>(presentFieldSnapshots.size());
	final ArrayList<TypeSerializer<?>> associatedNewFieldSerializers = new ArrayList<>(presentFieldSnapshots.size());

	final Map<Field, TypeSerializer<?>> newFieldSerializersIndex = buildNewFieldSerializersIndex(newPojoSerializer);
	for (LinkedOptionalMap.KeyValue<Field, TypeSerializerSnapshot<?>> presentFieldEntry : presentFieldSnapshots) {
		TypeSerializer<?> associatedNewFieldSerializer = newFieldSerializersIndex.get(presentFieldEntry.getKey());
		checkState(
			associatedNewFieldSerializer != null,
			"a present field should have its associated new field serializer available.");

		associatedFieldSerializerSnapshots.add(presentFieldEntry.getValue());
		associatedNewFieldSerializers.add(associatedNewFieldSerializer);
	}

	return CompositeTypeSerializerUtil.constructIntermediateCompatibilityResult(
		associatedNewFieldSerializers.toArray(new TypeSerializer<?>[associatedNewFieldSerializers.size()]),
		associatedFieldSerializerSnapshots.toArray(new TypeSerializerSnapshot<?>[associatedFieldSerializerSnapshots.size()]));
}
 
Example #22
Source File: PojoSerializerSnapshot.java    From flink with Apache License 2.0 5 votes vote down vote up
/**
 * Finds which Pojo fields 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 those preexisting fields.
 */
private static <T> IntermediateCompatibilityResult<T> getCompatibilityOfPreExistingFields(
		PojoSerializer<T> newPojoSerializer,
		LinkedOptionalMap<Field, TypeSerializerSnapshot<?>> fieldSerializerSnapshots) {

	// the present entries dictates the preexisting fields, because removed fields would be
	// represented as absent keys in the optional map.
	final Set<LinkedOptionalMap.KeyValue<Field, TypeSerializerSnapshot<?>>> presentFieldSnapshots =
		fieldSerializerSnapshots.getPresentEntries();

	final ArrayList<TypeSerializerSnapshot<?>> associatedFieldSerializerSnapshots = new ArrayList<>(presentFieldSnapshots.size());
	final ArrayList<TypeSerializer<?>> associatedNewFieldSerializers = new ArrayList<>(presentFieldSnapshots.size());

	final Map<Field, TypeSerializer<?>> newFieldSerializersIndex = buildNewFieldSerializersIndex(newPojoSerializer);
	for (LinkedOptionalMap.KeyValue<Field, TypeSerializerSnapshot<?>> presentFieldEntry : presentFieldSnapshots) {
		TypeSerializer<?> associatedNewFieldSerializer = newFieldSerializersIndex.get(presentFieldEntry.getKey());
		checkState(
			associatedNewFieldSerializer != null,
			"a present field should have its associated new field serializer available.");

		associatedFieldSerializerSnapshots.add(presentFieldEntry.getValue());
		associatedNewFieldSerializers.add(associatedNewFieldSerializer);
	}

	return CompositeTypeSerializerUtil.constructIntermediateCompatibilityResult(
		associatedNewFieldSerializers.toArray(new TypeSerializer<?>[associatedNewFieldSerializers.size()]),
		associatedFieldSerializerSnapshots.toArray(new TypeSerializerSnapshot<?>[associatedFieldSerializerSnapshots.size()]));
}
 
Example #23
Source File: PojoSerializerSnapshot.java    From flink with Apache License 2.0 5 votes vote down vote up
/**
 * Checks if the new {@link PojoSerializer} is compatible after migration.
 */
private static <T> boolean newPojoSerializerIsCompatibleAfterMigration(
		PojoSerializer<T> newPojoSerializer,
		IntermediateCompatibilityResult<T> fieldSerializerCompatibility,
		IntermediateCompatibilityResult<T> preExistingRegistrationsCompatibility,
		LinkedOptionalMap<Field, TypeSerializerSnapshot<?>> fieldSerializerSnapshots) {
	return newPojoHasNewOrRemovedFields(fieldSerializerSnapshots, newPojoSerializer)
		|| fieldSerializerCompatibility.isCompatibleAfterMigration()
		|| preExistingRegistrationsCompatibility.isCompatibleAfterMigration();
}
 
Example #24
Source File: PojoSerializerSnapshot.java    From flink with Apache License 2.0 5 votes vote down vote up
/**
 * Checks if the new {@link PojoSerializer} is compatible with a reconfigured instance.
 */
private static <T> boolean newPojoSerializerIsCompatibleWithReconfiguredSerializer(
		PojoSerializer<T> newPojoSerializer,
		IntermediateCompatibilityResult<T> fieldSerializerCompatibility,
		IntermediateCompatibilityResult<T> preExistingRegistrationsCompatibility,
		LinkedOptionalMap<Class<?>, TypeSerializerSnapshot<?>> registeredSubclassSerializerSnapshots,
		LinkedOptionalMap<Class<?>, TypeSerializerSnapshot<?>> nonRegisteredSubclassSerializerSnapshots) {
	return newPojoHasDifferentSubclassRegistrationOrder(registeredSubclassSerializerSnapshots, newPojoSerializer)
		|| previousSerializerHasNonRegisteredSubclasses(nonRegisteredSubclassSerializerSnapshots)
		|| fieldSerializerCompatibility.isCompatibleWithReconfiguredSerializer()
		|| preExistingRegistrationsCompatibility.isCompatibleWithReconfiguredSerializer();
}
 
Example #25
Source File: CompositeTypeSerializerUtilTest.java    From flink with Apache License 2.0 5 votes vote down vote up
@Test(expected = IllegalStateException.class)
public void testGetFinalResultOnUndefinedReconfigureIntermediateCompatibilityResultFails() {
	IntermediateCompatibilityResult<Integer> intermediateCompatibilityResult =
		IntermediateCompatibilityResult.undefinedReconfigureResult(new TypeSerializer[]{ IntSerializer.INSTANCE });

	intermediateCompatibilityResult.getFinalResult();
}
 
Example #26
Source File: CompositeTypeSerializerUtilTest.java    From flink with Apache License 2.0 5 votes vote down vote up
@Test(expected = IllegalStateException.class)
public void testGetNestedSerializersOnCompatibleAfterMigrationIntermediateCompatibilityResultFails() {
	IntermediateCompatibilityResult<Integer> intermediateCompatibilityResult =
		IntermediateCompatibilityResult.definedCompatibleAfterMigrationResult();

	intermediateCompatibilityResult.getNestedSerializers();
}
 
Example #27
Source File: CompositeTypeSerializerUtilTest.java    From flink with Apache License 2.0 5 votes vote down vote up
@Test(expected = IllegalStateException.class)
public void testGetNestedSerializersOnIncompatibleIntermediateCompatibilityResultFails() {
	IntermediateCompatibilityResult<Integer> intermediateCompatibilityResult =
		IntermediateCompatibilityResult.definedIncompatibleResult();

	intermediateCompatibilityResult.getNestedSerializers();
}
 
Example #28
Source File: CompositeTypeSerializerUtilTest.java    From flink with Apache License 2.0 5 votes vote down vote up
@Test(expected = IllegalStateException.class)
public void testGetNestedSerializersOnCompatibleAfterMigrationIntermediateCompatibilityResultFails() {
	IntermediateCompatibilityResult<Integer> intermediateCompatibilityResult =
		IntermediateCompatibilityResult.definedCompatibleAfterMigrationResult();

	intermediateCompatibilityResult.getNestedSerializers();
}
 
Example #29
Source File: CompositeTypeSerializerUtilTest.java    From flink with Apache License 2.0 5 votes vote down vote up
@Test(expected = IllegalStateException.class)
public void testGetFinalResultOnUndefinedReconfigureIntermediateCompatibilityResultFails() {
	IntermediateCompatibilityResult<Integer> intermediateCompatibilityResult =
		IntermediateCompatibilityResult.undefinedReconfigureResult(new TypeSerializer[]{ IntSerializer.INSTANCE });

	intermediateCompatibilityResult.getFinalResult();
}
 
Example #30
Source File: PojoSerializerSnapshot.java    From flink with Apache License 2.0 5 votes vote down vote up
/**
 * Checks if the new {@link PojoSerializer} is compatible with a reconfigured instance.
 */
private static <T> boolean newPojoSerializerIsCompatibleWithReconfiguredSerializer(
		PojoSerializer<T> newPojoSerializer,
		IntermediateCompatibilityResult<T> fieldSerializerCompatibility,
		IntermediateCompatibilityResult<T> preExistingRegistrationsCompatibility,
		LinkedOptionalMap<Class<?>, TypeSerializerSnapshot<?>> registeredSubclassSerializerSnapshots,
		LinkedOptionalMap<Class<?>, TypeSerializerSnapshot<?>> nonRegisteredSubclassSerializerSnapshots) {
	return newPojoHasDifferentSubclassRegistrationOrder(registeredSubclassSerializerSnapshots, newPojoSerializer)
		|| previousSerializerHasNonRegisteredSubclasses(nonRegisteredSubclassSerializerSnapshots)
		|| fieldSerializerCompatibility.isCompatibleWithReconfiguredSerializer()
		|| preExistingRegistrationsCompatibility.isCompatibleWithReconfiguredSerializer();
}