Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[FLINK-11329] Migrating ScalaOptionSerializer
- Loading branch information
Igal Shilman
committed
Jan 28, 2019
1 parent
9a0ddc1
commit 4e1a755
Showing
8 changed files
with
133 additions
and
39 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
62 changes: 62 additions & 0 deletions
62
...ala/src/main/java/org/apache/flink/api/scala/typeutils/ScalaOptionSerializerSnapshot.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
/* | ||
* 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.scala.typeutils; | ||
|
||
import org.apache.flink.api.common.typeutils.CompositeTypeSerializerSnapshot; | ||
import org.apache.flink.api.common.typeutils.TypeSerializer; | ||
|
||
import scala.Option; | ||
|
||
/** | ||
* A {@link org.apache.flink.api.common.typeutils.TypeSerializerSnapshot} for the Scala {@link OptionSerializer}. | ||
*/ | ||
public final class ScalaOptionSerializerSnapshot<E> extends CompositeTypeSerializerSnapshot<Option<E>, OptionSerializer<E>> { | ||
|
||
private static final int VERSION = 2; | ||
|
||
@SuppressWarnings("WeakerAccess") | ||
public ScalaOptionSerializerSnapshot() { | ||
super(underlyingClass()); | ||
} | ||
|
||
public ScalaOptionSerializerSnapshot(OptionSerializer<E> serializerInstance) { | ||
super(serializerInstance); | ||
} | ||
|
||
@Override | ||
protected int getCurrentOuterSnapshotVersion() { | ||
return VERSION; | ||
} | ||
|
||
@Override | ||
protected TypeSerializer<?>[] getNestedSerializers(OptionSerializer<E> outerSerializer) { | ||
return new TypeSerializer[]{outerSerializer.elemSerializer()}; | ||
} | ||
|
||
@Override | ||
protected OptionSerializer<E> createOuterSerializerWithNestedSerializers(TypeSerializer<?>[] nestedSerializers) { | ||
@SuppressWarnings("unchecked") TypeSerializer<E> nestedSerializer = (TypeSerializer<E>) nestedSerializers[0]; | ||
return new OptionSerializer<>(nestedSerializer); | ||
} | ||
|
||
@SuppressWarnings("unchecked") | ||
private static <E> Class<OptionSerializer<E>> underlyingClass() { | ||
return (Class<OptionSerializer<E>>) (Class<?>) OptionSerializer.class; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
58 changes: 58 additions & 0 deletions
58
...java/org/apache/flink/api/scala/typeutils/ScalaOptionSerializerSnapshotMigrationTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
/* | ||
* 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.scala.typeutils; | ||
|
||
import org.apache.flink.api.common.typeutils.TypeSerializerSnapshotMigrationTestBase; | ||
import org.apache.flink.api.common.typeutils.base.StringSerializer; | ||
import org.apache.flink.testutils.migration.MigrationVersion; | ||
|
||
import org.junit.runner.RunWith; | ||
import org.junit.runners.Parameterized; | ||
|
||
import java.util.Collection; | ||
|
||
import scala.Option; | ||
|
||
/** | ||
* Migration test for the {@link ScalaEitherSerializerSnapshot}. | ||
*/ | ||
@RunWith(Parameterized.class) | ||
public class ScalaOptionSerializerSnapshotMigrationTest extends TypeSerializerSnapshotMigrationTestBase<Option<String>> { | ||
|
||
private static final String SPEC_NAME = "scala-option-serializer"; | ||
|
||
public ScalaOptionSerializerSnapshotMigrationTest(TestSpecification<Option<String>> testSpecification) { | ||
super(testSpecification); | ||
} | ||
|
||
@SuppressWarnings("unchecked") | ||
@Parameterized.Parameters(name = "Test Specification = {0}") | ||
public static Collection<TestSpecification<?>> testSpecifications() { | ||
|
||
final TestSpecifications testSpecifications = new TestSpecifications(MigrationVersion.v1_6, MigrationVersion.v1_7); | ||
|
||
testSpecifications.add( | ||
SPEC_NAME, | ||
OptionSerializer.class, | ||
ScalaOptionSerializerSnapshot.class, | ||
() -> new OptionSerializer<>(StringSerializer.INSTANCE)); | ||
|
||
return testSpecifications.get(); | ||
} | ||
} |
Binary file added
BIN
+31 Bytes
flink-scala/src/test/resources/flink-1.6-scala-option-serializer-data
Binary file not shown.
Binary file added
BIN
+876 Bytes
flink-scala/src/test/resources/flink-1.6-scala-option-serializer-snapshot
Binary file not shown.
Binary file added
BIN
+31 Bytes
flink-scala/src/test/resources/flink-1.7-scala-option-serializer-data
Binary file not shown.
Binary file added
BIN
+877 Bytes
flink-scala/src/test/resources/flink-1.7-scala-option-serializer-snapshot
Binary file not shown.