Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

bump jsonb 0.4.2 #58

Merged
merged 2 commits into from
Sep 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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
Expand Down
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down
24 changes: 12 additions & 12 deletions src/de.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<Value<'_>, Error> {
let mut decoder = Decoder::new(buf);
match decoder.decode() {
Expand Down
79 changes: 35 additions & 44 deletions src/functions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2234,20 +2234,15 @@ fn delete_value_object_by_keypath<'a>(
obj: &mut BTreeMap<String, Value<'_>>,
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),
_ => {}
}
_ => {}
}
}
}
Expand Down Expand Up @@ -2346,49 +2341,45 @@ fn delete_jsonb_object_by_keypath<'a, 'b>(
keypath: &mut VecDeque<&'a KeyPath<'a>>,
) -> Result<Option<ObjectBuilder<'b>>, 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),
}
}

Expand Down
Loading