You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@fluss.apache.org by "charlesdong1991 (via GitHub)" <gi...@apache.org> on 2026/02/22 19:59:19 UTC

[PR] feat(iceberg): add IcebergBinaryRowWriter [fluss-rust]

charlesdong1991 opened a new pull request, #366:
URL: https://github.com/apache/fluss-rust/pull/366

   ### Purpose
   
   This PR implements IcebergBinaryRowWriter
   
   ### Tests
   
   All tests are passed locally
   


-- 
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: issues-unsubscribe@fluss.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] feat(iceberg): add IcebergBinaryRowWriter [fluss-rust]

Posted by "charlesdong1991 (via GitHub)" <gi...@apache.org>.
charlesdong1991 commented on code in PR #366:
URL: https://github.com/apache/fluss-rust/pull/366#discussion_r2867863764


##########
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:
   i added a TODO comment in the function, and will address after 308



-- 
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: issues-unsubscribe@fluss.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] feat(iceberg): add IcebergBinaryRowWriter [fluss-rust]

Posted by "leekeiabstraction (via GitHub)" <gi...@apache.org>.
leekeiabstraction merged PR #366:
URL: https://github.com/apache/fluss-rust/pull/366


-- 
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: issues-unsubscribe@fluss.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] feat(iceberg): add IcebergBinaryRowWriter [fluss-rust]

Posted by "leekeiabstraction (via GitHub)" <gi...@apache.org>.
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: issues-unsubscribe@fluss.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] feat(iceberg): add IcebergBinaryRowWriter [fluss-rust]

Posted by "charlesdong1991 (via GitHub)" <gi...@apache.org>.
charlesdong1991 commented on code in PR #366:
URL: https://github.com/apache/fluss-rust/pull/366#discussion_r2849626815


##########
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:
   Actually, similar to previous comment, I notice `IcebergKeyEncoder` is being worked on in https://github.com/apache/fluss-rust/pull/308 . 
   
   So I can have a TODO to verify and add tests (since that key encoder is sort of consumer of row writer)?



-- 
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: issues-unsubscribe@fluss.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] feat(iceberg): add IcebergBinaryRowWriter [fluss-rust]

Posted by "charlesdong1991 (via GitHub)" <gi...@apache.org>.
charlesdong1991 commented on PR #366:
URL: https://github.com/apache/fluss-rust/pull/366#issuecomment-4063168559

   Hi @leekeiabstraction @luoyuxia i wonder what's your preference for this PR? For all dependencies on KeyEncoder part, i highlighted as TODO to address after it is implmeneted/merged.
   
   If it is fine, I am happy also to take over the IcebergKeyEncoder implementation to push it though as I'd like to test fluss/iceberg in python for demo.
   
   Thanks again!


-- 
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: issues-unsubscribe@fluss.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] feat(iceberg): add IcebergBinaryRowWriter [fluss-rust]

Posted by "charlesdong1991 (via GitHub)" <gi...@apache.org>.
charlesdong1991 commented on code in PR #366:
URL: https://github.com/apache/fluss-rust/pull/366#discussion_r2867863317


##########
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:
   nice catch! @leekeiabstraction added with tests!



-- 
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: issues-unsubscribe@fluss.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] feat(iceberg): add IcebergBinaryRowWriter [fluss-rust]

Posted by "charlesdong1991 (via GitHub)" <gi...@apache.org>.
charlesdong1991 commented on code in PR #366:
URL: https://github.com/apache/fluss-rust/pull/366#discussion_r2849618231


##########
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:
   Similar to `CompactedKeyEncoder`, it should be called by `IcebergKeyEncoder`, but `IcebergKeyEncoder` is currently being implemented in https://github.com/apache/fluss-rust/pull/308 , so more or less this PR is a bit blocked.
   
   Since I didn't wanna be blocked by that one, so keep it while waiting for that PR make progress. I can either remove this, or add a TODO to address it in a separate PR. WDYT? @leekeiabstraction 



-- 
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: issues-unsubscribe@fluss.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] feat(iceberg): add IcebergBinaryRowWriter [fluss-rust]

Posted by "charlesdong1991 (via GitHub)" <gi...@apache.org>.
charlesdong1991 commented on code in PR #366:
URL: https://github.com/apache/fluss-rust/pull/366#discussion_r2849626815


##########
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:
   Actually, similar to previous comment, I notice `IcebergKeyEncoder` is being worked on in https://github.com/apache/fluss-rust/pull/308 . 
   
   So I can have a TODO to verify and add tests (since that key encoder is sort of consumer of row writer) after that PR is merged?



-- 
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: issues-unsubscribe@fluss.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] feat(iceberg): add IcebergBinaryRowWriter [fluss-rust]

Posted by "leekeiabstraction (via GitHub)" <gi...@apache.org>.
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: issues-unsubscribe@fluss.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] feat(iceberg): add IcebergBinaryRowWriter [fluss-rust]

Posted by "leekeiabstraction (via GitHub)" <gi...@apache.org>.
leekeiabstraction commented on code in PR #366:
URL: https://github.com/apache/fluss-rust/pull/366#discussion_r2942178338


##########
crates/fluss/src/row/binary/iceberg_binary_row_writer.rs:
##########
@@ -0,0 +1,552 @@
+// 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::{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,
+        }
+    }
+
+    // Dependency order note:
+    // 1) Keep this PR scoped to writer-level Java parity.
+    // 2) Wire the writer through IcebergKeyEncoder in follow-up #308.
+    // TODO(#308): add end-to-end key-encoding tests via IcebergKeyEncoder
+    // (similar to CompactedKeyEncoder tests for CompactedKeyWriter).
+    pub fn create_value_writer(field_type: &DataType) -> Result<ValueWriter> {
+        match field_type {
+            // Match Java IcebergBinaryRowWriter.createFieldWriter() supported types exactly.
+            DataType::Int(_)
+            | DataType::Date(_)
+            | DataType::Time(_)
+            | DataType::BigInt(_)
+            | DataType::Float(_)
+            | DataType::Double(_)
+            | DataType::Timestamp(_)
+            | DataType::Decimal(_)
+            | DataType::String(_)
+            | DataType::Char(_)
+            | DataType::Binary(_)
+            | DataType::Bytes(_) => ValueWriter::create_value_writer(field_type, None),
+
+            // Keep Java's explicit scalar-only rejection messaging for ARRAY/MAP.
+            DataType::Array(_) => Err(Error::UnsupportedOperation {
+                message:
+                    "Array types cannot be used as bucket keys. Bucket keys must be scalar types."
+                        .to_string(),
+            }),
+            DataType::Map(_) => Err(Error::UnsupportedOperation {
+                message:
+                    "Map types cannot be used as bucket keys. Bucket keys must be scalar types."
+                        .to_string(),
+            }),
+
+            // BOOLEAN, TINYINT, SMALLINT, TIMESTAMP_LTZ, ROW and any future types.
+            _ => Err(Error::UnsupportedOperation {
+                message: format!(
+                    "Unsupported type for Iceberg binary row writer: {:?}",
+                    field_type
+                ),
+            }),
+        }
+    }
+
+    #[allow(dead_code)]
+    pub fn position(&self) -> usize {
+        self.position
+    }
+
+    #[allow(dead_code)]
+    pub fn buffer(&self) -> &[u8] {
+        &self.buffer[..self.position]
+    }
+
+    pub fn to_bytes(&self) -> Bytes {
+        Bytes::copy_from_slice(&self.buffer[..self.position])
+    }
+
+    fn ensure_capacity(&mut self, need_len: usize) {
+        if (self.buffer.len() - self.position) < need_len {
+            let new_len = std::cmp::max(self.buffer.len() * 2, self.buffer.len() + need_len);
+            self.buffer.resize(new_len, 0);
+        }
+    }
+
+    fn write_raw(&mut self, src: &[u8]) {
+        let end = self.position + src.len();
+        self.ensure_capacity(src.len());
+        self.buffer[self.position..end].copy_from_slice(src);
+        self.position = end;
+    }
+}
+
+impl BinaryWriter for IcebergBinaryRowWriter {
+    fn reset(&mut self) {
+        self.position = 0;

Review Comment:
   Do we need to fill buffer with zeroes?
   
   https://github.com/apache/fluss/blob/0f4d86532b48d229706f894dff652c40f825b003/fluss-common/src/main/java/org/apache/fluss/row/encode/iceberg/IcebergBinaryRowWriter.java#L64
   



-- 
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: issues-unsubscribe@fluss.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org