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

The following examples show how to use org.apache.flink.api.common.typeutils.TypeSerializerSchemaCompatibility#compatibleAsIs() . 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: MapDataSerializer.java    From flink with Apache License 2.0 6 votes vote down vote up
@Override
public TypeSerializerSchemaCompatibility<MapData> resolveSchemaCompatibility(TypeSerializer<MapData> newSerializer) {
	if (!(newSerializer instanceof MapDataSerializer)) {
		return TypeSerializerSchemaCompatibility.incompatible();
	}

	MapDataSerializer newBaseMapSerializer = (MapDataSerializer) newSerializer;
	if (!previousKeyType.equals(newBaseMapSerializer.keyType) ||
		!previousValueType.equals(newBaseMapSerializer.valueType) ||
		!previousKeySerializer.equals(newBaseMapSerializer.keySerializer) ||
		!previousValueSerializer.equals(newBaseMapSerializer.valueSerializer)) {
		return TypeSerializerSchemaCompatibility.incompatible();
	} else {
		return TypeSerializerSchemaCompatibility.compatibleAsIs();
	}
}
 
Example 2
Source File: MapDataSerializer.java    From flink with Apache License 2.0 6 votes vote down vote up
@Override
public TypeSerializerSchemaCompatibility<MapData> resolveSchemaCompatibility(TypeSerializer<MapData> newSerializer) {
	if (!(newSerializer instanceof MapDataSerializer)) {
		return TypeSerializerSchemaCompatibility.incompatible();
	}

	MapDataSerializer newMapDataSerializer = (MapDataSerializer) newSerializer;
	if (!previousKeyType.equals(newMapDataSerializer.keyType) ||
		!previousValueType.equals(newMapDataSerializer.valueType) ||
		!previousKeySerializer.equals(newMapDataSerializer.keyTypeSerializer) ||
		!previousValueSerializer.equals(newMapDataSerializer.valueTypeSerializer)) {
		return TypeSerializerSchemaCompatibility.incompatible();
	} else {
		return TypeSerializerSchemaCompatibility.compatibleAsIs();
	}
}
 
Example 3
Source File: V2TestTypeSerializerSnapshot.java    From flink with Apache License 2.0 6 votes vote down vote up
@Override
public TypeSerializerSchemaCompatibility<TestType> resolveSchemaCompatibility(TypeSerializer<TestType> newSerializer) {
	if (newSerializer instanceof TestType.V2TestTypeSerializer) {
		return TypeSerializerSchemaCompatibility.compatibleAsIs();
	} else if (newSerializer instanceof TestType.ReconfigurationRequiringTestTypeSerializer) {
		// we mimic the reconfiguration by just re-instantiating the correct serializer
		return TypeSerializerSchemaCompatibility.compatibleWithReconfiguredSerializer(new TestType.V2TestTypeSerializer());
	} else if (
		// migrating from V2 -> V1 is not supported
		newSerializer instanceof TestType.V1TestTypeSerializer
			|| newSerializer instanceof TestType.IncompatibleTestTypeSerializer) {

		return TypeSerializerSchemaCompatibility.incompatible();
	} else {
		throw new IllegalStateException("Unknown serializer class for TestType.");
	}
}
 
Example 4
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 5
Source File: EnumSerializer.java    From flink with Apache License 2.0 5 votes vote down vote up
@Override
public TypeSerializerSchemaCompatibility<T> resolveSchemaCompatibility(TypeSerializer<T> newSerializer) {
	if (!(newSerializer instanceof EnumSerializer)) {
		return TypeSerializerSchemaCompatibility.incompatible();
	}

	EnumSerializer<T> newEnumSerializer = (EnumSerializer<T>) newSerializer;
	if (!enumClass.equals(newEnumSerializer.enumClass)) {
		return TypeSerializerSchemaCompatibility.incompatible();
	}

	T[] currentEnums = enumClass.getEnumConstants();

	if (Arrays.equals(previousEnums, currentEnums)) {
		return TypeSerializerSchemaCompatibility.compatibleAsIs();
	}

	Set<T> reconfiguredEnumSet = new LinkedHashSet<>(Arrays.asList(previousEnums));
	reconfiguredEnumSet.addAll(Arrays.asList(currentEnums));

	@SuppressWarnings("unchecked")
	T[] reconfiguredEnums = reconfiguredEnumSet.toArray(
			(T[]) Array.newInstance(enumClass, reconfiguredEnumSet.size()));

	EnumSerializer<T> reconfiguredSerializer = new EnumSerializer<>(
			enumClass,
			reconfiguredEnums);
	return TypeSerializerSchemaCompatibility.compatibleWithReconfiguredSerializer(
			reconfiguredSerializer);
}
 
Example 6
Source File: TimestampDataSerializer.java    From flink with Apache License 2.0 5 votes vote down vote up
@Override
public TypeSerializerSchemaCompatibility<TimestampData> resolveSchemaCompatibility(TypeSerializer<TimestampData> newSerializer) {
	if (!(newSerializer instanceof TimestampDataSerializer)) {
		return TypeSerializerSchemaCompatibility.incompatible();
	}

	TimestampDataSerializer timestampDataSerializer = (TimestampDataSerializer) newSerializer;
	if (previousPrecision != timestampDataSerializer.precision) {
		return TypeSerializerSchemaCompatibility.incompatible();
	} else {
		return TypeSerializerSchemaCompatibility.compatibleAsIs();
	}
}
 
Example 7
Source File: InternalPriorityQueueTestBase.java    From Flink-CEPplus with Apache License 2.0 5 votes vote down vote up
@Override
public TypeSerializerSchemaCompatibility<TestElement> resolveSchemaCompatibility(TypeSerializer<TestElement> newSerializer) {
	if (!(newSerializer instanceof TestElementSerializer)) {
		return TypeSerializerSchemaCompatibility.incompatible();
	}

	TestElementSerializer testElementSerializer = (TestElementSerializer) newSerializer;
	return (revision <= testElementSerializer.getRevision())
		? TypeSerializerSchemaCompatibility.compatibleAsIs()
		: TypeSerializerSchemaCompatibility.incompatible();
}
 
Example 8
Source File: MessageTypeSerializer.java    From flink-statefun with Apache License 2.0 5 votes vote down vote up
@Override
public TypeSerializerSchemaCompatibility<Message> resolveSchemaCompatibility(
    TypeSerializer<Message> typeSerializer) {
  if (!(typeSerializer instanceof MessageTypeSerializer)) {
    return TypeSerializerSchemaCompatibility.incompatible();
  }
  MessageTypeSerializer casted = (MessageTypeSerializer) typeSerializer;
  if (casted.messageFactoryType == messageFactoryType) {
    return TypeSerializerSchemaCompatibility.compatibleAsIs();
  }
  return TypeSerializerSchemaCompatibility.incompatible();
}
 
Example 9
Source File: ProtobufTypeSerializerSnapshot.java    From flink-statefun with Apache License 2.0 5 votes vote down vote up
/**
 * Check schema compatibility with the new serializer.
 *
 * <p>This check is very simplistic, that just compares the two typeClasses, but the {@link
 * ProtobufSerializerSnapshot} has much more information to be used for compatibility resolution.
 * We make sure to store this information first, and implement a more robust schema resolution
 * logic in the future.
 */
private TypeSerializerSchemaCompatibility<M> resolveSchemaCompatibility(
    ProtobufTypeSerializer<?> newSerializer) {
  Class<?> otherTypeClass = newSerializer.getTypeClass();
  if (otherTypeClass == typeClass) {
    return TypeSerializerSchemaCompatibility.compatibleAsIs();
  }
  return TypeSerializerSchemaCompatibility.incompatible();
}
 
Example 10
Source File: SortedMapSerializerSnapshot.java    From flink with Apache License 2.0 5 votes vote down vote up
@Override
public TypeSerializerSchemaCompatibility<SortedMap<K, V>> resolveSchemaCompatibility(
		TypeSerializer<SortedMap<K, V>> newSerializer) {
	if (!(newSerializer instanceof SortedMapSerializer)) {
		return TypeSerializerSchemaCompatibility.incompatible();
	}
	SortedMapSerializer newSortedMapSerializer = (SortedMapSerializer) newSerializer;
	if (!comparator.equals(newSortedMapSerializer.getComparator())) {
		return TypeSerializerSchemaCompatibility.incompatible();
	} else {
		return TypeSerializerSchemaCompatibility.compatibleAsIs();
	}
}
 
Example 11
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 12
Source File: InternalPriorityQueueTestBase.java    From flink with Apache License 2.0 5 votes vote down vote up
@Override
public TypeSerializerSchemaCompatibility<TestElement> resolveSchemaCompatibility(TypeSerializer<TestElement> newSerializer) {
	if (!(newSerializer instanceof TestElementSerializer)) {
		return TypeSerializerSchemaCompatibility.incompatible();
	}

	TestElementSerializer testElementSerializer = (TestElementSerializer) newSerializer;
	return (revision <= testElementSerializer.getRevision())
		? TypeSerializerSchemaCompatibility.compatibleAsIs()
		: TypeSerializerSchemaCompatibility.incompatible();
}
 
Example 13
Source File: TimestampSerializer.java    From flink with Apache License 2.0 5 votes vote down vote up
@Override
public TypeSerializerSchemaCompatibility<Timestamp> resolveSchemaCompatibility(TypeSerializer<Timestamp> newSerializer) {
	if (!(newSerializer instanceof TimestampSerializer)) {
		return TypeSerializerSchemaCompatibility.incompatible();
	}

	TimestampSerializer timestampSerializer = (TimestampSerializer) newSerializer;
	if (previousPrecision != timestampSerializer.precision) {
		return TypeSerializerSchemaCompatibility.incompatible();
	} else {
		return TypeSerializerSchemaCompatibility.compatibleAsIs();
	}
}
 
Example 14
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 15
Source File: SchemaCompatibilityTestingSerializer.java    From flink with Apache License 2.0 4 votes vote down vote up
public static SchemaCompatibilityTestingSnapshot thatIsCompatibleWithNextSerializer(String tokenForEqualityChecks) {
	return new SchemaCompatibilityTestingSnapshot(tokenForEqualityChecks, unused -> TypeSerializerSchemaCompatibility.compatibleAsIs());
}
 
Example 16
Source File: SchemaCompatibilityTestingSerializer.java    From flink with Apache License 2.0 4 votes vote down vote up
public static SchemaCompatibilityTestingSnapshot thatIsCompatibleWithNextSerializer(String tokenForEqualityChecks) {
	return new SchemaCompatibilityTestingSnapshot(tokenForEqualityChecks, unused -> TypeSerializerSchemaCompatibility.compatibleAsIs());
}
 
Example 17
Source File: StateBackendMigrationTestBase.java    From flink with Apache License 2.0 4 votes vote down vote up
@Override
public TypeSerializerSchemaCompatibility<VoidNamespace>
resolveSchemaCompatibility(TypeSerializer<VoidNamespace> newSerializer) {
	return TypeSerializerSchemaCompatibility.compatibleAsIs();
}
 
Example 18
Source File: StateBackendMigrationTestBase.java    From Flink-CEPplus with Apache License 2.0 4 votes vote down vote up
@Override
public TypeSerializerSchemaCompatibility<VoidNamespace>
resolveSchemaCompatibility(TypeSerializer<VoidNamespace> newSerializer) {
	return TypeSerializerSchemaCompatibility.compatibleAsIs();
}
 
Example 19
Source File: SchemaCompatibilityTestingSerializer.java    From Flink-CEPplus with Apache License 2.0 4 votes vote down vote up
public static SchemaCompatibilityTestingSnapshot thatIsCompatibleWithNextSerializer(String tokenForEqualityChecks) {
	return new SchemaCompatibilityTestingSnapshot(tokenForEqualityChecks, unused -> TypeSerializerSchemaCompatibility.compatibleAsIs());
}
 
Example 20
Source File: TypeSerializerSnapshotMigrationITCase.java    From Flink-CEPplus with Apache License 2.0 4 votes vote down vote up
@Override
public TypeSerializerSchemaCompatibility<Long> resolveSchemaCompatibility(TypeSerializer<Long> newSerializer) {
	return (newSerializer instanceof TestSerializer)
		? TypeSerializerSchemaCompatibility.compatibleAsIs()
		: TypeSerializerSchemaCompatibility.incompatible();
}