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:30:41 UTC

[flink-table-store] branch master updated: [Flink-30993] Introduce FloatSerializer 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 c62992ce [Flink-30993] Introduce FloatSerializer for Table Store
c62992ce is described below

commit c62992cef568274ec777c2d6e264a12f077b0925
Author: Feng Wang <99...@users.noreply.github.com>
AuthorDate: Sat Feb 11 12:30:35 2023 +0800

    [Flink-30993] Introduce FloatSerializer for Table Store
    
    This closes #511
---
 .../store/data/serializer/FloatSerializer.java     | 48 +++++++++++++++++++
 .../store/data/serializer/FloatSerializerTest.java | 54 ++++++++++++++++++++++
 2 files changed, 102 insertions(+)

diff --git a/flink-table-store-common/src/main/java/org/apache/flink/table/store/data/serializer/FloatSerializer.java b/flink-table-store-common/src/main/java/org/apache/flink/table/store/data/serializer/FloatSerializer.java
new file mode 100644
index 00000000..a1fd7094
--- /dev/null
+++ b/flink-table-store-common/src/main/java/org/apache/flink/table/store/data/serializer/FloatSerializer.java
@@ -0,0 +1,48 @@
+/*
+ * 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.table.store.data.serializer;
+
+import org.apache.flink.core.memory.DataInputView;
+import org.apache.flink.core.memory.DataOutputView;
+
+import java.io.IOException;
+
+/** Type serializer for {@code Float} (and {@code float}, via auto-boxing). */
+public final class FloatSerializer extends SerializerSingleton<Float> {
+
+    private static final long serialVersionUID = 1L;
+
+    /** Sharable instance of the IntSerializer. */
+    public static final FloatSerializer INSTANCE = new FloatSerializer();
+
+    @Override
+    public Float copy(Float from) {
+        return from;
+    }
+
+    @Override
+    public void serialize(Float record, DataOutputView target) throws IOException {
+        target.writeFloat(record);
+    }
+
+    @Override
+    public Float deserialize(DataInputView source) throws IOException {
+        return source.readFloat();
+    }
+}
diff --git a/flink-table-store-common/src/test/java/org/apache/flink/table/store/data/serializer/FloatSerializerTest.java b/flink-table-store-common/src/test/java/org/apache/flink/table/store/data/serializer/FloatSerializerTest.java
new file mode 100644
index 00000000..993badf3
--- /dev/null
+++ b/flink-table-store-common/src/test/java/org/apache/flink/table/store/data/serializer/FloatSerializerTest.java
@@ -0,0 +1,54 @@
+/*
+ * 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.table.store.data.serializer;
+
+import java.util.Random;
+
+/** Test for {@link FloatSerializer}. */
+public class FloatSerializerTest extends SerializerTestBase<Float> {
+
+    @Override
+    protected Serializer<Float> createSerializer() {
+        return FloatSerializer.INSTANCE;
+    }
+
+    @Override
+    protected boolean deepEquals(Float t1, Float t2) {
+        return t1.equals(t2);
+    }
+
+    @Override
+    protected Float[] getTestData() {
+        Random rnd = new Random();
+        float rndFloat = rnd.nextFloat() * Float.MAX_VALUE;
+
+        return new Float[] {
+            (float) 0,
+            1F,
+            (float) -1,
+            Float.MAX_VALUE,
+            Float.MIN_VALUE,
+            rndFloat,
+            -rndFloat,
+            Float.NaN,
+            Float.NEGATIVE_INFINITY,
+            Float.POSITIVE_INFINITY
+        };
+    }
+}