This is an automated email from the ASF dual-hosted git repository. yuxia pushed a commit to branch get_char_optimize in repository https://gitbox.apache.org/repos/asf/fluss-rust.git
commit be108f6840a97b350a1465baa6e02fb1e5707c16 Author: luoyuxia <[email protected]> AuthorDate: Sun Dec 21 12:53:05 2025 +0800 chore: optimize get_char method --- 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..fff3572 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 {
