Skip to content

Commit

Permalink
feat(storage): record first_key in block_index_builder
Browse files Browse the repository at this point in the history
Signed-off-by: ZheNing Hu <adlternative@gmail.com>
  • Loading branch information
adlternative committed Apr 3, 2022
1 parent a23b9b1 commit aa51882
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 2 deletions.
10 changes: 9 additions & 1 deletion src/storage/secondary/block/block_index_builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@ pub struct BlockIndexBuilder {

/// Builder options
options: ColumnBuilderOptions,

/// First key
first_key: Vec<u8>,
}

impl BlockIndexBuilder {
Expand All @@ -32,6 +35,7 @@ impl BlockIndexBuilder {
indexes: vec![],
block_header: vec![],
options,
first_key: vec![],
}
}

Expand All @@ -49,7 +53,7 @@ impl BlockIndexBuilder {
first_rowid: self.last_row_count as u32,
row_count: (self.row_count - self.last_row_count) as u32,
/// TODO(chi): support sort key
first_key: "".into(),
first_key: self.first_key.clone(),
stats,
});

Expand Down Expand Up @@ -83,4 +87,8 @@ impl BlockIndexBuilder {
pub fn into_index(self) -> Vec<BlockIndex> {
self.indexes
}

pub fn set_first_key(&mut self, first_key: Vec<u8>) {
self.first_key = first_key;
}
}
11 changes: 10 additions & 1 deletion src/storage/secondary/column/primitive_column_builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ pub fn append_one_by_one<'a, A: Array>(
impl<T: PrimitiveFixedWidthEncode> ColumnBuilder<T::ArrayType> for PrimitiveColumnBuilder<T> {
fn append(&mut self, array: &T::ArrayType) {
let mut iter = array.iter().peekable();

let mut first_flag = true;
while iter.peek().is_some() {
if self.current_builder.is_none() {
match (self.nullable, self.options.is_rle) {
Expand Down Expand Up @@ -163,6 +163,15 @@ impl<T: PrimitiveFixedWidthEncode> ColumnBuilder<T::ArrayType> for PrimitiveColu
}
}

if first_flag {
if let Some(to_be_appended) = iter.peek() {
let mut first_key = vec![];
to_be_appended.unwrap().encode(&mut first_key);
self.block_index_builder.set_first_key(first_key);
}
first_flag = false;
}

let (row_count, should_finish) = match self.current_builder.as_mut().unwrap() {
BlockBuilderImpl::Plain(builder) => append_one_by_one(&mut iter, builder),
BlockBuilderImpl::PlainNullable(builder) => append_one_by_one(&mut iter, builder),
Expand Down

0 comments on commit aa51882

Please sign in to comment.