Skip to content

Commit 71acbc1

Browse files
authored
fix: fix get by keypath with null value (#14684)
1 parent 78d0de4 commit 71acbc1

File tree

5 files changed

+66
-11
lines changed

5 files changed

+66
-11
lines changed

Cargo.lock

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

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ members = [
107107

108108
[workspace.dependencies]
109109
# databend maintains
110-
jsonb = { git = "https://github.com/datafuselabs/jsonb", rev = "0247ffc" }
110+
jsonb = { git = "https://github.com/datafuselabs/jsonb", rev = "a7325f4" }
111111

112112
opendal = { version = "0.45.0", features = [
113113
"layers-minitrace",

src/query/functions/tests/it/scalars/testdata/variant.txt

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3203,6 +3203,24 @@ output domain : {NULL}
32033203
output : NULL
32043204

32053205

3206+
ast : parse_json('{"k": null}') #> '{k}'
3207+
raw expr : get_by_keypath(parse_json('{"k": null}'), '{k}')
3208+
checked expr : get_by_keypath<Variant, String>(parse_json<String>("{\"k\": null}"), "{k}")
3209+
optimized expr : 0x2000000000000000
3210+
output type : Variant NULL
3211+
output domain : Undefined
3212+
output : 'null'
3213+
3214+
3215+
ast : parse_json('[10, 20, null]') #> '{2}'
3216+
raw expr : get_by_keypath(parse_json('[10, 20, null]'), '{2}')
3217+
checked expr : get_by_keypath<Variant, String>(parse_json<String>("[10, 20, null]"), "{2}")
3218+
optimized expr : 0x2000000000000000
3219+
output type : Variant NULL
3220+
output domain : Undefined
3221+
output : 'null'
3222+
3223+
32063224
ast : parse_json('[10, {"a":{"k1":[1,2,3], "k2":2}}, 30]') #> '{1, a, k1}'
32073225
raw expr : get_by_keypath(parse_json('[10, {"a":{"k1":[1,2,3], "k2":2}}, 30]'), '{1, a, k1}')
32083226
checked expr : get_by_keypath<Variant, String>(parse_json<String>("[10, {\"a\":{\"k1\":[1,2,3], \"k2\":2}}, 30]"), "{1, a, k1}")
@@ -3331,6 +3349,24 @@ output domain : {NULL}
33313349
output : NULL
33323350

33333351

3352+
ast : parse_json('{"k": null}') #>> '{k}'
3353+
raw expr : get_by_keypath_string(parse_json('{"k": null}'), '{k}')
3354+
checked expr : get_by_keypath_string<Variant, String>(parse_json<String>("{\"k\": null}"), "{k}")
3355+
optimized expr : "null"
3356+
output type : String NULL
3357+
output domain : {"null"..="null"}
3358+
output : 'null'
3359+
3360+
3361+
ast : parse_json('[10, 20, null]') #>> '{2}'
3362+
raw expr : get_by_keypath_string(parse_json('[10, 20, null]'), '{2}')
3363+
checked expr : get_by_keypath_string<Variant, String>(parse_json<String>("[10, 20, null]"), "{2}")
3364+
optimized expr : "null"
3365+
output type : String NULL
3366+
output domain : {"null"..="null"}
3367+
output : 'null'
3368+
3369+
33343370
ast : parse_json('[10, {"a":{"k1":[1,2,3], "k2":2}}, 30]') #>> '{1, a, k1}'
33353371
raw expr : get_by_keypath_string(parse_json('[10, {"a":{"k1":[1,2,3], "k2":2}}, 30]'), '{1, a, k1}')
33363372
checked expr : get_by_keypath_string<Variant, String>(parse_json<String>("[10, {\"a\":{\"k1\":[1,2,3], \"k2\":2}}, 30]"), "{1, a, k1}")

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1171,6 +1171,8 @@ fn test_get_by_keypath_op(file: &mut impl Write) {
11711171
run_ast(file, r#"parse_json('[10, 20, 30]') #> '{1}'"#, &[]);
11721172
run_ast(file, r#"parse_json('[10, 20, 30]') #> '{3}'"#, &[]);
11731173
run_ast(file, r#"parse_json('[10, 20, 30]') #> '{a}'"#, &[]);
1174+
run_ast(file, r#"parse_json('{"k": null}') #> '{k}'"#, &[]);
1175+
run_ast(file, r#"parse_json('[10, 20, null]') #> '{2}'"#, &[]);
11741176
run_ast(
11751177
file,
11761178
r#"parse_json('[10, {"a":{"k1":[1,2,3], "k2":2}}, 30]') #> '{1, a, k1}'"#,
@@ -1217,6 +1219,8 @@ fn test_get_by_keypath_string_op(file: &mut impl Write) {
12171219
run_ast(file, r#"parse_json('[10, 20, 30]') #>> '{1}'"#, &[]);
12181220
run_ast(file, r#"parse_json('[10, 20, 30]') #>> '{3}'"#, &[]);
12191221
run_ast(file, r#"parse_json('[10, 20, 30]') #>> '{a}'"#, &[]);
1222+
run_ast(file, r#"parse_json('{"k": null}') #>> '{k}'"#, &[]);
1223+
run_ast(file, r#"parse_json('[10, 20, null]') #>> '{2}'"#, &[]);
12201224
run_ast(
12211225
file,
12221226
r#"parse_json('[10, {"a":{"k1":[1,2,3], "k2":2}}, 30]') #>> '{1, a, k1}'"#,

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

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,11 @@ select parse_json('{"aa": 1, "aA": 2, "Aa": 3 }')['aa']
114114
----
115115
1
116116

117+
query T
118+
select '{"k1": 1, "k2": null}'::json['k2']
119+
----
120+
null
121+
117122
query T
118123
select get_ignore_case(parse_json('{"aa": 1, "aA": 2, "Aa": 3}'), 'aA')
119124
----
@@ -247,6 +252,11 @@ select parse_json('[1, {"a": 1, "b": [100, 200, {"k1": 1, "k2": 2}]}, 3]')#>'{1,
247252
----
248253
1
249254

255+
query T
256+
select '[1, 2, 3, null]'::json#>'{3}'
257+
----
258+
null
259+
250260
query T
251261
select NULL#>>'{0}'
252262
----
@@ -292,6 +302,11 @@ select parse_json('[1, {"a": 1, "b": [100, 200, {"k1": 1, "k2": 2}]}, 3]')#>>'{1
292302
----
293303
1
294304

305+
query T
306+
select '[1, 2, 3, null]'::json#>>'{3}'
307+
----
308+
null
309+
295310
query T
296311
select [][0]
297312
----

0 commit comments

Comments
 (0)