leekeiabstraction commented on code in PR #366: URL: https://github.com/apache/fluss-rust/pull/366#discussion_r2849698824
########## crates/fluss/src/row/binary/iceberg_binary_row_writer.rs: ########## @@ -0,0 +1,411 @@ +// 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. + +use bytes::{Bytes, BytesMut}; + +use crate::error::Result; +use crate::metadata::DataType; +use crate::row::Decimal; +use crate::row::binary::{BinaryWriter, ValueWriter}; + +const MICROS_PER_MILLI: i64 = 1_000; + +/// Iceberg-specific binary writer for encoding key columns. +/// +/// Unlike [`CompactedRowWriter`] which uses varint encoding and length-prefixed +/// variable-length fields, this writer follows Iceberg's encoding conventions: +/// - Integers (int, date) are written as i64 (8 bytes, little-endian) +/// - Time values are converted from milliseconds to microseconds +/// - Timestamps are converted to microseconds +/// - Floats/doubles use fixed-width little-endian encoding +/// - Variable-length types (string, binary) are written without length prefixes +/// - Decimals are written as unscaled big-endian bytes without length prefixes +/// +/// The encoded bytes feed directly into [`IcebergBucketingFunction`]'s MurmurHash +/// for bucket assignment and must match the Java Fluss server's encoding exactly. +/// +/// [`CompactedRowWriter`]: crate::row::compacted::CompactedRowWriter +/// [`IcebergBucketingFunction`]: crate::bucketing::IcebergBucketingFunction +pub struct IcebergBinaryRowWriter { + position: usize, + buffer: BytesMut, +} + +impl Default for IcebergBinaryRowWriter { + fn default() -> Self { + Self::new() + } +} + +impl IcebergBinaryRowWriter { + pub fn new() -> Self { + let buffer = BytesMut::zeroed(64); + Self { + position: 0, + buffer, + } + } + + pub fn create_value_writer(field_type: &DataType) -> Result<ValueWriter> { + ValueWriter::create_value_writer(field_type, None) + } Review Comment: I see. Note that `ValueWriter::create_value_writer(field_type, None)` creates ValueWriter (containing InnerValueWriters). InnerValueWriters supports `TinyInt` and `SmallInt`. It seems that Java side and from my search, Iceberg does not support TinyInt / SmallInt directly. https://github.com/apache/fluss/blob/4f74f32eafb74890f0b1069242ba18900e29f5ef/fluss-common/src/main/java/org/apache/fluss/row/encode/iceberg/IcebergBinaryRowWriter.java#L183 `IcebergKeyEncoderTest` also does not test TinyInt / SmallInt. So we may want to reflect that as well. -- 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]
