Java Code Examples for org.apache.flink.api.common.typeutils.TypeSerializerSchemaCompatibility#compatibleAfterMigration()

The following examples show how to use org.apache.flink.api.common.typeutils.TypeSerializerSchemaCompatibility#compatibleAfterMigration() . 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: AvroSerializerSnapshot.java    From Flink-CEPplus with Apache License 2.0 6 votes vote down vote up
private static <T> TypeSerializerSchemaCompatibility<T>
avroCompatibilityToFlinkCompatibility(SchemaPairCompatibility compatibility) {

	switch (compatibility.getType()) {
		case COMPATIBLE: {
			// The new serializer would be able to read data persisted with *this* serializer, therefore no migration
			// is required.
			return TypeSerializerSchemaCompatibility.compatibleAfterMigration();
		}
		case INCOMPATIBLE: {
			return TypeSerializerSchemaCompatibility.incompatible();
		}
		case RECURSION_IN_PROGRESS:
		default:
			return TypeSerializerSchemaCompatibility.incompatible();
	}
}
 
Example 2
Source File: AvroSerializerSnapshot.java    From flink with Apache License 2.0 6 votes vote down vote up
private static <T> TypeSerializerSchemaCompatibility<T>
avroCompatibilityToFlinkCompatibility(SchemaPairCompatibility compatibility) {

	switch (compatibility.getType()) {
		case COMPATIBLE: {
			// The new serializer would be able to read data persisted with *this* serializer, therefore no migration
			// is required.
			return TypeSerializerSchemaCompatibility.compatibleAfterMigration();
		}
		case INCOMPATIBLE: {
			return TypeSerializerSchemaCompatibility.incompatible();
		}
		case RECURSION_IN_PROGRESS:
		default:
			return TypeSerializerSchemaCompatibility.incompatible();
	}
}
 
Example 3
Source File: AvroSerializerSnapshot.java    From flink with Apache License 2.0 6 votes vote down vote up
private static <T> TypeSerializerSchemaCompatibility<T>
avroCompatibilityToFlinkCompatibility(SchemaPairCompatibility compatibility) {

	switch (compatibility.getType()) {
		case COMPATIBLE: {
			// The new serializer would be able to read data persisted with *this* serializer, therefore no migration
			// is required.
			return TypeSerializerSchemaCompatibility.compatibleAfterMigration();
		}
		case INCOMPATIBLE: {
			return TypeSerializerSchemaCompatibility.incompatible();
		}
		case RECURSION_IN_PROGRESS:
		default:
			return TypeSerializerSchemaCompatibility.incompatible();
	}
}
 
Example 4
Source File: V1TestTypeSerializerSnapshot.java    From Flink-CEPplus with Apache License 2.0 5 votes vote down vote up
@Override
public TypeSerializerSchemaCompatibility<TestType> resolveSchemaCompatibility(TypeSerializer<TestType> newSerializer) {
	if (newSerializer instanceof TestType.V1TestTypeSerializer) {
		return TypeSerializerSchemaCompatibility.compatibleAsIs();
	} else if (newSerializer instanceof TestType.V2TestTypeSerializer) {
		return TypeSerializerSchemaCompatibility.compatibleAfterMigration();
	} else if (newSerializer instanceof TestType.ReconfigurationRequiringTestTypeSerializer) {
		// we mimic the reconfiguration by just re-instantiating the correct serializer
		return TypeSerializerSchemaCompatibility.compatibleWithReconfiguredSerializer(new TestType.V1TestTypeSerializer());
	} else if (newSerializer instanceof TestType.IncompatibleTestTypeSerializer) {
		return TypeSerializerSchemaCompatibility.incompatible();
	} else {
		throw new IllegalStateException("Unknown serializer class for TestType.");
	}
}
 
Example 5
Source File: V1TestTypeSerializerSnapshot.java    From flink with Apache License 2.0 5 votes vote down vote up
@Override
public TypeSerializerSchemaCompatibility<TestType> resolveSchemaCompatibility(TypeSerializer<TestType> newSerializer) {
	if (newSerializer instanceof TestType.V1TestTypeSerializer) {
		return TypeSerializerSchemaCompatibility.compatibleAsIs();
	} else if (newSerializer instanceof TestType.V2TestTypeSerializer) {
		return TypeSerializerSchemaCompatibility.compatibleAfterMigration();
	} else if (newSerializer instanceof TestType.ReconfigurationRequiringTestTypeSerializer) {
		// we mimic the reconfiguration by just re-instantiating the correct serializer
		return TypeSerializerSchemaCompatibility.compatibleWithReconfiguredSerializer(new TestType.V1TestTypeSerializer());
	} else if (newSerializer instanceof TestType.IncompatibleTestTypeSerializer) {
		return TypeSerializerSchemaCompatibility.incompatible();
	} else {
		throw new IllegalStateException("Unknown serializer class for TestType.");
	}
}
 
Example 6
Source File: EncodedValueSerializer.java    From beam with Apache License 2.0 5 votes vote down vote up
@Override
public TypeSerializerSnapshot<byte[]> snapshotConfiguration() {
  return new TypeSerializerSnapshot<byte[]>() {
    @Override
    public int getCurrentVersion() {
      return 1;
    }

    @Override
    public void writeSnapshot(DataOutputView out) throws IOException {}

    @Override
    public void readSnapshot(int readVersion, DataInputView in, ClassLoader userCodeClassLoader)
        throws IOException {}

    @Override
    public TypeSerializer<byte[]> restoreSerializer() {
      return new EncodedValueSerializer();
    }

    @Override
    public TypeSerializerSchemaCompatibility<byte[]> resolveSchemaCompatibility(
        TypeSerializer<byte[]> newSerializer) {
      return newSerializer instanceof EncodedValueSerializer
          ? TypeSerializerSchemaCompatibility.compatibleAsIs()
          : TypeSerializerSchemaCompatibility.compatibleAfterMigration();
    }
  };
}
 
Example 7
Source File: V1TestTypeSerializerSnapshot.java    From flink with Apache License 2.0 5 votes vote down vote up
@Override
public TypeSerializerSchemaCompatibility<TestType> resolveSchemaCompatibility(TypeSerializer<TestType> newSerializer) {
	if (newSerializer instanceof TestType.V1TestTypeSerializer) {
		return TypeSerializerSchemaCompatibility.compatibleAsIs();
	} else if (newSerializer instanceof TestType.V2TestTypeSerializer) {
		return TypeSerializerSchemaCompatibility.compatibleAfterMigration();
	} else if (newSerializer instanceof TestType.ReconfigurationRequiringTestTypeSerializer) {
		// we mimic the reconfiguration by just re-instantiating the correct serializer
		return TypeSerializerSchemaCompatibility.compatibleWithReconfiguredSerializer(new TestType.V1TestTypeSerializer());
	} else if (newSerializer instanceof TestType.IncompatibleTestTypeSerializer) {
		return TypeSerializerSchemaCompatibility.incompatible();
	} else {
		throw new IllegalStateException("Unknown serializer class for TestType.");
	}
}
 
Example 8
Source File: PojoSerializerSnapshot.java    From Flink-CEPplus with Apache License 2.0 4 votes vote down vote up
@Override
public TypeSerializerSchemaCompatibility<T> resolveSchemaCompatibility(TypeSerializer<T> newSerializer) {
	if (newSerializer.getClass() != PojoSerializer.class) {
		return TypeSerializerSchemaCompatibility.incompatible();
	}

	final PojoSerializer<T> newPojoSerializer = (PojoSerializer<T>) newSerializer;

	final Class<T> previousPojoClass = snapshotData.getPojoClass();
	final LinkedOptionalMap<Field, TypeSerializerSnapshot<?>> fieldSerializerSnapshots = snapshotData.getFieldSerializerSnapshots();
	final LinkedOptionalMap<Class<?>, TypeSerializerSnapshot<?>> registeredSubclassSerializerSnapshots = snapshotData.getRegisteredSubclassSerializerSnapshots();
	final LinkedOptionalMap<Class<?>, TypeSerializerSnapshot<?>> nonRegisteredSubclassSerializerSnapshots = snapshotData.getNonRegisteredSubclassSerializerSnapshots();

	if (previousPojoClass != newPojoSerializer.getPojoClass()) {
		return TypeSerializerSchemaCompatibility.incompatible();
	}

	if (registeredSubclassSerializerSnapshots.hasAbsentKeysOrValues()) {
		return TypeSerializerSchemaCompatibility.incompatible();
	}

	if (nonRegisteredSubclassSerializerSnapshots.hasAbsentKeysOrValues()) {
		return TypeSerializerSchemaCompatibility.incompatible();
	}

	final IntermediateCompatibilityResult<T> preExistingFieldSerializersCompatibility =
		getCompatibilityOfPreExistingFields(newPojoSerializer, fieldSerializerSnapshots);

	if (preExistingFieldSerializersCompatibility.isIncompatible()) {
		return TypeSerializerSchemaCompatibility.incompatible();
	}

	final IntermediateCompatibilityResult<T> preExistingRegistrationsCompatibility =
		getCompatibilityOfPreExistingRegisteredSubclasses(newPojoSerializer, registeredSubclassSerializerSnapshots);

	if (preExistingRegistrationsCompatibility.isIncompatible()) {
		return TypeSerializerSchemaCompatibility.incompatible();
	}

	if (newPojoSerializerIsCompatibleAfterMigration(
			newPojoSerializer,
			preExistingFieldSerializersCompatibility,
			preExistingRegistrationsCompatibility,
			fieldSerializerSnapshots)) {

		return TypeSerializerSchemaCompatibility.compatibleAfterMigration();
	}

	if (newPojoSerializerIsCompatibleWithReconfiguredSerializer(
			newPojoSerializer,
			preExistingFieldSerializersCompatibility,
			preExistingRegistrationsCompatibility,
			registeredSubclassSerializerSnapshots,
			nonRegisteredSubclassSerializerSnapshots)) {

		return TypeSerializerSchemaCompatibility.compatibleWithReconfiguredSerializer(
			constructReconfiguredPojoSerializer(
				newPojoSerializer,
				preExistingFieldSerializersCompatibility,
				registeredSubclassSerializerSnapshots,
				preExistingRegistrationsCompatibility,
				nonRegisteredSubclassSerializerSnapshots));
	}

	return TypeSerializerSchemaCompatibility.compatibleAsIs();
}
 
Example 9
Source File: SchemaCompatibilityTestingSerializer.java    From Flink-CEPplus with Apache License 2.0 4 votes vote down vote up
public static SchemaCompatibilityTestingSnapshot thatIsCompatibleWithNextSerializerAfterMigration(String tokenForEqualityChecks) {
	return new SchemaCompatibilityTestingSnapshot(tokenForEqualityChecks, unused -> TypeSerializerSchemaCompatibility.compatibleAfterMigration());
}
 
Example 10
Source File: PojoSerializerSnapshot.java    From flink with Apache License 2.0 4 votes vote down vote up
@Override
public TypeSerializerSchemaCompatibility<T> resolveSchemaCompatibility(TypeSerializer<T> newSerializer) {
	if (newSerializer.getClass() != PojoSerializer.class) {
		return TypeSerializerSchemaCompatibility.incompatible();
	}

	final PojoSerializer<T> newPojoSerializer = (PojoSerializer<T>) newSerializer;

	final Class<T> previousPojoClass = snapshotData.getPojoClass();
	final LinkedOptionalMap<Field, TypeSerializerSnapshot<?>> fieldSerializerSnapshots = snapshotData.getFieldSerializerSnapshots();
	final LinkedOptionalMap<Class<?>, TypeSerializerSnapshot<?>> registeredSubclassSerializerSnapshots = snapshotData.getRegisteredSubclassSerializerSnapshots();
	final LinkedOptionalMap<Class<?>, TypeSerializerSnapshot<?>> nonRegisteredSubclassSerializerSnapshots = snapshotData.getNonRegisteredSubclassSerializerSnapshots();

	if (previousPojoClass != newPojoSerializer.getPojoClass()) {
		return TypeSerializerSchemaCompatibility.incompatible();
	}

	if (registeredSubclassSerializerSnapshots.hasAbsentKeysOrValues()) {
		return TypeSerializerSchemaCompatibility.incompatible();
	}

	if (nonRegisteredSubclassSerializerSnapshots.hasAbsentKeysOrValues()) {
		return TypeSerializerSchemaCompatibility.incompatible();
	}

	final IntermediateCompatibilityResult<T> preExistingFieldSerializersCompatibility =
		getCompatibilityOfPreExistingFields(newPojoSerializer, fieldSerializerSnapshots);

	if (preExistingFieldSerializersCompatibility.isIncompatible()) {
		return TypeSerializerSchemaCompatibility.incompatible();
	}

	final IntermediateCompatibilityResult<T> preExistingRegistrationsCompatibility =
		getCompatibilityOfPreExistingRegisteredSubclasses(newPojoSerializer, registeredSubclassSerializerSnapshots);

	if (preExistingRegistrationsCompatibility.isIncompatible()) {
		return TypeSerializerSchemaCompatibility.incompatible();
	}

	if (newPojoSerializerIsCompatibleAfterMigration(
			newPojoSerializer,
			preExistingFieldSerializersCompatibility,
			preExistingRegistrationsCompatibility,
			fieldSerializerSnapshots)) {

		return TypeSerializerSchemaCompatibility.compatibleAfterMigration();
	}

	if (newPojoSerializerIsCompatibleWithReconfiguredSerializer(
			newPojoSerializer,
			preExistingFieldSerializersCompatibility,
			preExistingRegistrationsCompatibility,
			registeredSubclassSerializerSnapshots,
			nonRegisteredSubclassSerializerSnapshots)) {

		return TypeSerializerSchemaCompatibility.compatibleWithReconfiguredSerializer(
			constructReconfiguredPojoSerializer(
				newPojoSerializer,
				preExistingFieldSerializersCompatibility,
				registeredSubclassSerializerSnapshots,
				preExistingRegistrationsCompatibility,
				nonRegisteredSubclassSerializerSnapshots));
	}

	return TypeSerializerSchemaCompatibility.compatibleAsIs();
}
 
Example 11
Source File: SchemaCompatibilityTestingSerializer.java    From flink with Apache License 2.0 4 votes vote down vote up
public static SchemaCompatibilityTestingSnapshot thatIsCompatibleWithNextSerializerAfterMigration(String tokenForEqualityChecks) {
	return new SchemaCompatibilityTestingSnapshot(tokenForEqualityChecks, unused -> TypeSerializerSchemaCompatibility.compatibleAfterMigration());
}
 
Example 12
Source File: PojoSerializerSnapshot.java    From flink with Apache License 2.0 4 votes vote down vote up
@Override
public TypeSerializerSchemaCompatibility<T> resolveSchemaCompatibility(TypeSerializer<T> newSerializer) {
	if (newSerializer.getClass() != PojoSerializer.class) {
		return TypeSerializerSchemaCompatibility.incompatible();
	}

	final PojoSerializer<T> newPojoSerializer = (PojoSerializer<T>) newSerializer;

	final Class<T> previousPojoClass = snapshotData.getPojoClass();
	final LinkedOptionalMap<Field, TypeSerializerSnapshot<?>> fieldSerializerSnapshots = snapshotData.getFieldSerializerSnapshots();
	final LinkedOptionalMap<Class<?>, TypeSerializerSnapshot<?>> registeredSubclassSerializerSnapshots = snapshotData.getRegisteredSubclassSerializerSnapshots();
	final LinkedOptionalMap<Class<?>, TypeSerializerSnapshot<?>> nonRegisteredSubclassSerializerSnapshots = snapshotData.getNonRegisteredSubclassSerializerSnapshots();

	if (previousPojoClass != newPojoSerializer.getPojoClass()) {
		return TypeSerializerSchemaCompatibility.incompatible();
	}

	if (registeredSubclassSerializerSnapshots.hasAbsentKeysOrValues()) {
		return TypeSerializerSchemaCompatibility.incompatible();
	}

	if (nonRegisteredSubclassSerializerSnapshots.hasAbsentKeysOrValues()) {
		return TypeSerializerSchemaCompatibility.incompatible();
	}

	final IntermediateCompatibilityResult<T> preExistingFieldSerializersCompatibility =
		getCompatibilityOfPreExistingFields(newPojoSerializer, fieldSerializerSnapshots);

	if (preExistingFieldSerializersCompatibility.isIncompatible()) {
		return TypeSerializerSchemaCompatibility.incompatible();
	}

	final IntermediateCompatibilityResult<T> preExistingRegistrationsCompatibility =
		getCompatibilityOfPreExistingRegisteredSubclasses(newPojoSerializer, registeredSubclassSerializerSnapshots);

	if (preExistingRegistrationsCompatibility.isIncompatible()) {
		return TypeSerializerSchemaCompatibility.incompatible();
	}

	if (newPojoSerializerIsCompatibleAfterMigration(
			newPojoSerializer,
			preExistingFieldSerializersCompatibility,
			preExistingRegistrationsCompatibility,
			fieldSerializerSnapshots)) {

		return TypeSerializerSchemaCompatibility.compatibleAfterMigration();
	}

	if (newPojoSerializerIsCompatibleWithReconfiguredSerializer(
			newPojoSerializer,
			preExistingFieldSerializersCompatibility,
			preExistingRegistrationsCompatibility,
			registeredSubclassSerializerSnapshots,
			nonRegisteredSubclassSerializerSnapshots)) {

		return TypeSerializerSchemaCompatibility.compatibleWithReconfiguredSerializer(
			constructReconfiguredPojoSerializer(
				newPojoSerializer,
				preExistingFieldSerializersCompatibility,
				registeredSubclassSerializerSnapshots,
				preExistingRegistrationsCompatibility,
				nonRegisteredSubclassSerializerSnapshots));
	}

	return TypeSerializerSchemaCompatibility.compatibleAsIs();
}
 
Example 13
Source File: SchemaCompatibilityTestingSerializer.java    From flink with Apache License 2.0 4 votes vote down vote up
public static SchemaCompatibilityTestingSnapshot thatIsCompatibleWithNextSerializerAfterMigration(String tokenForEqualityChecks) {
	return new SchemaCompatibilityTestingSnapshot(tokenForEqualityChecks, unused -> TypeSerializerSchemaCompatibility.compatibleAfterMigration());
}