Skip to content

Commit 61bf3ef

Browse files
authored
chore: bump jsonb 0.5.0 (#17698)
* chore: bump jsonb 0.5.0 * fix tests * fix tests * bump jsonb v0.5
1 parent 58fa7cd commit 61bf3ef

File tree

5 files changed

+138
-30
lines changed

5 files changed

+138
-30
lines changed

Cargo.lock

Lines changed: 21 additions & 11 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -348,7 +348,7 @@ jaq-interpret = "1.5.0"
348348
jaq-parse = "1.0.3"
349349
jaq-std = "1.6.0"
350350
jiff = { version = "0.2.1", features = ["serde", "tzdb-bundle-always"] }
351-
jsonb = "0.4.4"
351+
jsonb = "0.5.0"
352352
jwt-simple = { version = "0.12.10", default-features = false, features = ["pure-rust"] }
353353
lenient_semver = "0.4.2"
354354
levenshtein_automata = "0.2.1"
@@ -406,7 +406,7 @@ openraft = { version = "0.10.0", features = [
406406
] }
407407
opensrv-mysql = { git = "https://github.com/databendlabs/opensrv.git", rev = "a1fb4da", features = ["tls"] }
408408
orc-rust = "0.5.0"
409-
ordered-float = { version = "4.5.0", default-features = false }
409+
ordered-float = { version = "5.0.0", default-features = false }
410410
ordq = "0.2.0"
411411
p256 = "0.13"
412412
parking_lot = "0.12.1"
@@ -640,7 +640,6 @@ color-eyre = { git = "https://github.com/eyre-rs/eyre.git", rev = "e5d92c3" }
640640
deltalake = { git = "https://github.com/delta-io/delta-rs", rev = "c149502" }
641641
display-more = { git = "https://github.com/databendlabs/display-more", tag = "v0.1.2" }
642642
ethnum = { git = "https://github.com/datafuse-extras/ethnum-rs", rev = "4cb05f1" }
643-
jsonb = { git = "https://github.com/databendlabs/jsonb", rev = "1a53512" }
644643
map-api = { git = "https://github.com/databendlabs/map-api", tag = "v0.2.3" }
645644
openai_api_rust = { git = "https://github.com/datafuse-extras/openai-api", rev = "819a0ed" }
646645
openraft = { git = "https://github.com/databendlabs/openraft", tag = "v0.10.0-alpha.9" }

src/query/functions/src/scalars/variant.rs

Lines changed: 28 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2261,20 +2261,35 @@ fn path_predicate_fn<'a>(
22612261
match json_row {
22622262
ScalarRef::Variant(v) => {
22632263
let jsonb = RawJsonb::new(v);
2264-
let res = if is_match {
2265-
jsonb.path_match(&path)
2266-
} else {
2267-
jsonb.path_exists(&path)
2268-
};
2269-
match res {
2270-
Ok(r) => {
2271-
output.push(r);
2272-
validity.push(true);
2264+
if is_match {
2265+
let res = jsonb.path_match(&path);
2266+
match res {
2267+
Ok(Some(r)) => {
2268+
output.push(r);
2269+
validity.push(true);
2270+
}
2271+
Ok(None) => {
2272+
output.push(false);
2273+
validity.push(false);
2274+
}
2275+
Err(err) => {
2276+
ctx.set_error(output.len(), err.to_string());
2277+
output.push(false);
2278+
validity.push(false);
2279+
}
22732280
}
2274-
Err(err) => {
2275-
ctx.set_error(output.len(), err.to_string());
2276-
output.push(false);
2277-
validity.push(false);
2281+
} else {
2282+
let res = jsonb.path_exists(&path);
2283+
match res {
2284+
Ok(r) => {
2285+
output.push(r);
2286+
validity.push(true);
2287+
}
2288+
Err(err) => {
2289+
ctx.set_error(output.len(), err.to_string());
2290+
output.push(false);
2291+
validity.push(false);
2292+
}
22782293
}
22792294
}
22802295
}

tests/sqllogictests/suites/query/functions/02_0051_function_semi_structureds_get.test

Lines changed: 85 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -383,7 +383,7 @@ statement ok
383383
CREATE TABLE IF NOT EXISTS t5(id Int null, obj Variant null) Engine = Fuse
384384

385385
statement ok
386-
insert into t5 values(1, '{"car_no":10,"测试\\"\\uD83D\\uDC8E":"a"}'), (2, '{"car_no":20}')
386+
insert into t5 values(1, '{"car_no":10,"测试\\"\\uD83D\\uDC8E":"a","nums":[2,3,4],"obj":{"a":{"b":[1,2]},"c":1}}'), (2, '{"car_no":20,"nums":[-10,-11],"obj":{"x":"y"}}')
387387

388388
query T
389389
select get(arr, 0) from t1
@@ -549,6 +549,11 @@ select id, json_path_query(arr, '$[*]?(@ > 1 && @ <= 3)') from t1
549549
1 2
550550
1 3
551551

552+
query IT
553+
select id, json_path_query(arr, '$[3][*]?(@ starts with "a")') from t1
554+
----
555+
1 "a"
556+
552557
query IT
553558
select id, json_path_query(arr, '$[*][1]') from t1
554559
----
@@ -704,6 +709,85 @@ select json_path_query_first(obj, '$.测试\\"\\uD83D\\uDC8E') from t5
704709
"a"
705710
NULL
706711

712+
query IT
713+
select id, json_path_query(obj, '$.obj.**') from t5
714+
----
715+
1 {"a":{"b":[1,2]},"c":1}
716+
1 {"b":[1,2]}
717+
1 [1,2]
718+
1 1
719+
1 2
720+
1 1
721+
2 {"x":"y"}
722+
2 "y"
723+
724+
query IT
725+
select id, json_path_query(obj, '$.obj.**{2 to last}') from t5
726+
----
727+
1 [1,2]
728+
1 1
729+
1 2
730+
731+
query IT
732+
select id, json_path_query(obj, '$.obj.**{1}') from t5
733+
----
734+
1 {"b":[1,2]}
735+
1 1
736+
2 "y"
737+
738+
query IT
739+
select id, json_path_query(obj, '$.obj.**{1}.b') from t5
740+
----
741+
1 [1,2]
742+
743+
query IT
744+
select id, json_path_query(obj, '+$.nums') from t5
745+
----
746+
1 2
747+
1 3
748+
1 4
749+
2 -10
750+
2 -11
751+
752+
query IT
753+
select id, json_path_query(obj, '-$.nums') from t5
754+
----
755+
1 -2
756+
1 -3
757+
1 -4
758+
2 10
759+
2 11
760+
761+
query IT
762+
select id, json_path_query(obj, '$.nums[0] + 3') from t5
763+
----
764+
1 5
765+
2 -7
766+
767+
query IT
768+
select id, json_path_query(obj, '7 - $.nums[0]') from t5
769+
----
770+
1 5
771+
2 17
772+
773+
query IT
774+
select id, json_path_query(obj, '2 * $.nums[1]') from t5
775+
----
776+
1 6
777+
2 -22
778+
779+
query IT
780+
select id, json_path_query(obj, '$.nums[1] / 2') from t5
781+
----
782+
1 1.5
783+
2 -5.5
784+
785+
query IT
786+
select id, json_path_query(obj, '$.nums[1] % 2') from t5
787+
----
788+
1 1
789+
2 -1
790+
707791
statement ok
708792
set max_block_size = 65535;
709793

tests/sqllogictests/suites/query/functions/02_0065_function_json.test

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -570,8 +570,8 @@ select id, v @? '$.b' from t2 order by id
570570
query T
571571
select id, v @@ '$[*] == "b"' from t2 order by id
572572
----
573-
1 0
574-
2 0
573+
1 NULL
574+
2 NULL
575575
3 1
576576
4 NULL
577577

0 commit comments

Comments
 (0)