Skip to content

Commit df1de53

Browse files
committed
merge
2 parents bdcc6a4 + ace7386 commit df1de53

File tree

19 files changed

+1757
-236
lines changed

19 files changed

+1757
-236
lines changed

CHANGELOG.md

Lines changed: 67 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,38 +1,71 @@
1+
## [v0.4.4] - 2024-11-16
2+
3+
### Fixed
4+
5+
- Fix: panic when facing corrupted jsonb (#67)
6+
7+
### Added
8+
9+
- Bump fast-float2 v0.2.3 (#69)
10+
- Feat: add a function to parse jsonb only (#66)
11+
- Feat: support `object_delete` and `object_pick` function (#65)
12+
- Feat: support `object_insert` function (#64)
13+
- Feat: Support json array functions (#62)
14+
- Feat: add lazy value (#61)
15+
16+
## [v0.4.3] - 2024-09-30
17+
18+
### Fixed
19+
20+
- Fix: Fix compare object value with different length panic (#59)
21+
22+
## [v0.4.2] - 2024-09-19
23+
24+
### Added
25+
26+
- Feat: make `preserve_order` a default feature (#56)
27+
28+
## [v0.4.1] - 2024-07-18
29+
30+
### Fixed
31+
32+
- Fix: Fix jsonpath selector unwrap panic. (#53)
33+
134
## [v0.4.0] - 2024-05-17
235

336
### Fixed
437

5-
Fix: Fix get by keypath with null value. (#47)
6-
Fix: Handle invalid jsonb value to avoid panic in functions. (#46)
7-
Fix: Fix builder & concat container jentry len. (#43)
38+
- Fix: Fix get by keypath with null value. (#47)
39+
- Fix: Handle invalid jsonb value to avoid panic in functions. (#46)
40+
- Fix: Fix builder & concat container jentry len. (#43)
841

942
### Added
1043

11-
Feat: Support convert jsonb value to `serde_json` value. (#49)
12-
Feat: Add `exists` filter expression. (48)`
13-
Feat: Add `delete_by_keypath`. (#45)
14-
Feat: Add `delete_by_index` & `delete_by_name`. (#44)
15-
Feat: Add `concat` & improve `strip_nulls`. (#42)
16-
Feat: Add jsonpath predicate support. (#41)
17-
Feat: Add `contains` api. (#40)
18-
Feat: Add `exists_any_keys` & `exists_all_keys`. (#38)
19-
Feat: Support parse key paths. (#37)
20-
Feat: Add `get_by_keypath`. (#36)
44+
- Feat: Support convert jsonb value to `serde_json` value. (#49)
45+
- Feat: Add `exists` filter expression. (48)`
46+
- Feat: Add `delete_by_keypath`. (#45)
47+
- Feat: Add `delete_by_index` & `delete_by_name`. (#44)
48+
- Feat: Add `concat` & improve `strip_nulls`. (#42)
49+
- Feat: Add jsonpath predicate support. (#41)
50+
- Feat: Add `contains` api. (#40)
51+
- Feat: Add `exists_any_keys` & `exists_all_keys`. (#38)
52+
- Feat: Support parse key paths. (#37)
53+
- Feat: Add `get_by_keypath`. (#36)
2154

2255
## [v0.3.0] - 2023-10-13
2356

2457
### Added
2558

26-
Docs: Add more jsonb encoding format descriptions. (#34)
27-
Feat: Support `object_each` api. (#33)
28-
Feat: Support `path_exists` api. (#32)
29-
Feat: Support `type_of` api. (#31)
30-
Feat: Support `strip_nulls` api. (#30)
31-
Perf: Add benches for parser and `get_path`. (#29)
32-
Chore: Add check fmt and clippy. (#27)
33-
Feat: Support `to_pretty_string` api. (#26)
34-
Feat: Support `traverse_check_string` function. (#25)
35-
Feat: Improve json path selector using less memory. (#24)
59+
- Docs: Add more jsonb encoding format descriptions. (#34)
60+
- Feat: Support `object_each` api. (#33)
61+
- Feat: Support `path_exists` api. (#32)
62+
- Feat: Support `type_of` api. (#31)
63+
- Feat: Support `strip_nulls` api. (#30)
64+
- Perf: Add benches for parser and `get_path`. (#29)
65+
- Chore: Add check fmt and clippy. (#27)
66+
- Feat: Support `to_pretty_string` api. (#26)
67+
- Feat: Support `traverse_check_string` function. (#25)
68+
- Feat: Improve json path selector using less memory. (#24)
3669

3770
## [v0.2.3] - 2023-07-10
3871

@@ -81,8 +114,14 @@ Feat: Improve json path selector using less memory. (#24)
81114
- Implement `JSONB` encodes and decodes.
82115
- Implemented a number of `JSONB` functions.
83116

84-
85-
[v0.2.2]: https://github.com/datafuselabs/jsonb/compare/v0.2.1...v0.2.2
86-
[v0.2.1]: https://github.com/datafuselabs/jsonb/compare/v0.2.0...v0.2.1
87-
[v0.2.0]: https://github.com/datafuselabs/jsonb/compare/v0.1.1...v0.2.0
88-
[v0.1.1]: https://github.com/datafuselabs/jsonb/compare/v0.1.0...v0.1.1
117+
[v0.4.4]: https://github.com/databendlabs/jsonb/compare/v0.4.3...v0.4.4
118+
[v0.4.3]: https://github.com/databendlabs/jsonb/compare/v0.4.2...v0.4.3
119+
[v0.4.2]: https://github.com/databendlabs/jsonb/compare/v0.4.1...v0.4.2
120+
[v0.4.1]: https://github.com/databendlabs/jsonb/compare/v0.4.0...v0.4.1
121+
[v0.4.0]: https://github.com/databendlabs/jsonb/compare/v0.3.0...v0.4.0
122+
[v0.3.0]: https://github.com/databendlabs/jsonb/compare/v0.2.3...v0.3.0
123+
[v0.2.3]: https://github.com/databendlabs/jsonb/compare/v0.2.2...v0.2.3
124+
[v0.2.2]: https://github.com/databendlabs/jsonb/compare/v0.2.1...v0.2.2
125+
[v0.2.1]: https://github.com/databendlabs/jsonb/compare/v0.2.0...v0.2.1
126+
[v0.2.0]: https://github.com/databendlabs/jsonb/compare/v0.1.1...v0.2.0
127+
[v0.1.1]: https://github.com/databendlabs/jsonb/compare/v0.1.0...v0.1.1

Cargo.toml

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -17,25 +17,23 @@ authors = ["Databend Authors <opensource@datafuselabs.com>"]
1717
categories = ["encoding"]
1818
description = "JSONB implement in Rust."
1919
edition = "2021"
20-
homepage = "https://github.com/datafuselabs/jsonb"
20+
homepage = "https://github.com/databendlabs/jsonb"
2121
keywords = ["json", "jsonb", "jsonpath"]
2222
license = "Apache-2.0"
2323
name = "jsonb"
24-
repository = "https://github.com/datafuselabs/jsonb"
25-
version = "0.4.0"
24+
repository = "https://github.com/databendlabs/jsonb"
25+
version = "0.4.4"
2626
rust-version = "1.77"
2727

2828
[dependencies]
2929
byteorder = "1.5.0"
30-
fast-float = "0.2.0"
30+
fast-float2 = "0.2.3"
3131
itoa = "1.0"
3232
nom = "7.1.3"
33-
ordered-float = { version = "4.2", default-features = false }
33+
ordered-float = { version = "4.5", default-features = false }
3434
rand = { version = "0.8.5", features = ["small_rng"] }
3535
ryu = "1.0"
36-
serde_json = { version = "1.0", default-features = false, features = [
37-
"preserve_order",
38-
] }
36+
serde_json = { version = "1.0", default-features = false, features = ["std"] }
3937

4038
[dev-dependencies]
4139
goldenfile = "1.7"
@@ -45,6 +43,9 @@ simd-json = "0.13.10"
4543
mockalloc = "0.1.2"
4644
criterion = "0.5.1"
4745

46+
[features]
47+
default = ["serde_json/preserve_order"]
48+
4849
[[bench]]
4950
name = "parser"
5051
harness = false

benches/get_path.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ fn jsonb_get(data: &[u8], paths: &[&str], expected: &str) {
2727
let mut result_data = vec![];
2828
let mut result_offsets = vec![];
2929

30-
jsonb::get_by_path(data, json_path, &mut result_data, &mut result_offsets);
30+
jsonb::get_by_path(data, json_path, &mut result_data, &mut result_offsets).unwrap();
3131

3232
let s = jsonb::as_str(&result_data).unwrap();
3333
assert_eq!(s, expected);

src/de.rs

Lines changed: 21 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -40,19 +40,19 @@ use super::value::Value;
4040
/// `Number`, `String` and `Container`. They have three different decode methods.
4141
/// 1. `Null`, `True` and `False` can be obtained by `JEntry`, no extra work required.
4242
/// 2. `Number` and `String` has related `RawData`, `JEntry` store the length
43-
/// or offset of this data, the `Value` can be read out and then decoded.
43+
/// or offset of this data, the `Value` can be read out and then decoded.
4444
/// 3. `Container` is actually a nested `Array` or `Object` with the same structure,
45-
/// `JEntry` store the length or offset of the lower-level `Header`,
46-
/// from where the same decode process can begin.
47-
48-
/// `RawData` is the encoded `Value`.
49-
/// `Number` is a variable-length `Decimal`, store both int and float value.
50-
/// `String` is the original string, can be borrowed directly without extra decode.
51-
/// `Array` and `Object` is a lower-level encoded `JSONB` value.
52-
/// The upper-level doesn't care about the specific content.
53-
/// Decode can be executed recursively.
54-
55-
/// Decode `JSONB` Value from binary bytes.
45+
/// `JEntry` store the length or offset of the lower-level `Header`,
46+
/// from where the same decode process can begin.
47+
///
48+
/// `RawData` is the encoded `Value`.
49+
/// `Number` is a variable-length `Decimal`, store both int and float value.
50+
/// `String` is the original string, can be borrowed directly without extra decode.
51+
/// `Array` and `Object` is a lower-level encoded `JSONB` value.
52+
/// The upper-level doesn't care about the specific content.
53+
/// Decode can be executed recursively.
54+
///
55+
/// Decode `JSONB` Value from binary bytes.
5656
pub fn from_slice(buf: &[u8]) -> Result<Value<'_>, Error> {
5757
let mut decoder = Decoder::new(buf);
5858
match decoder.decode() {
@@ -62,6 +62,11 @@ pub fn from_slice(buf: &[u8]) -> Result<Value<'_>, Error> {
6262
}
6363
}
6464

65+
pub fn parse_jsonb(buf: &[u8]) -> Result<Value<'_>, Error> {
66+
let mut decoder = Decoder::new(buf);
67+
decoder.decode()
68+
}
69+
6570
#[repr(transparent)]
6671
pub struct Decoder<'a> {
6772
buf: &'a [u8],
@@ -111,13 +116,15 @@ impl<'a> Decoder<'a> {
111116
FALSE_TAG => Ok(Value::Bool(false)),
112117
STRING_TAG => {
113118
let offset = jentry.length as usize;
114-
let s = unsafe { std::str::from_utf8_unchecked(&self.buf[..offset]) };
119+
let string = &self.buf.get(..offset).ok_or(Error::InvalidUtf8)?;
120+
let s = unsafe { std::str::from_utf8_unchecked(string) };
115121
self.buf = &self.buf[offset..];
116122
Ok(Value::String(Cow::Borrowed(s)))
117123
}
118124
NUMBER_TAG => {
119125
let offset = jentry.length as usize;
120-
let n = Number::decode(&self.buf[..offset]);
126+
let number = &self.buf.get(..offset).ok_or(Error::InvalidJsonbNumber)?;
127+
let n = Number::decode(number)?;
121128
self.buf = &self.buf[offset..];
122129
Ok(Value::Number(n))
123130
}

src/error.rs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,12 +79,15 @@ pub enum Error {
7979
InvalidJsonb,
8080
InvalidJsonbHeader,
8181
InvalidJsonbJEntry,
82+
InvalidJsonbNumber,
8283

8384
InvalidJsonPath,
8485
InvalidJsonPathPredicate,
8586
InvalidKeyPath,
8687

8788
InvalidJsonType,
89+
InvalidObject,
90+
ObjectDuplicateKey,
8891

8992
Syntax(ParseErrorCode, usize),
9093
}
@@ -109,3 +112,9 @@ impl From<std::str::Utf8Error> for Error {
109112
Error::InvalidUtf8
110113
}
111114
}
115+
116+
impl From<nom::Err<nom::error::Error<&[u8]>>> for Error {
117+
fn from(_error: nom::Err<nom::error::Error<&[u8]>>) -> Self {
118+
Error::InvalidJsonb
119+
}
120+
}

0 commit comments

Comments
 (0)