luoyuxia commented on code in PR #138:
URL: https://github.com/apache/fluss-rust/pull/138#discussion_r2679294094
##########
crates/fluss/src/row/compacted/compacted_row.rs:
##########
@@ -24,125 +24,100 @@ use crate::row::{GenericRow, InternalRow};
// Reference implementation:
//
https://github.com/apache/fluss/blob/main/fluss-common/src/main/java/org/apache/fluss/row/compacted/CompactedRow.java
#[allow(dead_code)]
-pub struct CompactedRow {
+pub struct CompactedRow<'a> {
arity: usize,
- segment: Bytes,
+ segment: &'a [u8],
offset: usize,
size_in_bytes: usize,
- decoded: bool,
- decoded_row: GenericRow<'static>,
- reader: CompactedRowReader,
- deserializer: CompactedRowDeserializer,
+ decoded_row: OnceLock<GenericRow<'a>>,
+ deserializer: CompactedRowDeserializer<'a>,
+ reader: CompactedRowReader<'a>,
}
#[allow(dead_code)]
-impl CompactedRow {
+impl<'a> CompactedRow<'a> {
pub fn calculate_bit_set_width_in_bytes(arity: usize) -> usize {
arity.div_ceil(8)
}
- pub fn new(types: Vec<DataType>) -> Self {
- let arity = types.len();
- Self {
- arity,
- segment: Bytes::new(),
- offset: 0,
- size_in_bytes: 0,
- decoded: false,
- decoded_row: GenericRow::new(),
- reader: CompactedRowReader::new(arity),
- deserializer: CompactedRowDeserializer::new(types),
- }
- }
-
- pub fn from_bytes(types: Vec<DataType>, data: Bytes) -> Self {
+ pub fn from_bytes(types: &'a [DataType], data: &'a [u8]) -> Self {
let arity = types.len();
let size = data.len();
Self {
arity,
segment: data,
offset: 0,
size_in_bytes: size,
- decoded: false,
- decoded_row: GenericRow::new(),
- reader: CompactedRowReader::new(arity),
+ decoded_row: OnceLock::new(),
deserializer: CompactedRowDeserializer::new(types),
+ reader: CompactedRowReader::new(arity, data, 0, size),
}
}
- pub fn point_to(&mut self, segment: Bytes, offset: usize, size_in_bytes:
usize) {
- self.segment = segment;
- self.offset = offset;
- self.size_in_bytes = size_in_bytes;
- self.decoded = false;
- }
-
- pub fn get_segment(&self) -> &Bytes {
- &self.segment
- }
-
- pub fn get_offset(&self) -> usize {
- self.offset
- }
-
pub fn get_size_in_bytes(&self) -> usize {
self.size_in_bytes
}
- pub fn get_field_count(&self) -> usize {
+ fn decoded_row(&self) -> &GenericRow<'_> {
+ self.decoded_row
+ .get_or_init(|| self.deserializer.deserialize(&self.reader))
+ }
+}
+
+#[allow(dead_code)]
+impl<'a> InternalRow for CompactedRow<'a> {
+ fn get_field_count(&self) -> usize {
self.arity
}
- pub fn is_null_at(&self, pos: usize) -> bool {
+ fn is_null_at(&self, pos: usize) -> bool {
let byte_index = pos >> 3;
Review Comment:
Miss that while copy & paste.
--
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]