You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@flink.apache.org by lz...@apache.org on 2023/02/11 04:29:50 UTC

[flink-table-store] branch master updated: [Flink-30992] Introduce ShortSerializer for Table Store

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

lzljs3620320 pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/flink-table-store.git


The following commit(s) were added to refs/heads/master by this push:
     new f285db56 [Flink-30992] Introduce ShortSerializer for Table Store
f285db56 is described below

commit f285db56b8a440ef4ef08d15b5a48d58b7c10e01
Author: Feng Wang <99...@users.noreply.github.com>
AuthorDate: Sat Feb 11 12:29:44 2023 +0800

    [Flink-30992] Introduce ShortSerializer for Table Store
    
    This closes #510
---
 .../store/data/serializer/ShortSerializer.java}    | 29 +++++++++++++---------
 .../store/data/serializer/IntSerializerTest.java   |  2 +-
 ...erializerTest.java => ShortSerializerTest.java} | 18 ++++++++------
 3 files changed, 28 insertions(+), 21 deletions(-)

diff --git a/flink-table-store-common/src/test/java/org/apache/flink/table/store/data/serializer/IntSerializerTest.java b/flink-table-store-common/src/main/java/org/apache/flink/table/store/data/serializer/ShortSerializer.java
similarity index 55%
copy from flink-table-store-common/src/test/java/org/apache/flink/table/store/data/serializer/IntSerializerTest.java
copy to flink-table-store-common/src/main/java/org/apache/flink/table/store/data/serializer/ShortSerializer.java
index 82eb8503..759d2942 100644
--- a/flink-table-store-common/src/test/java/org/apache/flink/table/store/data/serializer/IntSerializerTest.java
+++ b/flink-table-store-common/src/main/java/org/apache/flink/table/store/data/serializer/ShortSerializer.java
@@ -18,26 +18,31 @@
 
 package org.apache.flink.table.store.data.serializer;
 
-import java.util.Random;
+import org.apache.flink.core.memory.DataInputView;
+import org.apache.flink.core.memory.DataOutputView;
 
-/** Test for {@link IntSerializer}. */
-public class IntSerializerTest extends SerializerTestBase<Integer> {
+import java.io.IOException;
+
+/** Type serializer for {@code Short} (and {@code short}, via auto-boxing). */
+public final class ShortSerializer extends SerializerSingleton<Short> {
+
+    private static final long serialVersionUID = 1L;
+
+    /** Sharable instance of the IntSerializer. */
+    public static final ShortSerializer INSTANCE = new ShortSerializer();
 
     @Override
-    protected Serializer<Integer> createSerializer() {
-        return IntSerializer.INSTANCE;
+    public Short copy(Short from) {
+        return from;
     }
 
     @Override
-    protected boolean deepEquals(Integer t1, Integer t2) {
-        return t1.equals(t2);
+    public void serialize(Short record, DataOutputView target) throws IOException {
+        target.writeShort(record);
     }
 
     @Override
-    protected Integer[] getTestData() {
-        Random rnd = new Random(874597969123412341L);
-        int rndInt = rnd.nextInt();
-
-        return new Integer[] {0, 1, -1, Integer.MAX_VALUE, Integer.MIN_VALUE, rndInt, -rndInt};
+    public Short deserialize(DataInputView source) throws IOException {
+        return source.readShort();
     }
 }
diff --git a/flink-table-store-common/src/test/java/org/apache/flink/table/store/data/serializer/IntSerializerTest.java b/flink-table-store-common/src/test/java/org/apache/flink/table/store/data/serializer/IntSerializerTest.java
index 82eb8503..c6a97528 100644
--- a/flink-table-store-common/src/test/java/org/apache/flink/table/store/data/serializer/IntSerializerTest.java
+++ b/flink-table-store-common/src/test/java/org/apache/flink/table/store/data/serializer/IntSerializerTest.java
@@ -35,7 +35,7 @@ public class IntSerializerTest extends SerializerTestBase<Integer> {
 
     @Override
     protected Integer[] getTestData() {
-        Random rnd = new Random(874597969123412341L);
+        Random rnd = new Random();
         int rndInt = rnd.nextInt();
 
         return new Integer[] {0, 1, -1, Integer.MAX_VALUE, Integer.MIN_VALUE, rndInt, -rndInt};
diff --git a/flink-table-store-common/src/test/java/org/apache/flink/table/store/data/serializer/IntSerializerTest.java b/flink-table-store-common/src/test/java/org/apache/flink/table/store/data/serializer/ShortSerializerTest.java
similarity index 68%
copy from flink-table-store-common/src/test/java/org/apache/flink/table/store/data/serializer/IntSerializerTest.java
copy to flink-table-store-common/src/test/java/org/apache/flink/table/store/data/serializer/ShortSerializerTest.java
index 82eb8503..0278d3ab 100644
--- a/flink-table-store-common/src/test/java/org/apache/flink/table/store/data/serializer/IntSerializerTest.java
+++ b/flink-table-store-common/src/test/java/org/apache/flink/table/store/data/serializer/ShortSerializerTest.java
@@ -20,24 +20,26 @@ package org.apache.flink.table.store.data.serializer;
 
 import java.util.Random;
 
-/** Test for {@link IntSerializer}. */
-public class IntSerializerTest extends SerializerTestBase<Integer> {
+/** Test for {@link ShortSerializer}. */
+public class ShortSerializerTest extends SerializerTestBase<Short> {
 
     @Override
-    protected Serializer<Integer> createSerializer() {
-        return IntSerializer.INSTANCE;
+    protected Serializer<Short> createSerializer() {
+        return ShortSerializer.INSTANCE;
     }
 
     @Override
-    protected boolean deepEquals(Integer t1, Integer t2) {
+    protected boolean deepEquals(Short t1, Short t2) {
         return t1.equals(t2);
     }
 
     @Override
-    protected Integer[] getTestData() {
+    protected Short[] getTestData() {
         Random rnd = new Random(874597969123412341L);
-        int rndInt = rnd.nextInt();
+        short rndShort = (short) rnd.nextInt();
 
-        return new Integer[] {0, 1, -1, Integer.MAX_VALUE, Integer.MIN_VALUE, rndInt, -rndInt};
+        return new Short[] {
+            0, 1, -1, Short.MAX_VALUE, Short.MIN_VALUE, rndShort, (short) -rndShort
+        };
     }
 }