Skip to content

Commit 37d07f0

Browse files
authored
Refactor: Implements serde trait for RawJsonb (#77)
* Refactor: Implements `serde::de::Deserializer` and `serde::ser::Serializer` for `RawJsonb` * refactor code struct * fix * fix clippy
1 parent 7694b92 commit 37d07f0

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

41 files changed

+5703
-4586
lines changed

Cargo.toml

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,11 @@ byteorder = "1.5.0"
3030
fast-float2 = "0.2.3"
3131
itoa = "1.0"
3232
nom = "7.1.3"
33+
num-traits = "0.2.19"
3334
ordered-float = { version = "4.5", default-features = false }
3435
rand = { version = "0.8.5", features = ["small_rng"] }
3536
ryu = "1.0"
37+
serde = "1.0"
3638
serde_json = { version = "1.0", default-features = false, features = ["std"] }
3739

3840
[dev-dependencies]
@@ -44,7 +46,9 @@ mockalloc = "0.1.2"
4446
criterion = "0.5.1"
4547

4648
[features]
47-
default = ["serde_json/preserve_order"]
49+
default = ["databend", "serde_json/preserve_order"]
50+
databend = []
51+
sqlite = []
4852

4953
[[bench]]
5054
name = "parser"

benches/get_path.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,9 @@ fn jsonb_get(data: &[u8], paths: &[&str], expected: &str) {
2323
.map(|p| jsonb::jsonpath::Path::DotField(std::borrow::Cow::Borrowed(p)))
2424
.collect::<Vec<_>>();
2525
let json_path = jsonb::jsonpath::JsonPath { paths };
26-
let mode = jsonb::jsonpath::Mode::Mixed;
2726

2827
let raw_jsonb = jsonb::RawJsonb::new(data);
29-
let result_jsonb = raw_jsonb.get_by_path_opt(&json_path, mode).unwrap();
28+
let result_jsonb = raw_jsonb.select_value_by_path(&json_path).unwrap();
3029
assert!(result_jsonb.is_some());
3130
let result_jsonb = result_jsonb.unwrap();
3231
let result_raw_jsonb = result_jsonb.as_raw();

src/builder.rs

Lines changed: 0 additions & 204 deletions
This file was deleted.

src/constants.rs

Lines changed: 0 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -12,41 +12,6 @@
1212
// See the License for the specific language governing permissions and
1313
// limitations under the License.
1414

15-
// JSONB header constants
16-
pub(crate) const ARRAY_PREFIX: u8 = 0x80;
17-
pub(crate) const OBJECT_PREFIX: u8 = 0x40;
18-
pub(crate) const SCALAR_PREFIX: u8 = 0x20;
19-
20-
pub(crate) const ARRAY_CONTAINER_TAG: u32 = 0x80000000;
21-
pub(crate) const OBJECT_CONTAINER_TAG: u32 = 0x40000000;
22-
pub(crate) const SCALAR_CONTAINER_TAG: u32 = 0x20000000;
23-
24-
pub(crate) const CONTAINER_HEADER_TYPE_MASK: u32 = 0xE0000000;
25-
pub(crate) const CONTAINER_HEADER_LEN_MASK: u32 = 0x1FFFFFFF;
26-
27-
// JSONB JEntry constants
28-
pub(crate) const NULL_TAG: u32 = 0x00000000;
29-
pub(crate) const STRING_TAG: u32 = 0x10000000;
30-
pub(crate) const NUMBER_TAG: u32 = 0x20000000;
31-
pub(crate) const FALSE_TAG: u32 = 0x30000000;
32-
pub(crate) const TRUE_TAG: u32 = 0x40000000;
33-
pub(crate) const CONTAINER_TAG: u32 = 0x50000000;
34-
35-
// JSONB number constants
36-
pub(crate) const NUMBER_ZERO: u8 = 0x00;
37-
pub(crate) const NUMBER_NAN: u8 = 0x10;
38-
pub(crate) const NUMBER_INF: u8 = 0x20;
39-
pub(crate) const NUMBER_NEG_INF: u8 = 0x30;
40-
pub(crate) const NUMBER_INT: u8 = 0x40;
41-
pub(crate) const NUMBER_UINT: u8 = 0x50;
42-
pub(crate) const NUMBER_FLOAT: u8 = 0x60;
43-
44-
// @todo support offset mode
45-
#[allow(dead_code)]
46-
pub(crate) const JENTRY_IS_OFF_FLAG: u32 = 0x80000000;
47-
pub(crate) const JENTRY_TYPE_MASK: u32 = 0x70000000;
48-
pub(crate) const JENTRY_OFF_LEN_MASK: u32 = 0x0FFFFFFF;
49-
5015
// JSON text constants
5116
pub(crate) const UNICODE_LEN: usize = 4;
5217

@@ -68,7 +33,6 @@ pub(crate) const STRING_LEVEL: u8 = 4;
6833
pub(crate) const NUMBER_LEVEL: u8 = 3;
6934
pub(crate) const TRUE_LEVEL: u8 = 2;
7035
pub(crate) const FALSE_LEVEL: u8 = 1;
71-
pub(crate) const INVALID_LEVEL: u8 = 0;
7236

7337
pub(crate) const TYPE_STRING: &str = "string";
7438
pub(crate) const TYPE_NULL: &str = "null";

0 commit comments

Comments
 (0)