You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@flink.apache.org by tz...@apache.org on 2019/02/14 09:03:38 UTC

[flink] 06/07: [FLINK-11591] [core] Allow injecting nested serializer snapshots via CompositeTypeSerializerUtil

This is an automated email from the ASF dual-hosted git repository.

tzulitai pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/flink.git

commit 978f190118b3cd3a7c8899e943a19412d1af1274
Author: Igal Shilman <ig...@data-artisans.com>
AuthorDate: Wed Feb 13 15:15:18 2019 +0100

    [FLINK-11591] [core] Allow injecting nested serializer snapshots via CompositeTypeSerializerUtil
---
 .../common/typeutils/CompositeTypeSerializerSnapshot.java  | 11 +++++++++--
 .../api/common/typeutils/CompositeTypeSerializerUtil.java  | 14 ++++++++++++++
 .../typeutils/NestedSerializersSnapshotDelegate.java       |  6 ++++--
 3 files changed, 27 insertions(+), 4 deletions(-)

diff --git a/flink-core/src/main/java/org/apache/flink/api/common/typeutils/CompositeTypeSerializerSnapshot.java b/flink-core/src/main/java/org/apache/flink/api/common/typeutils/CompositeTypeSerializerSnapshot.java
index 49ff8a0..d14a80e 100644
--- a/flink-core/src/main/java/org/apache/flink/api/common/typeutils/CompositeTypeSerializerSnapshot.java
+++ b/flink-core/src/main/java/org/apache/flink/api/common/typeutils/CompositeTypeSerializerSnapshot.java
@@ -30,6 +30,8 @@ import org.apache.flink.util.Preconditions;
 
 import java.io.IOException;
 
+import static org.apache.flink.util.Preconditions.checkNotNull;
+
 /**
  * A {@link CompositeTypeSerializerSnapshot} is a convenient serializer snapshot class that can be used by
  * simple serializers which 1) delegates its serialization to multiple nested serializers, and 2) may contain
@@ -110,7 +112,7 @@ public abstract class CompositeTypeSerializerSnapshot<T, S extends TypeSerialize
 	 * @param correspondingSerializerClass the expected class of the new serializer.
 	 */
 	public CompositeTypeSerializerSnapshot(Class<S> correspondingSerializerClass) {
-		this.correspondingSerializerClass = Preconditions.checkNotNull(correspondingSerializerClass);
+		this.correspondingSerializerClass = checkNotNull(correspondingSerializerClass);
 	}
 
 	/**
@@ -120,7 +122,7 @@ public abstract class CompositeTypeSerializerSnapshot<T, S extends TypeSerialize
 	 */
 	@SuppressWarnings("unchecked")
 	public CompositeTypeSerializerSnapshot(S serializerInstance) {
-		Preconditions.checkNotNull(serializerInstance);
+		checkNotNull(serializerInstance);
 		this.nestedSerializersSnapshotDelegate = new NestedSerializersSnapshotDelegate(getNestedSerializers(serializerInstance));
 		this.correspondingSerializerClass = (Class<S>) serializerInstance.getClass();
 	}
@@ -171,6 +173,11 @@ public abstract class CompositeTypeSerializerSnapshot<T, S extends TypeSerialize
 			snapshots);
 	}
 
+	@Internal
+	void setNestedSerializersSnapshotDelegate(NestedSerializersSnapshotDelegate delegate) {
+		this.nestedSerializersSnapshotDelegate = checkNotNull(delegate);
+	}
+
 	@Override
 	public final TypeSerializer<T> restoreSerializer() {
 		@SuppressWarnings("unchecked")
diff --git a/flink-core/src/main/java/org/apache/flink/api/common/typeutils/CompositeTypeSerializerUtil.java b/flink-core/src/main/java/org/apache/flink/api/common/typeutils/CompositeTypeSerializerUtil.java
index 3c162e3..f98bc72 100644
--- a/flink-core/src/main/java/org/apache/flink/api/common/typeutils/CompositeTypeSerializerUtil.java
+++ b/flink-core/src/main/java/org/apache/flink/api/common/typeutils/CompositeTypeSerializerUtil.java
@@ -48,4 +48,18 @@ public class CompositeTypeSerializerUtil {
 		checkArgument(legacyNestedSnapshots.length > 0);
 		return newCompositeSnapshot.internalResolveSchemaCompatibility(newSerializer, legacyNestedSnapshots);
 	}
+
+	/**
+	 * Overrides the existing nested serializer's snapshots with the provided {@code nestedSnapshots}.
+	 *
+	 * @param compositeSnapshot the composite snapshot to overwrite its nested serializers.
+	 * @param nestedSnapshots the nested snapshots to overwrite with.
+	 */
+	public static void setNestedSerializersSnapshots(
+		CompositeTypeSerializerSnapshot<?, ?> compositeSnapshot,
+		TypeSerializerSnapshot<?>... nestedSnapshots) {
+
+		NestedSerializersSnapshotDelegate delegate = new NestedSerializersSnapshotDelegate(nestedSnapshots);
+		compositeSnapshot.setNestedSerializersSnapshotDelegate(delegate);
+	}
 }
diff --git a/flink-core/src/main/java/org/apache/flink/api/common/typeutils/NestedSerializersSnapshotDelegate.java b/flink-core/src/main/java/org/apache/flink/api/common/typeutils/NestedSerializersSnapshotDelegate.java
index a4dcdd2..0b2cb78 100644
--- a/flink-core/src/main/java/org/apache/flink/api/common/typeutils/NestedSerializersSnapshotDelegate.java
+++ b/flink-core/src/main/java/org/apache/flink/api/common/typeutils/NestedSerializersSnapshotDelegate.java
@@ -28,6 +28,7 @@ import java.util.Arrays;
 import java.util.List;
 
 import static org.apache.flink.util.Preconditions.checkArgument;
+import static org.apache.flink.util.Preconditions.checkNotNull;
 
 /**
  * A NestedSerializersSnapshotDelegate represents the snapshots of multiple serializers that are used
@@ -65,8 +66,9 @@ public class NestedSerializersSnapshotDelegate {
 	/**
 	 * Constructor to create a snapshot during deserialization.
 	 */
-	private NestedSerializersSnapshotDelegate(TypeSerializerSnapshot<?>[] snapshots) {
-		this.nestedSnapshots = snapshots;
+	@Internal
+	NestedSerializersSnapshotDelegate(TypeSerializerSnapshot<?>[] snapshots) {
+		this.nestedSnapshots = checkNotNull(snapshots);
 	}
 
 	// ------------------------------------------------------------------------