Skip to content

Commit

Permalink
feat: support columar encoding for datums
Browse files Browse the repository at this point in the history
  • Loading branch information
ShiKaiWi committed Aug 16, 2023
1 parent b59e07e commit 41bda2d
Show file tree
Hide file tree
Showing 11 changed files with 488 additions and 17 deletions.
42 changes: 27 additions & 15 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ bytes = "1.1.0"
bytes_ext = { path = "components/bytes_ext" }
catalog = { path = "catalog" }
catalog_impls = { path = "catalog_impls" }
ceresdbproto = "1.0.10"
ceresdbproto = { git = "https://github.com/ShiKaiWi/ceresdbproto.git", rev = "776dc2ee44bcc8217742268fef78a31a215235da" }
codec = { path = "components/codec" }
chrono = "0.4"
clap = "3.0"
Expand Down
1 change: 1 addition & 0 deletions analytic_engine/src/instance/write.rs
Original file line number Diff line number Diff line change
Expand Up @@ -566,6 +566,7 @@ impl<'a> Writer<'a> {
// mismatch during replaying
schema: Some(schema_pb::TableSchema::from(&self.table_data.schema())),
rows: encoded_rows,
cols: vec![],
};

// Encode payload
Expand Down
2 changes: 1 addition & 1 deletion common_types/src/row/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ use crate::{
time::Timestamp,
};

pub(crate) mod bitset;
pub mod bitset;
pub mod contiguous;

#[derive(Debug, Snafu)]
Expand Down
14 changes: 14 additions & 0 deletions components/codec/src/columnar/float.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
// Copyright 2023 The CeresDB Authors
//
// Licensed 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.

63 changes: 63 additions & 0 deletions components/codec/src/columnar/int.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
// Copyright 2023 The CeresDB Authors
//
// Licensed 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_ext::{Buf, BufMut};

use crate::columnar::{Result, ValuesDecoder, ValuesEncoder};

pub struct I32ValuesEncoder;

impl ValuesEncoder for I32ValuesEncoder {
type ValueType = i32;

fn encode<B, I>(&self, buf: &mut B, values: I) -> Result<()>
where
B: BufMut,
I: Iterator<Item = i32>,
{
for v in values {
buf.put_i32(v);
}

Ok(())
}

fn estimated_encoded_size<I>(&self, values: I) -> usize
where
I: Iterator<Item = i32>,
{
let (lower, higher) = values.size_hint();
let num = lower.max(higher.unwrap_or_default());
num * std::mem::size_of::<i32>()
}
}

pub struct I32ValuesDecoder;

impl ValuesDecoder for I32ValuesDecoder {
type ValueType = i32;

fn decode<B, F>(&self, buf: &mut B, mut f: F) -> Result<()>
where
B: Buf,
F: FnMut(i32) -> Result<()>,
{
while buf.remaining() > 0 {
let v = buf.get_i32();
f(v)?;
}

Ok(())
}
}
Loading

0 comments on commit 41bda2d

Please sign in to comment.