提交 301be555 编写于 作者: T Tzu-Li (Gordon) Tai

[FLINK-11073] [core] Replace EitherSerializerSnapshot with new JavaEitherSerializerSnapshot

上级 e791b1a2
...@@ -205,7 +205,7 @@ public class EitherSerializer<L, R> extends TypeSerializer<Either<L, R>> { ...@@ -205,7 +205,7 @@ public class EitherSerializer<L, R> extends TypeSerializer<Either<L, R>> {
// ------------------------------------------------------------------------ // ------------------------------------------------------------------------
@Override @Override
public EitherSerializerSnapshot<L, R> snapshotConfiguration() { public JavaEitherSerializerSnapshot<L, R> snapshotConfiguration() {
return new EitherSerializerSnapshot<>(leftSerializer, rightSerializer); return new JavaEitherSerializerSnapshot<>(this);
} }
} }
...@@ -35,8 +35,12 @@ import static org.apache.flink.util.Preconditions.checkState; ...@@ -35,8 +35,12 @@ import static org.apache.flink.util.Preconditions.checkState;
/** /**
* Configuration snapshot for the {@link EitherSerializer}. * Configuration snapshot for the {@link EitherSerializer}.
*
* @deprecated this snapshot class is no longer used by any serializers.
* Instead, {@link JavaEitherSerializerSnapshot} is used.
*/ */
@Internal @Internal
@Deprecated
public final class EitherSerializerSnapshot<L, R> implements TypeSerializerSnapshot<Either<L, R>> { public final class EitherSerializerSnapshot<L, R> implements TypeSerializerSnapshot<Either<L, R>> {
private static final int CURRENT_VERSION = 2; private static final int CURRENT_VERSION = 2;
...@@ -110,12 +114,10 @@ public final class EitherSerializerSnapshot<L, R> implements TypeSerializerSnaps ...@@ -110,12 +114,10 @@ public final class EitherSerializerSnapshot<L, R> implements TypeSerializerSnaps
checkState(nestedSnapshot != null); checkState(nestedSnapshot != null);
if (newSerializer instanceof EitherSerializer) { if (newSerializer instanceof EitherSerializer) {
// delegate compatibility check to the new snapshot class
EitherSerializer<L, R> serializer = (EitherSerializer<L, R>) newSerializer; EitherSerializer<L, R> serializer = (EitherSerializer<L, R>) newSerializer;
JavaEitherSerializerSnapshot<L, R> newSnapshot = new JavaEitherSerializerSnapshot<>(serializer);
return nestedSnapshot.resolveCompatibilityWithNested( return newSnapshot.resolveSchemaCompatibility(serializer);
TypeSerializerSchemaCompatibility.compatibleAsIs(),
serializer.getLeftSerializer(),
serializer.getRightSerializer());
} }
else { else {
return TypeSerializerSchemaCompatibility.incompatible(); return TypeSerializerSchemaCompatibility.incompatible();
......
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.flink.api.java.typeutils.runtime;
import org.apache.flink.api.common.typeutils.CompositeTypeSerializerSnapshot;
import org.apache.flink.api.common.typeutils.TypeSerializer;
import org.apache.flink.types.Either;
/**
* Snapshot class for the {@link EitherSerializer}.
*/
public class JavaEitherSerializerSnapshot<L, R> extends CompositeTypeSerializerSnapshot<Either<L, R>, EitherSerializer> {
private static final int CURRENT_VERSION = 1;
/**
* Constructor for read instantiation.
*/
@SuppressWarnings("unused")
public JavaEitherSerializerSnapshot() {
super(EitherSerializer.class);
}
/**
* Constructor to create the snapshot for writing.
*/
public JavaEitherSerializerSnapshot(EitherSerializer<L, R> eitherSerializer) {
super(eitherSerializer);
}
@Override
protected int getCurrentOuterSnapshotVersion() {
return CURRENT_VERSION;
}
@Override
protected EitherSerializer createOuterSerializerWithNestedSerializers(TypeSerializer<?>[] nestedSerializers) {
return new EitherSerializer<>(nestedSerializers[0], nestedSerializers[1]);
}
@Override
protected TypeSerializer<?>[] getNestedSerializers(EitherSerializer outerSerializer) {
return new TypeSerializer<?>[]{ outerSerializer.getLeftSerializer(), outerSerializer.getRightSerializer() };
}
}
...@@ -23,7 +23,7 @@ import org.apache.flink.api.common.typeutils.base.GenericArraySerializerSnapshot ...@@ -23,7 +23,7 @@ import org.apache.flink.api.common.typeutils.base.GenericArraySerializerSnapshot
import org.apache.flink.api.common.typeutils.base.IntSerializer; import org.apache.flink.api.common.typeutils.base.IntSerializer;
import org.apache.flink.api.common.typeutils.base.StringSerializer; import org.apache.flink.api.common.typeutils.base.StringSerializer;
import org.apache.flink.api.java.typeutils.runtime.EitherSerializer; import org.apache.flink.api.java.typeutils.runtime.EitherSerializer;
import org.apache.flink.api.java.typeutils.runtime.EitherSerializerSnapshot; import org.apache.flink.api.java.typeutils.runtime.JavaEitherSerializerSnapshot;
import org.apache.flink.types.Either; import org.apache.flink.types.Either;
import org.junit.runner.RunWith; import org.junit.runner.RunWith;
...@@ -48,7 +48,7 @@ public class CompositeTypeSerializerSnapshotMigrationTest extends TypeSerializer ...@@ -48,7 +48,7 @@ public class CompositeTypeSerializerSnapshotMigrationTest extends TypeSerializer
// Either<String, Integer> // Either<String, Integer>
final TestSpecification<Either<String, Integer>> either = TestSpecification.<Either<String, Integer>>builder("1.6-either", EitherSerializer.class, EitherSerializerSnapshot.class) final TestSpecification<Either<String, Integer>> either = TestSpecification.<Either<String, Integer>>builder("1.6-either", EitherSerializer.class, JavaEitherSerializerSnapshot.class)
.withSerializerProvider(() -> new EitherSerializer<>(StringSerializer.INSTANCE, IntSerializer.INSTANCE)) .withSerializerProvider(() -> new EitherSerializer<>(StringSerializer.INSTANCE, IntSerializer.INSTANCE))
.withSnapshotDataLocation("flink-1.6-either-type-serializer-snapshot") .withSnapshotDataLocation("flink-1.6-either-type-serializer-snapshot")
.withTestData("flink-1.6-either-type-serializer-data", 10); .withTestData("flink-1.6-either-type-serializer-data", 10);
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册