From 1c69c1f34d45c3e3321c7dec2bd25ebd2ee5f0e5 Mon Sep 17 00:00:00 2001 From: baishen Date: Thu, 19 Sep 2024 17:53:23 +0800 Subject: [PATCH 1/2] bump jsonb 0.4.2 --- CHANGELOG.md | 5 +++++ Cargo.toml | 2 +- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 0d0f42b..5a01d4e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,8 @@ +## [v0.4.2] - 2024-09-19 + +### Added +Feat: make `preserve_order` a default feature (#56) + ## [v0.4.1] - 2024-07-18 ### Fixed diff --git a/Cargo.toml b/Cargo.toml index 07018c1..3c4722e 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -22,7 +22,7 @@ keywords = ["json", "jsonb", "jsonpath"] license = "Apache-2.0" name = "jsonb" repository = "https://github.com/datafuselabs/jsonb" -version = "0.4.1" +version = "0.4.2" rust-version = "1.77" [dependencies] From abf3b06a1ca75116d9e002cbbf643bff25b33e33 Mon Sep 17 00:00:00 2001 From: baishen Date: Thu, 19 Sep 2024 18:08:32 +0800 Subject: [PATCH 2/2] fix clippy --- src/de.rs | 24 +++++++-------- src/functions.rs | 79 +++++++++++++++++++++--------------------------- 2 files changed, 47 insertions(+), 56 deletions(-) diff --git a/src/de.rs b/src/de.rs index c51f77c..c818cf1 100644 --- a/src/de.rs +++ b/src/de.rs @@ -40,19 +40,19 @@ use super::value::Value; /// `Number`, `String` and `Container`. They have three different decode methods. /// 1. `Null`, `True` and `False` can be obtained by `JEntry`, no extra work required. /// 2. `Number` and `String` has related `RawData`, `JEntry` store the length -/// or offset of this data, the `Value` can be read out and then decoded. +/// or offset of this data, the `Value` can be read out and then decoded. /// 3. `Container` is actually a nested `Array` or `Object` with the same structure, -/// `JEntry` store the length or offset of the lower-level `Header`, -/// from where the same decode process can begin. - -/// `RawData` is the encoded `Value`. -/// `Number` is a variable-length `Decimal`, store both int and float value. -/// `String` is the original string, can be borrowed directly without extra decode. -/// `Array` and `Object` is a lower-level encoded `JSONB` value. -/// The upper-level doesn't care about the specific content. -/// Decode can be executed recursively. - -/// Decode `JSONB` Value from binary bytes. +/// `JEntry` store the length or offset of the lower-level `Header`, +/// from where the same decode process can begin. +/// +/// `RawData` is the encoded `Value`. +/// `Number` is a variable-length `Decimal`, store both int and float value. +/// `String` is the original string, can be borrowed directly without extra decode. +/// `Array` and `Object` is a lower-level encoded `JSONB` value. +/// The upper-level doesn't care about the specific content. +/// Decode can be executed recursively. +/// +/// Decode `JSONB` Value from binary bytes. pub fn from_slice(buf: &[u8]) -> Result, Error> { let mut decoder = Decoder::new(buf); match decoder.decode() { diff --git a/src/functions.rs b/src/functions.rs index 032d182..3bfb913 100644 --- a/src/functions.rs +++ b/src/functions.rs @@ -2234,20 +2234,15 @@ fn delete_value_object_by_keypath<'a>( obj: &mut BTreeMap>, keypath: &mut VecDeque<&'a KeyPath<'a>>, ) { - if let Some(path) = keypath.pop_front() { - match path { - KeyPath::QuotedName(name) | KeyPath::Name(name) => { - if keypath.is_empty() { - obj.remove(name.as_ref()); - } else if let Some(val) = obj.get_mut(name.as_ref()) { - match val { - Value::Array(ref mut arr) => delete_value_array_by_keypath(arr, keypath), - Value::Object(ref mut obj) => delete_value_object_by_keypath(obj, keypath), - _ => {} - } - } + if let Some(KeyPath::QuotedName(name) | KeyPath::Name(name)) = keypath.pop_front() { + if keypath.is_empty() { + obj.remove(name.as_ref()); + } else if let Some(val) = obj.get_mut(name.as_ref()) { + match val { + Value::Array(ref mut arr) => delete_value_array_by_keypath(arr, keypath), + Value::Object(ref mut obj) => delete_value_object_by_keypath(obj, keypath), + _ => {} } - _ => {} } } } @@ -2346,49 +2341,45 @@ fn delete_jsonb_object_by_keypath<'a, 'b>( keypath: &mut VecDeque<&'a KeyPath<'a>>, ) -> Result>, Error> { match keypath.pop_front() { - Some(path) => match path { - KeyPath::QuotedName(name) | KeyPath::Name(name) => { - let mut builder = ObjectBuilder::new(); - for (key, jentry, item) in iterate_object_entries(value, header) { - if !key.eq(name) { - builder.push_raw(key, jentry, item); - } else if !keypath.is_empty() { - match jentry.type_code { - CONTAINER_TAG => { - let item_header = read_u32(item, 0)?; - match item_header & CONTAINER_HEADER_TYPE_MASK { - ARRAY_CONTAINER_TAG => match delete_jsonb_array_by_keypath( + Some(KeyPath::QuotedName(name) | KeyPath::Name(name)) => { + let mut builder = ObjectBuilder::new(); + for (key, jentry, item) in iterate_object_entries(value, header) { + if !key.eq(name) { + builder.push_raw(key, jentry, item); + } else if !keypath.is_empty() { + match jentry.type_code { + CONTAINER_TAG => { + let item_header = read_u32(item, 0)?; + match item_header & CONTAINER_HEADER_TYPE_MASK { + ARRAY_CONTAINER_TAG => { + match delete_jsonb_array_by_keypath(item, item_header, keypath)? + { + Some(item_builder) => builder.push_array(key, item_builder), + None => return Ok(None), + } + } + OBJECT_CONTAINER_TAG => { + match delete_jsonb_object_by_keypath( item, item_header, keypath, )? { - Some(item_builder) => builder.push_array(key, item_builder), - None => return Ok(None), - }, - OBJECT_CONTAINER_TAG => { - match delete_jsonb_object_by_keypath( - item, - item_header, - keypath, - )? { - Some(item_builder) => { - builder.push_object(key, item_builder) - } - None => return Ok(None), + Some(item_builder) => { + builder.push_object(key, item_builder) } + None => return Ok(None), } - _ => unreachable!(), } + _ => unreachable!(), } - _ => return Ok(None), } + _ => return Ok(None), } } - Ok(Some(builder)) } - _ => Ok(None), - }, - None => Ok(None), + Ok(Some(builder)) + } + _ => Ok(None), } }