openinx commented on a change in pull request #1477:
URL: https://github.com/apache/iceberg/pull/1477#discussion_r513143279



##########
File path: core/src/main/java/org/apache/iceberg/avro/AvroEncoderUtil.java
##########
@@ -0,0 +1,105 @@
+/*
+ * 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.iceberg.avro;
+
+import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
+import java.io.IOException;
+import java.nio.ByteBuffer;
+import java.nio.charset.StandardCharsets;
+import java.util.Arrays;
+import org.apache.avro.LogicalTypes;
+import org.apache.avro.Schema;
+import org.apache.avro.io.BinaryDecoder;
+import org.apache.avro.io.BinaryEncoder;
+import org.apache.avro.io.DatumReader;
+import org.apache.avro.io.DatumWriter;
+import org.apache.avro.io.DecoderFactory;
+import org.apache.avro.io.EncoderFactory;
+import org.apache.iceberg.relocated.com.google.common.base.Preconditions;
+
+public class AvroEncoderUtil {
+
+  private AvroEncoderUtil() {
+  }
+
+  static {
+    LogicalTypes.register(LogicalMap.NAME, schema -> LogicalMap.get());
+  }
+
+  private static final int VERSION = 1;
+  private static final byte[] MAGIC_BYTES = new byte[] {'a', 'V', 'R', 
VERSION};
+
+  private static byte[] encodeInt(int value) {
+    return ByteBuffer.allocate(4).putInt(value).array();
+  }
+
+  private static int decodeInt(byte[] value) {
+    return ByteBuffer.wrap(value).getInt();
+  }
+
+  public static <T> byte[] encode(T datum, Schema avroSchema) throws 
IOException {

Review comment:
       > That keeps the size of the encoded record lower.
   
   OK , I saw there's a `SchemaStore` in IcebergDecoder, which keeps the 
fingerprint-schema mapping. In theory, for all manifest files,  we only need to 
keep only one schema binary data.  If we really need to save those schema 
bytes,  we may need another extra states to track the `SchemaStore`,  and for 
each manifestFiles encoding or decoding, we need to maintain the `SchemaStore` 
( For example, if use the a new manifests file schema to encode, then we will 
need to put `<fingerprint, schema>` to the SchemaStore and persist to state 
backend,  If plan to decode, then we will fetch the schema by the manifests 
binary data's fingerprint -- here we may need to encode the fingerpint into the 
manifests file's binary data -- and use that schema to accomplish the decode).  
For me, that sounds a bit complex optimization for making state more smaller, 
it's not worth to do that in my mind. 




----------------------------------------------------------------
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.

For queries about this service, please contact Infrastructure at:
[email protected]



---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to