leekeiabstraction commented on code in PR #366:
URL: https://github.com/apache/fluss-rust/pull/366#discussion_r2848958230


##########
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:
   Where do we intend to call this from?



##########
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 {

Review Comment:
   Should this PR also contain `IcebergKeyEncoder`? IcebergKeyEncoder 
implementation should be small, but the test cases there should provide a lot 
of value in verifying correctness of IcebergBinaryRowWriter.
   
   See CompactedKeyEncoder implementation and test as example.



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

Reply via email to