Skip to content

Commit db4cd7a

Browse files
authored
Merge pull request #58 from b41sh/bump-jsonb-0.4.2
bump jsonb 0.4.2
2 parents 46ad50f + abf3b06 commit db4cd7a

File tree

4 files changed

+53
-57
lines changed

4 files changed

+53
-57
lines changed

CHANGELOG.md

+5
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
## [v0.4.2] - 2024-09-19
2+
3+
### Added
4+
Feat: make `preserve_order` a default feature (#56)
5+
16
## [v0.4.1] - 2024-07-18
27

38
### Fixed

Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ keywords = ["json", "jsonb", "jsonpath"]
2222
license = "Apache-2.0"
2323
name = "jsonb"
2424
repository = "https://github.com/datafuselabs/jsonb"
25-
version = "0.4.1"
25+
version = "0.4.2"
2626
rust-version = "1.77"
2727

2828
[dependencies]

src/de.rs

+12-12
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() {

src/functions.rs

+35-44
Original file line numberDiff line numberDiff line change
@@ -2234,20 +2234,15 @@ fn delete_value_object_by_keypath<'a>(
22342234
obj: &mut BTreeMap<String, Value<'_>>,
22352235
keypath: &mut VecDeque<&'a KeyPath<'a>>,
22362236
) {
2237-
if let Some(path) = keypath.pop_front() {
2238-
match path {
2239-
KeyPath::QuotedName(name) | KeyPath::Name(name) => {
2240-
if keypath.is_empty() {
2241-
obj.remove(name.as_ref());
2242-
} else if let Some(val) = obj.get_mut(name.as_ref()) {
2243-
match val {
2244-
Value::Array(ref mut arr) => delete_value_array_by_keypath(arr, keypath),
2245-
Value::Object(ref mut obj) => delete_value_object_by_keypath(obj, keypath),
2246-
_ => {}
2247-
}
2248-
}
2237+
if let Some(KeyPath::QuotedName(name) | KeyPath::Name(name)) = keypath.pop_front() {
2238+
if keypath.is_empty() {
2239+
obj.remove(name.as_ref());
2240+
} else if let Some(val) = obj.get_mut(name.as_ref()) {
2241+
match val {
2242+
Value::Array(ref mut arr) => delete_value_array_by_keypath(arr, keypath),
2243+
Value::Object(ref mut obj) => delete_value_object_by_keypath(obj, keypath),
2244+
_ => {}
22492245
}
2250-
_ => {}
22512246
}
22522247
}
22532248
}
@@ -2346,49 +2341,45 @@ fn delete_jsonb_object_by_keypath<'a, 'b>(
23462341
keypath: &mut VecDeque<&'a KeyPath<'a>>,
23472342
) -> Result<Option<ObjectBuilder<'b>>, Error> {
23482343
match keypath.pop_front() {
2349-
Some(path) => match path {
2350-
KeyPath::QuotedName(name) | KeyPath::Name(name) => {
2351-
let mut builder = ObjectBuilder::new();
2352-
for (key, jentry, item) in iterate_object_entries(value, header) {
2353-
if !key.eq(name) {
2354-
builder.push_raw(key, jentry, item);
2355-
} else if !keypath.is_empty() {
2356-
match jentry.type_code {
2357-
CONTAINER_TAG => {
2358-
let item_header = read_u32(item, 0)?;
2359-
match item_header & CONTAINER_HEADER_TYPE_MASK {
2360-
ARRAY_CONTAINER_TAG => match delete_jsonb_array_by_keypath(
2344+
Some(KeyPath::QuotedName(name) | KeyPath::Name(name)) => {
2345+
let mut builder = ObjectBuilder::new();
2346+
for (key, jentry, item) in iterate_object_entries(value, header) {
2347+
if !key.eq(name) {
2348+
builder.push_raw(key, jentry, item);
2349+
} else if !keypath.is_empty() {
2350+
match jentry.type_code {
2351+
CONTAINER_TAG => {
2352+
let item_header = read_u32(item, 0)?;
2353+
match item_header & CONTAINER_HEADER_TYPE_MASK {
2354+
ARRAY_CONTAINER_TAG => {
2355+
match delete_jsonb_array_by_keypath(item, item_header, keypath)?
2356+
{
2357+
Some(item_builder) => builder.push_array(key, item_builder),
2358+
None => return Ok(None),
2359+
}
2360+
}
2361+
OBJECT_CONTAINER_TAG => {
2362+
match delete_jsonb_object_by_keypath(
23612363
item,
23622364
item_header,
23632365
keypath,
23642366
)? {
2365-
Some(item_builder) => builder.push_array(key, item_builder),
2366-
None => return Ok(None),
2367-
},
2368-
OBJECT_CONTAINER_TAG => {
2369-
match delete_jsonb_object_by_keypath(
2370-
item,
2371-
item_header,
2372-
keypath,
2373-
)? {
2374-
Some(item_builder) => {
2375-
builder.push_object(key, item_builder)
2376-
}
2377-
None => return Ok(None),
2367+
Some(item_builder) => {
2368+
builder.push_object(key, item_builder)
23782369
}
2370+
None => return Ok(None),
23792371
}
2380-
_ => unreachable!(),
23812372
}
2373+
_ => unreachable!(),
23822374
}
2383-
_ => return Ok(None),
23842375
}
2376+
_ => return Ok(None),
23852377
}
23862378
}
2387-
Ok(Some(builder))
23882379
}
2389-
_ => Ok(None),
2390-
},
2391-
None => Ok(None),
2380+
Ok(Some(builder))
2381+
}
2382+
_ => Ok(None),
23922383
}
23932384
}
23942385

0 commit comments

Comments
 (0)