MehulBatra commented on code in PR #1350: URL: https://github.com/apache/fluss/pull/1350#discussion_r2219658617
########## fluss-common/src/main/java/com/alibaba/fluss/row/encode/iceberg/IcebergBinaryRowWriter.java: ########## @@ -0,0 +1,326 @@ +/* + * 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 com.alibaba.fluss.row.encode.iceberg; + +import com.alibaba.fluss.memory.MemorySegment; +import com.alibaba.fluss.row.BinaryString; +import com.alibaba.fluss.row.Decimal; +import com.alibaba.fluss.row.InternalRow; +import com.alibaba.fluss.row.TimestampLtz; +import com.alibaba.fluss.row.TimestampNtz; +import com.alibaba.fluss.types.DataType; +import com.alibaba.fluss.utils.UnsafeUtils; + +import java.io.Serializable; +import java.nio.ByteBuffer; +import java.nio.ByteOrder; +import java.util.Arrays; + +import static com.alibaba.fluss.types.DataTypeChecks.getPrecision; + +/** + * A writer to encode Fluss's {@link InternalRow} using Iceberg's binary encoding format. + * + * <p>This implementation follows Iceberg's binary encoding specification for partition and bucket + * keys. Reference: https://iceberg.apache.org/spec/#partition-transforms + * + * <p>The encoding logic is based on Iceberg's Conversions.toByteBuffer() implementation: + * https://github.com/apache/iceberg/blob/main/api/src/main/java/org/apache/iceberg/types/Conversions.java + * + * <p>Key encoding principles from Iceberg's Conversions class: + * + * <ul> + * <li>All numeric types (int, long, float, double, timestamps) use LITTLE-ENDIAN byte order + * <li>Decimal and UUID types use BIG-ENDIAN byte order + * <li>NO length prefix for any type - the buffer size determines the length + * <li>Strings are encoded as UTF-8 bytes without length prefix + * <li>Timestamps are stored as long values (microseconds since epoch) + * </ul> + * + * <p>Note: This implementation uses Fluss's MemorySegment instead of ByteBuffer for performance, + * but maintains byte-level compatibility with Iceberg's encoding. + */ +class IcebergBinaryRowWriter { Review Comment: Whitelisted, except the UUID as we don't have that datatype in fluss and also iceberg 1.4.3 doesn't support nanoseconds, as it came in table v3, which was released in later version. will add a note for nanoseconds to support post #1195 -- 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: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
