This is an automated email from the ASF dual-hosted git repository.

yuxia pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/fluss-rust.git


The following commit(s) were added to refs/heads/main by this push:
     new e3728fc  chore: optimize get_char method (#105)
e3728fc is described below

commit e3728fcfa437a45835247bcc86cb438882a0dc03
Author: yuxia Luo <[email protected]>
AuthorDate: Sun Dec 21 13:06:02 2025 +0800

    chore: optimize get_char method (#105)
---
 crates/fluss/src/row/column.rs | 14 +++-----------
 crates/fluss/src/row/mod.rs    | 15 ++++-----------
 2 files changed, 7 insertions(+), 22 deletions(-)

diff --git a/crates/fluss/src/row/column.rs b/crates/fluss/src/row/column.rs
index 20d86c0..31f0fdf 100644
--- a/crates/fluss/src/row/column.rs
+++ b/crates/fluss/src/row/column.rs
@@ -126,7 +126,7 @@ impl InternalRow for ColumnarRow {
             .value(self.row_id)
     }
 
-    fn get_char(&self, pos: usize, length: usize) -> String {
+    fn get_char(&self, pos: usize, _length: usize) -> &str {
         let array = self
             .record_batch
             .column(pos)
@@ -135,16 +135,8 @@ impl InternalRow for ColumnarRow {
             .expect("Expected fixed-size binary array for char type");
 
         let bytes = array.value(self.row_id);
-        if bytes.len() != length {
-            panic!(
-                "Length mismatch for fixed-size char: expected {}, got {}",
-                length,
-                bytes.len()
-            );
-        }
-
-        String::from_utf8(bytes.to_vec())
-            .unwrap_or_else(|_| String::from_utf8_lossy(bytes).into_owned())
+        // don't check length, following java client
+        std::str::from_utf8(bytes).expect("Invalid UTF-8 in char field")
     }
 
     fn get_string(&self, pos: usize) -> &str {
diff --git a/crates/fluss/src/row/mod.rs b/crates/fluss/src/row/mod.rs
index dd1dedf..01b89fc 100644
--- a/crates/fluss/src/row/mod.rs
+++ b/crates/fluss/src/row/mod.rs
@@ -51,7 +51,7 @@ pub trait InternalRow {
     fn get_double(&self, pos: usize) -> f64;
 
     /// Returns the string value at the given position with fixed length
-    fn get_char(&self, pos: usize, length: usize) -> String;
+    fn get_char(&self, pos: usize, length: usize) -> &str;
 
     /// Returns the string value at the given position
     fn get_string(&self, pos: usize) -> &str;
@@ -116,16 +116,9 @@ impl<'a> InternalRow for GenericRow<'a> {
         self.values.get(pos).unwrap().try_into().unwrap()
     }
 
-    fn get_char(&self, pos: usize, length: usize) -> String {
-        let value = self.get_string(pos);
-        if value.len() != length {
-            panic!(
-                "Length mismatch for fixed-size char: expected {}, got {}",
-                length,
-                value.len()
-            );
-        }
-        value.to_string()
+    fn get_char(&self, pos: usize, _length: usize) -> &str {
+        // don't check length, following java client
+        self.get_string(pos)
     }
 
     fn get_string(&self, pos: usize) -> &str {

Reply via email to