rdblue commented on a change in pull request #1477: URL: https://github.com/apache/iceberg/pull/1477#discussion_r511197961
########## 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: Can we move this so that we don't need to make it public? It works, but it basically defines its own format for a single message. I'd prefer to use Avro's single-message encoding if we can but this is good for this PR. The more important thing is that we should not expose utility methods that we may need to support that serialize single objects with Avro. I think we should move this and the `ManifestFiles` methods to package-private to support the Flink `ManifestFileSerializer`. ---------------------------------------------------------------- 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]
