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

fix json_extract_string, json_extract_float64 with multi path param #18770

Merged
merged 6 commits into from
Sep 13, 2024
Merged
Show file tree
Hide file tree
Changes from 3 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
4 changes: 2 additions & 2 deletions pkg/sql/plan/function/func_builtin_json.go
Original file line number Diff line number Diff line change
Expand Up @@ -268,7 +268,7 @@ func (op *opBuiltInJsonExtract) jsonExtractString(parameters []*vector.Vector, r
return err
}

if !op.simple {
if !op.simple || op.simple && len(op.paths) > 1 {
return moerr.NewInvalidInput(proc.Ctx, "json_extract_value should use a path that retrives a single value")
}
if jsonVec.GetType().Oid == types.T_json {
Expand Down Expand Up @@ -332,7 +332,7 @@ func (op *opBuiltInJsonExtract) jsonExtractFloat64(parameters []*vector.Vector,
if err = op.buildPath(parameters, length); err != nil {
return err
}
if !op.simple {
if !op.simple || op.simple && len(op.paths) > 1 {
return moerr.NewInvalidInput(proc.Ctx, "json_extract_value should use a path that retrives a single value")
}

Expand Down
18 changes: 18 additions & 0 deletions test/distributed/cases/function/func_json_extract.result
Original file line number Diff line number Diff line change
Expand Up @@ -575,3 +575,21 @@ id extracted_name extracted_age extracted_math_score extracted_scien
8 Hank 25.0 80.5 88.0
9 Ivan 25.0 null null
drop database test;
create database test;
use test;
create table test_123(c1 json);
insert into test_123 values ('{"a1":10, "a2":20}');
insert into test_123 values ('{"a1":"test", "a2":"test2"}');
select * from test_123;
c1
{"a1": 10, "a2": 20}
{"a1": "test", "a2": "test2"}
select json_extract(c1, '$.a1', '$.a2') from test_123;
json_extract(c1, $.a1, $.a2)
[10, 20]
["test", "test2"]
select json_extract_float64(c1, '$.a1', '$.a2') from test_123;
invalid input: json_extract_value should use a path that retrives a single value
select json_extract_string(c1, '$.a1', '$.a2') from test_123;
invalid input: json_extract_value should use a path that retrives a single value
drop database test;
11 changes: 11 additions & 0 deletions test/distributed/cases/function/func_json_extract.test
Original file line number Diff line number Diff line change
Expand Up @@ -297,3 +297,14 @@ SELECT
FROM test_json_simplified;

drop database test;

create database test;
use test;
create table test_123(c1 json);
insert into test_123 values ('{"a1":10, "a2":20}');
insert into test_123 values ('{"a1":"test", "a2":"test2"}');
select * from test_123;
select json_extract(c1, '$.a1', '$.a2') from test_123;
select json_extract_float64(c1, '$.a1', '$.a2') from test_123;
select json_extract_string(c1, '$.a1', '$.a2') from test_123;
drop database test;
Loading