Skip to content

Commit 95f44d8

Browse files
authored
fix: remove unused attrs field (#41)
* refactor: remove unused attrs field * chore: cargo fix * chore: rm enum derive * fix: validate DeltaOfDelta bytes length in deserialization
1 parent d74f7c1 commit 95f44d8

12 files changed

Lines changed: 102 additions & 152 deletions

File tree

.github/workflows/rust-tests.yml

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
name: Rust Tests
2+
3+
on:
4+
push:
5+
branches: [ main ]
6+
pull_request:
7+
branches: [ main ]
8+
9+
env:
10+
CARGO_TERM_COLOR: always
11+
12+
jobs:
13+
test:
14+
name: Cargo Test
15+
runs-on: ubuntu-latest
16+
steps:
17+
- uses: actions/checkout@v3
18+
19+
- name: Install Rust toolchain
20+
uses: actions-rs/toolchain@v1
21+
with:
22+
profile: minimal
23+
toolchain: stable
24+
override: true
25+
26+
- name: Cache dependencies
27+
uses: actions/cache@v3
28+
with:
29+
path: |
30+
~/.cargo/registry
31+
~/.cargo/git
32+
target
33+
key: ${{ runner.os }}-cargo-${{ hashFiles('**/Cargo.lock') }}
34+
restore-keys: ${{ runner.os }}-cargo-
35+
36+
- name: Run tests
37+
uses: actions-rs/cargo@v1
38+
with:
39+
command: test
40+
args: --workspace --all-features

Cargo.toml

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,14 @@
11
[workspace]
22
members = ["columnar", "columnar_derive", "fuzz"]
3+
resolver = "2"
4+
5+
# Added profile settings from fuzz/Cargo.toml
6+
[profile.release]
7+
debug = 1
8+
9+
# Added profile settings from columnar/Cargo.toml
10+
[profile.dev.package.insta]
11+
opt-level = 3
12+
13+
[profile.dev.package.similar]
14+
opt-level = 3

README.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ It allows the contents that need to be serialized and deserialized to be encoded
66

77
For more detailed introduction, please refer to this `Notion` link: [Serde-Columnar](https://www.notion.so/loro-dev/Serde-Columnar-Ergonomic-columnar-storage-encoding-crate-7b0c86d6f8d24e4da45a1e2ebd86741c?pvs=4).
88

9+
![Image](https://github.com/user-attachments/assets/48475c7d-61c8-4903-892d-70d702137dba)
10+
911
## 🚧 This crate is in progress and not stable, should not be used in production environments
1012

1113
## Features 🚀
@@ -30,7 +32,7 @@ Or edit your `Cargo.toml` and add `serde_columnar` as dependency:
3032

3133
```toml
3234
[dependencies]
33-
serde_columnar = "0.3.10"
35+
serde_columnar = "0.3.11"
3436
```
3537

3638
### Container Attribute

columnar/Cargo.toml

Lines changed: 11 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "serde_columnar"
3-
version = "0.3.10"
3+
version = "0.3.11"
44
edition = "2021"
55
authors = ["leonzhao <leeeon233@gmail.com>", "zxch3n <remch183@outlook.com>"]
66
license = "MIT OR Apache-2.0"
@@ -9,22 +9,23 @@ readme = "README.md"
99
repository = "https://github.com/loro-dev/columnar"
1010
keywords = ["columnar", "column-oriented", "compression", "serde", "compatible"]
1111

12+
[dependencies]
13+
serde = { version = "1.0" }
14+
serde_columnar_derive = { path = "../columnar_derive", version = "0.3.6" }
15+
postcard = { version = "^1.1.0", features = ["alloc"] }
16+
thiserror = "1.0"
17+
lazy_static = { version = "1.4", optional = true }
18+
bincode = { version = "1.3.3", optional = true }
19+
itertools = "^0.11.0"
20+
flate2 = { version = "1.0", optional = true }
21+
1222
[dev-dependencies]
1323
serde = { version = "1.0.188", features = ["derive"] }
1424
criterion = "0.5.1"
1525
serde_json = "1.0"
1626
insta = { version = "1.31.0", features = ["yaml"] }
1727
rand = "0.8"
1828

19-
[dependencies]
20-
serde = { version = "1.0" }
21-
serde_columnar_derive = { path = "../columnar_derive", version = "0.3.5" }
22-
postcard = { version = "1.0", features = ["alloc"] }
23-
thiserror = "1.0"
24-
lazy_static = { version = "1.4", optional = true }
25-
bincode = { version = "1.3.3", optional = true }
26-
itertools = "0.11.0"
27-
flate2 = { version = "1.0", optional = true }
2829

2930
[[bench]]
3031
name = "columnar_bench"
@@ -43,9 +44,3 @@ required-features = ["analyze"]
4344

4445
[lib]
4546
doctest = false
46-
47-
[profile.dev.package.insta]
48-
opt-level = 3
49-
50-
[profile.dev.package.similar]
51-
opt-level = 3

columnar/src/iterable.rs

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ use crate::{
55
ColumnarError, DeltaOfDeltaDecoder, DeltaRleable, Rleable,
66
};
77
use postcard::Deserializer;
8+
use serde::de::Error;
89
use serde::Deserialize;
910

1011
pub struct GenericIter<'de, T> {
@@ -131,9 +132,8 @@ pub struct DeltaOfDeltaIter<'de, T> {
131132

132133
impl<'de, T: DeltaOfDeltable> DeltaOfDeltaIter<'de, T> {
133134
pub fn new(bytes: &'de [u8]) -> Self {
134-
Self {
135-
decoder: DeltaOfDeltaDecoder::new(bytes).unwrap(),
136-
}
135+
let decoder = DeltaOfDeltaDecoder::new(bytes).unwrap();
136+
Self { decoder }
137137
}
138138

139139
pub(crate) fn try_next(&mut self) -> Result<Option<T>, ColumnarError> {
@@ -301,6 +301,11 @@ impl<'de, T: DeltaOfDeltable> Deserialize<'de> for DeltaOfDeltaIter<'de, T> {
301301
D: serde::Deserializer<'de>,
302302
{
303303
let bytes: &'de [u8] = Deserialize::deserialize(deserializer)?;
304+
if bytes.len() < 2 {
305+
return Err(D::Error::custom(
306+
"DeltaOfDelta bytes should be at least 2 bytes",
307+
));
308+
}
304309
Ok(DeltaOfDeltaIter::new(bytes))
305310
}
306311
}

columnar/src/strategy/rle.rs

Lines changed: 9 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -528,7 +528,7 @@ impl<'de, T: DeltaOfDeltable> DeltaOfDeltaDecoder<'de, T> {
528528
let (head_num, bytes) = postcard::take_from_bytes(bytes)?;
529529
if bytes.is_empty() {
530530
return Err(ColumnarError::RleDecodeError(
531-
"invalid DeltaOfDelta input".to_string(),
531+
"Invalid DeltaOfDelta input".to_string(),
532532
));
533533
}
534534
let last_used_bit = bytes[0];
@@ -543,20 +543,6 @@ impl<'de, T: DeltaOfDeltable> DeltaOfDeltaDecoder<'de, T> {
543543
last_used_bit,
544544
_t: PhantomData,
545545
})
546-
547-
// let (head_num, bytes) = postcard::take_from_bytes(bytes).unwrap();
548-
// let last_used_bit = bytes[0];
549-
// let bits = &bytes[1..];
550-
// Self {
551-
// bits: &bytes,
552-
// head_num: None,
553-
// prev_value: 0,
554-
// prev_delta: 0,
555-
// index: 0,
556-
// current_bits_index: 0,
557-
// last_used_bit: 0,
558-
// _t: PhantomData,
559-
// }
560546
}
561547

562548
pub fn decode(&mut self) -> Result<Vec<T>, ColumnarError> {
@@ -591,7 +577,11 @@ impl<'de, T: DeltaOfDeltable> DeltaOfDeltaDecoder<'de, T> {
591577
self.prev_value += self.prev_delta;
592578
}
593579
None => return Ok(None),
594-
_ => panic!("delta of delta read flag should be 0 or 1"),
580+
_ => {
581+
return Err(ColumnarError::RleDecodeError(
582+
"delta of delta read flag should be 0 or 1".to_string(),
583+
))
584+
}
595585
};
596586
}
597587
// println!("prev_value {}", self.prev_value);
@@ -720,12 +710,8 @@ impl<'de, T: DeltaOfDeltable> Iterator for DeltaOfDeltaDecoder<'de, T> {
720710

721711
#[cfg(test)]
722712
mod test {
723-
724-
use rand::Rng;
725-
726-
use crate::column::delta_rle;
727-
728713
use super::{DeltaOfDeltaEncoder, DeltaRleEncoder};
714+
use rand::Rng;
729715

730716
#[test]
731717
fn test_rle() {
@@ -804,8 +790,8 @@ mod test {
804790
let mut delta_of_delta = DeltaOfDeltaEncoder::new();
805791
while n < 5000 {
806792
if rng.gen_bool(0.93) {
807-
delta_rle.append(i);
808-
delta_of_delta.append(i);
793+
delta_rle.append(i).unwrap();
794+
delta_of_delta.append(i).unwrap();
809795
n += 1;
810796
}
811797
i += 1;

columnar/tests/integration/iterable.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ fn row_iterable_strategy() {
1717
_rle: AnyRleIter::new(&[]),
1818
_delta_rle: DeltaRleIter::new(&[]),
1919
_bool_rle: BoolRleIter::new(&[]),
20-
_delta_of_delta: DeltaOfDeltaIter::new(&[]),
20+
_delta_of_delta: DeltaOfDeltaIter::new(&[0, 0]),
2121
};
2222
}
2323

columnar/tests/integration/snapshots/tests__integration__attribute__delta_of_delta.snap

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@ expression: bytes
44
---
55
- 1
66
- 1
7-
- 4
7+
- 5
8+
- 1
89
- 2
910
- 2
1011
- 160
1112
- 0
12-

columnar_derive/Cargo.toml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
[package]
22
name = "serde_columnar_derive"
3-
version = "0.3.5"
3+
version = "0.3.6"
4+
edition = "2021"
45
authors = ["leonzhao <leeeon233@gmail.com>", "zxch3n <remch183@outlook.com>"]
56
license = "MIT OR Apache-2.0"
67
description = "Macros implementation of #[columnar]"
@@ -15,7 +16,7 @@ doctest = false
1516
proc-macro2 = "1.0"
1617
quote = "1.0"
1718
syn = { version = "2.0", features = ["full"] }
18-
darling = "0.20.10"
19+
darling = "^0.20.10"
1920

2021
[features]
2122
analyze = []

columnar_derive/src/args.rs

Lines changed: 5 additions & 79 deletions
Original file line numberDiff line numberDiff line change
@@ -29,10 +29,9 @@ pub struct DeriveArgs {
2929
pub struct FieldArgs {
3030
/// the name of field
3131
pub ident: Option<syn::Ident>,
32-
pub vis: syn::Visibility,
32+
// pub vis: syn::Visibility,
3333
/// the type of field
3434
pub ty: Type,
35-
pub attrs: Vec<syn::Attribute>,
3635
// custom attributes
3736
/// The index of the field in the struct, starts from 0 default.
3837
pub index: Option<usize>,
@@ -51,21 +50,6 @@ pub struct FieldArgs {
5150
pub iter: Option<Type>,
5251
}
5352

54-
#[derive(FromVariant, Debug)]
55-
#[darling(attributes(columnar))]
56-
pub struct VariantArgs {
57-
// pub ident: syn::Ident,
58-
// pub vis: syn::Visibility,
59-
// pub ty: syn::Type,
60-
pub attrs: Vec<syn::Attribute>,
61-
/// the type of the column format, vec or map.
62-
#[darling(rename = "class")]
63-
pub type_: Option<String>,
64-
/// If skip, this field will be ignored.
65-
#[darling(default)]
66-
pub skip: bool,
67-
}
68-
6953
#[derive(Debug, Clone, Copy)]
7054
pub enum Strategy {
7155
Rle,
@@ -98,11 +82,10 @@ pub enum AsType {
9882
}
9983

10084
pub trait Args {
101-
fn ident(&self) -> Option<syn::Ident>;
85+
// fn ident(&self) -> Option<syn::Ident>;
10286
fn ty(&self) -> Option<syn::Type>;
103-
fn attrs(&self) -> &[syn::Attribute];
104-
fn index(&self) -> Option<usize>;
105-
fn optional(&self) -> bool;
87+
// fn index(&self) -> Option<usize>;
88+
// fn optional(&self) -> bool;
10689
fn strategy(&self) -> Strategy;
10790
fn can_copy(&self) -> bool {
10891
match self.strategy() {
@@ -147,21 +130,10 @@ pub trait Args {
147130
}
148131

149132
impl Args for FieldArgs {
150-
fn ident(&self) -> Option<syn::Ident> {
151-
self.ident.clone()
152-
}
153133
fn ty(&self) -> Option<syn::Type> {
154134
Some(self.ty.clone())
155135
}
156-
fn attrs(&self) -> &[syn::Attribute] {
157-
&self.attrs
158-
}
159-
fn index(&self) -> Option<usize> {
160-
self.index
161-
}
162-
fn optional(&self) -> bool {
163-
self.optional
164-
}
136+
165137
fn strategy(&self) -> Strategy {
166138
Strategy::from_str(self.strategy.clone())
167139
}
@@ -265,50 +237,6 @@ impl Args for FieldArgs {
265237
}
266238
}
267239

268-
impl Args for VariantArgs {
269-
fn ident(&self) -> Option<syn::Ident> {
270-
None
271-
}
272-
fn ty(&self) -> Option<syn::Type> {
273-
None
274-
}
275-
fn attrs(&self) -> &[syn::Attribute] {
276-
&self.attrs
277-
}
278-
fn index(&self) -> Option<usize> {
279-
None
280-
}
281-
fn optional(&self) -> bool {
282-
false
283-
}
284-
fn strategy(&self) -> Strategy {
285-
Strategy::None
286-
}
287-
fn class(&self) -> Option<AsType> {
288-
match self.type_.as_deref() {
289-
Some("vec") => Some(AsType::Vec),
290-
Some("map") => Some(AsType::Map),
291-
Some(_) => Some(AsType::Other),
292-
None => None,
293-
}
294-
}
295-
fn borrow_lifetimes(&self) -> syn::Result<Option<BTreeSet<Lifetime>>> {
296-
unimplemented!("Variant have not implemented borrow")
297-
}
298-
299-
fn self_lifetime(&self) -> syn::Result<BTreeSet<Lifetime>> {
300-
unimplemented!("Variant have not implemented self_lifetime")
301-
}
302-
303-
fn has_borrow_lifetime(&self) -> bool {
304-
false
305-
}
306-
307-
fn lifetime(&self) -> syn::Result<BTreeSet<Lifetime>> {
308-
unimplemented!("Variant have not implemented borrow")
309-
}
310-
}
311-
312240
pub fn get_derive_args(args: &[NestedMeta]) -> syn::Result<DeriveArgs> {
313241
match DeriveArgs::from_list(args) {
314242
Ok(v) => Ok(v),
@@ -448,8 +376,6 @@ fn collect_lifetimes(ty: &syn::Type, out: &mut BTreeSet<syn::Lifetime>) {
448376
| syn::Type::ImplTrait(_)
449377
| syn::Type::Infer(_)
450378
| syn::Type::Verbatim(_) => {}
451-
452-
#[cfg_attr(all(test, exhaustive), deny(non_exhaustive_omitted_patterns))]
453379
_ => {}
454380
}
455381
}

0 commit comments

Comments
 (0)