Java Code Examples for org.apache.flink.api.common.typeutils.CompositeTypeSerializerUtil#setNestedSerializersSnapshots()

The following examples show how to use org.apache.flink.api.common.typeutils.CompositeTypeSerializerUtil#setNestedSerializersSnapshots() . 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: 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 2
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 3
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 4
Source File: MapViewSerializer.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 map serializer as its own snapshot.
 *
 * <p>This method transforms the incorrect map serializer snapshot
 * to be a proper {@link MapViewSerializerSnapshot}.
 */
@Override
public <U> TypeSerializerSnapshot<MapView<K, V>> transformLegacySerializerSnapshot(
		TypeSerializerSnapshot<U> legacySnapshot) {
	if (legacySnapshot instanceof MapViewSerializerSnapshot) {
		return (TypeSerializerSnapshot<MapView<K, V>>) legacySnapshot;
	} else if (legacySnapshot instanceof MapSerializerConfigSnapshot) {
		// first, transform the incorrect map serializer's snapshot
		// into a proper ListSerializerSnapshot
		MapSerializerSnapshot<K, V> transformedNestedMapSerializerSnapshot = new MapSerializerSnapshot<>();
		MapSerializerConfigSnapshot<K, V> snapshot = (MapSerializerConfigSnapshot<K, V>) legacySnapshot;
		CompositeTypeSerializerUtil.setNestedSerializersSnapshots(
				transformedNestedMapSerializerSnapshot,
				snapshot.getNestedSerializersAndConfigs().get(0).f1,
				snapshot.getNestedSerializersAndConfigs().get(1).f1
		);

		// then, wrap the transformed MapSerializerSnapshot
		// as a nested snapshot in the final resulting MapViewSerializerSnapshot
		MapViewSerializerSnapshot<K, V> transformedMapViewSerializerSnapshot = new MapViewSerializerSnapshot<>();
		CompositeTypeSerializerUtil.setNestedSerializersSnapshots(
				transformedMapViewSerializerSnapshot,
				transformedNestedMapSerializerSnapshot
		);

		return transformedMapViewSerializerSnapshot;
	} else {
		throw new UnsupportedOperationException(
				legacySnapshot.getClass().getCanonicalName() + " is not supported.");
	}
}
 
Example 5
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 6
Source File: MapViewSerializer.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 map serializer as its own snapshot.
 *
 * <p>This method transforms the incorrect map serializer snapshot
 * to be a proper {@link MapViewSerializerSnapshot}.
 */
@Override
public <U> TypeSerializerSnapshot<MapView<K, V>> transformLegacySerializerSnapshot(
		TypeSerializerSnapshot<U> legacySnapshot) {
	if (legacySnapshot instanceof MapViewSerializerSnapshot) {
		return (TypeSerializerSnapshot<MapView<K, V>>) legacySnapshot;
	} else if (legacySnapshot instanceof MapSerializerConfigSnapshot) {
		// first, transform the incorrect map serializer's snapshot
		// into a proper ListSerializerSnapshot
		MapSerializerSnapshot<K, V> transformedNestedMapSerializerSnapshot = new MapSerializerSnapshot<>();
		MapSerializerConfigSnapshot<K, V> snapshot = (MapSerializerConfigSnapshot<K, V>) legacySnapshot;
		CompositeTypeSerializerUtil.setNestedSerializersSnapshots(
				transformedNestedMapSerializerSnapshot,
				snapshot.getNestedSerializersAndConfigs().get(0).f1,
				snapshot.getNestedSerializersAndConfigs().get(1).f1
		);

		// then, wrap the transformed MapSerializerSnapshot
		// as a nested snapshot in the final resulting MapViewSerializerSnapshot
		MapViewSerializerSnapshot<K, V> transformedMapViewSerializerSnapshot = new MapViewSerializerSnapshot<>();
		CompositeTypeSerializerUtil.setNestedSerializersSnapshots(
				transformedMapViewSerializerSnapshot,
				transformedNestedMapSerializerSnapshot
		);

		return transformedMapViewSerializerSnapshot;
	} else {
		throw new UnsupportedOperationException(
				legacySnapshot.getClass().getCanonicalName() + " is not supported.");
	}
}
 
Example 7
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.");
	}
}