You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@flink.apache.org by GitBox <gi...@apache.org> on 2022/05/11 08:18:43 UTC

[GitHub] [flink-table-store] JingsongLi opened a new pull request, #107: [FLINK-27372] Make DataFileMeta and ManifestFileMeta schemaless

JingsongLi opened a new pull request, #107:
URL: https://github.com/apache/flink-table-store/pull/107

   Currently these meta need key and value schema to serialize and deserialize
   - schema binding makes the construction of serializers difficult and prone to problems
   - Not conducive to schema evolution, different schema can not be mixed together, will increase the difficulty of management.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@flink.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [flink-table-store] JingsongLi merged pull request #107: [FLINK-27372] Make DataFileMeta and ManifestFileMeta schemaless

Posted by GitBox <gi...@apache.org>.
JingsongLi merged PR #107:
URL: https://github.com/apache/flink-table-store/pull/107


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@flink.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [flink-table-store] tsreaper commented on a diff in pull request #107: [FLINK-27372] Make DataFileMeta and ManifestFileMeta schemaless

Posted by GitBox <gi...@apache.org>.
tsreaper commented on code in PR #107:
URL: https://github.com/apache/flink-table-store/pull/107#discussion_r870889022


##########
flink-table-store-core/src/main/java/org/apache/flink/table/store/file/utils/SerializationUtils.java:
##########
@@ -0,0 +1,100 @@
+/*
+ * 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.file.utils;
+
+import org.apache.flink.core.memory.DataInputView;
+import org.apache.flink.core.memory.DataOutputView;
+import org.apache.flink.core.memory.MemorySegmentFactory;
+import org.apache.flink.table.data.binary.BinaryRowData;
+import org.apache.flink.table.runtime.typeutils.BinaryRowDataSerializer;
+import org.apache.flink.table.types.logical.VarBinaryType;
+
+import java.io.EOFException;
+import java.io.IOException;
+import java.nio.ByteBuffer;
+
+import static org.apache.flink.table.data.binary.BinarySegmentUtils.copyToBytes;
+
+/** Utils for serialization. */
+public class SerializationUtils {
+
+    /** Serialize a {@code byte[]} bytes with length. */
+    public static void serializeBytes(DataOutputView out, byte[] binary) throws IOException {
+        out.writeInt(binary.length);
+        out.write(binary);
+    }
+
+    /** Deserialize a {@code byte[]} bytes with length. */
+    public static byte[] deserializedBytes(DataInputView in) throws IOException {
+        int len = in.readInt();
+        byte[] buf = new byte[len];
+        int ret;
+        int off = 0;
+        for (int toRead = len; toRead > 0; off += ret) {
+            ret = in.read(buf, off, toRead);
+            if (ret < 0) {
+                throw new EOFException();
+            }
+
+            toRead -= ret;
+        }
+        return buf;
+    }
+
+    /** Create a bytes type VarBinaryType(Integer.MAX_VALUE). */
+    public static VarBinaryType newBytesType(boolean isNullable) {
+        return new VarBinaryType(isNullable, Integer.MAX_VALUE);
+    }
+
+    /**
+     * Serialize {@link BinaryRowData}, the difference between this and {@link
+     * BinaryRowDataSerializer} is that arity is also serialized here, so the deserialization is
+     * schemaless.
+     */
+    public static byte[] serializeBinaryRow(BinaryRowData row) {
+        byte[] bytes = copyToBytes(row.getSegments(), row.getOffset(), row.getSizeInBytes());
+        ByteBuffer buffer = ByteBuffer.allocate(4 + bytes.length);
+        buffer.putInt(row.getArity()).put(bytes);
+        return buffer.array();
+    }
+
+    /** Schemaless deserialization for {@link BinaryRowData}. */
+    public static BinaryRowData deserializeBinaryRow(byte[] bytes) {
+        ByteBuffer buffer = ByteBuffer.wrap(bytes);
+        int arity = buffer.getInt();
+        BinaryRowData row = new BinaryRowData(arity);
+        row.pointTo(MemorySegmentFactory.wrap(bytes), 4, bytes.length - 4);
+        return row;
+    }
+
+    /**
+     * Serialize {@link BinaryRowData} to a {@link DataOutputView}.
+     *
+     * @see #serializeBinaryRow(BinaryRowData)
+     */
+    public static void serializeBinaryRow(BinaryRowData row, DataOutputView out)
+            throws IOException {
+        serializeBytes(out, serializeBinaryRow(row));

Review Comment:
   Use `BinarySegmentUtils#copyToView` directly.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@flink.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [flink-table-store] JingsongLi commented on a diff in pull request #107: [FLINK-27372] Make DataFileMeta and ManifestFileMeta schemaless

Posted by GitBox <gi...@apache.org>.
JingsongLi commented on code in PR #107:
URL: https://github.com/apache/flink-table-store/pull/107#discussion_r869914759


##########
flink-table-store-core/src/main/java/org/apache/flink/table/store/file/data/DataFileMetaSerializer.java:
##########
@@ -48,27 +42,25 @@ public RowData toRow(DataFileMeta meta) {
                 StringData.fromString(meta.fileName()),
                 meta.fileSize(),
                 meta.rowCount(),
-                meta.minKey(),
-                meta.maxKey(),
-                keyStatsArraySerializer.toRow(meta.keyStats()),
-                valueStatsArraySerializer.toRow(meta.valueStats()),
+                serializeBinaryRow(meta.minKey()),

Review Comment:
   It is difficult:
   - First, the row serializer is dependent on flink, if we want to have this logic, we need to write a serializer ourselves.
   - Second, avro serialization does not use serializer, it is to get rowData to convert itself.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@flink.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [flink-table-store] tsreaper commented on a diff in pull request #107: [FLINK-27372] Make DataFileMeta and ManifestFileMeta schemaless

Posted by GitBox <gi...@apache.org>.
tsreaper commented on code in PR #107:
URL: https://github.com/apache/flink-table-store/pull/107#discussion_r869889027


##########
flink-table-store-core/src/main/java/org/apache/flink/table/store/file/data/DataFileMetaSerializer.java:
##########
@@ -48,27 +42,25 @@ public RowData toRow(DataFileMeta meta) {
                 StringData.fromString(meta.fileName()),
                 meta.fileSize(),
                 meta.rowCount(),
-                meta.minKey(),
-                meta.maxKey(),
-                keyStatsArraySerializer.toRow(meta.keyStats()),
-                valueStatsArraySerializer.toRow(meta.valueStats()),
+                serializeBinaryRow(meta.minKey()),

Review Comment:
   Current implementation will copy `BinaryRowData` into a new byte array. Can we keep `BinaryRowData` and read its underlying byte array directly when serializing? This can be applied not only to `minKey` and `maxKey`, but also to `partitionKey` and even `BinaryTableStats`. Also by storing a `BinaryRowData` in the object we can read its fields directly if we know the types, which simplifies the implementation a lot.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@flink.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [flink-table-store] JingsongLi closed pull request #107: [FLINK-27372] Make DataFileMeta and ManifestFileMeta schemaless

Posted by GitBox <gi...@apache.org>.
JingsongLi closed pull request #107: [FLINK-27372] Make DataFileMeta and ManifestFileMeta schemaless
URL: https://github.com/apache/flink-table-store/pull/107


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@flink.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org