Skip to content

Commit

Permalink
add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
cpegeric committed Nov 20, 2024
1 parent d26a2f0 commit 30e534e
Show file tree
Hide file tree
Showing 2 changed files with 161 additions and 0 deletions.
80 changes: 80 additions & 0 deletions test/distributed/cases/fulltext/jsonvalue.result
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
set experimental_fulltext_index=1;
create table src (id bigint primary key, json1 json, json2 json);
insert into src values (0, '{"a":1, "b":"red"}', '{"d": "happy birthday", "f":"winter"}'),
(1, '{"a":2, "b":"中文學習教材"}', '["apple", "orange", "banana", "指引"]'),
(2, '{"a":3, "b":"red blue"}', '{"d":"兒童中文"}');
create fulltext index ftidx on src (json1) with parser json_value;
select * from src where match(json1) against('red' in boolean mode);
id json1 json2
0 {"a": 1, "b": "red"} {"d": "happy birthday", "f": "winter"}
select * from src where match(json1) against('中文學習教材' in boolean mode);
id json1 json2
1 {"a": 2, "b": "中文學習教材"} ["apple", "orange", "banana", "指引"]
create fulltext index ftidx2 on src (json1, json2) with parser json_value;
select * from src where match(json1, json2) against('+red +winter' in boolean mode);
id json1 json2
0 {"a": 1, "b": "red"} {"d": "happy birthday", "f": "winter"}
select * from src where match(json1, json2) against('中文學習教材' in boolean mode);
id json1 json2
1 {"a": 2, "b": "中文學習教材"} ["apple", "orange", "banana", "指引"]
drop table src;
create table src (id bigint primary key, json1 text, json2 varchar);
insert into src values (0, '{"a":1, "b":"red"}', '{"d": "happy birthday", "f":"winter"}'),
(1, '{"a":2, "b":"中文學習教材"}', '["apple", "orange", "banana", "指引"]'),
(2, '{"a":3, "b":"red blue"}', '{"d":"兒童中文"}');
create fulltext index ftidx on src (json1) with parser json_value;
select * from src where match(json1) against('red' in boolean mode);
id json1 json2
0 {"a":1, "b":"red"} {"d": "happy birthday", "f":"winter"}
select * from src where match(json1) against('中文學習教材' in boolean mode);
id json1 json2
1 {"a":2, "b":"中文學習教材"} ["apple", "orange", "banana", "指引"]
create fulltext index ftidx2 on src (json1, json2) with parser json_value;
select * from src where match(json1, json2) against('+red +winter' in boolean mode);
id json1 json2
0 {"a":1, "b":"red"} {"d": "happy birthday", "f":"winter"}
select * from src where match(json1, json2) against('中文學習教材' in boolean mode);
id json1 json2
1 {"a":2, "b":"中文學習教材"} ["apple", "orange", "banana", "指引"]
drop table src;
create table src (id bigint primary key, json1 json, json2 json, FULLTEXT(json1) with parser json_value);
insert into src values (0, '{"a":1, "b":"red"}', '{"d": "happy birthday", "f":"winter"}'),
(1, '{"a":2, "b":"中文學習教材"}', '["apple", "orange", "banana", "指引"]'),
(2, '{"a":3, "b":"red blue"}', '{"d":"兒童中文"}');
select * from src where match(json1) against('red' in boolean mode);
id json1 json2
0 {"a": 1, "b": "red"} {"d": "happy birthday", "f": "winter"}
select * from src where match(json1) against('中文學習教材' in boolean mode);
id json1 json2
1 {"a": 2, "b": "中文學習教材"} ["apple", "orange", "banana", "指引"]
create fulltext index ftidx2 on src (json1, json2) with parser json_value;
select * from src where match(json1, json2) against('+red +winter' in boolean mode);
id json1 json2
0 {"a": 1, "b": "red"} {"d": "happy birthday", "f": "winter"}
select * from src where match(json1, json2) against('中文學習教材' in boolean mode);
id json1 json2
1 {"a": 2, "b": "中文學習教材"} ["apple", "orange", "banana", "指引"]
update src set json1='{"c":"update json"}' where id=0;
drop table src;
create table src (id bigint primary key, json1 text, json2 varchar, fulltext(json1) with parser json_value);
insert into src values (0, '{"a":1, "b":"red"}', '{"d": "happy birthday", "f":"winter"}'),
(1, '{"a":2, "b":"中文學習教材"}', '["apple", "orange", "banana", "指引"]'),
(2, '{"a":3, "b":"red blue"}', '{"d":"兒童中文"}');
select * from src where match(json1) against('red' in boolean mode);
id json1 json2
0 {"a":1, "b":"red"} {"d": "happy birthday", "f":"winter"}
select * from src where match(json1) against('中文學習教材' in boolean mode);
id json1 json2
1 {"a":2, "b":"中文學習教材"} ["apple", "orange", "banana", "指引"]
create fulltext index ftidx2 on src (json1, json2) with parser json_value;
select * from src where match(json1, json2) against('+red +winter' in boolean mode);
id json1 json2
0 {"a":1, "b":"red"} {"d": "happy birthday", "f":"winter"}
select * from src where match(json1, json2) against('中文學習教材' in boolean mode);
id json1 json2
1 {"a":2, "b":"中文學習教材"} ["apple", "orange", "banana", "指引"]
update src set json1='{"c":"update_json"}' where id=0;
select * from src where match(json1, json2) against('"update_json"' in boolean mode);
id json1 json2
0 {"c":"update_json"} {"d": "happy birthday", "f":"winter"}
drop table src;
81 changes: 81 additions & 0 deletions test/distributed/cases/fulltext/jsonvalue.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
-- TODO: run all tests with both experimental_fulltext_index = 0 and 1
-- TODO: GENERATE the test case to cover all combinations of types (varchar, char and text)
set experimental_fulltext_index=1;

-- bytejson parser
create table src (id bigint primary key, json1 json, json2 json);
insert into src values (0, '{"a":1, "b":"red"}', '{"d": "happy birthday", "f":"winter"}'),
(1, '{"a":2, "b":"中文學習教材"}', '["apple", "orange", "banana", "指引"]'),
(2, '{"a":3, "b":"red blue"}', '{"d":"兒童中文"}');

create fulltext index ftidx on src (json1) with parser json_value;

select * from src where match(json1) against('red' in boolean mode);

select * from src where match(json1) against('中文學習教材' in boolean mode);

create fulltext index ftidx2 on src (json1, json2) with parser json_value;
select * from src where match(json1, json2) against('+red +winter' in boolean mode);

select * from src where match(json1, json2) against('中文學習教材' in boolean mode);

drop table src;

-- bytejson parser
create table src (id bigint primary key, json1 text, json2 varchar);
insert into src values (0, '{"a":1, "b":"red"}', '{"d": "happy birthday", "f":"winter"}'),
(1, '{"a":2, "b":"中文學習教材"}', '["apple", "orange", "banana", "指引"]'),
(2, '{"a":3, "b":"red blue"}', '{"d":"兒童中文"}');

create fulltext index ftidx on src (json1) with parser json_value;

select * from src where match(json1) against('red' in boolean mode);

select * from src where match(json1) against('中文學習教材' in boolean mode);

create fulltext index ftidx2 on src (json1, json2) with parser json_value;
select * from src where match(json1, json2) against('+red +winter' in boolean mode);

select * from src where match(json1, json2) against('中文學習教材' in boolean mode);

drop table src;

-- bytejson parser
create table src (id bigint primary key, json1 json, json2 json, FULLTEXT(json1) with parser json_value);
insert into src values (0, '{"a":1, "b":"red"}', '{"d": "happy birthday", "f":"winter"}'),
(1, '{"a":2, "b":"中文學習教材"}', '["apple", "orange", "banana", "指引"]'),
(2, '{"a":3, "b":"red blue"}', '{"d":"兒童中文"}');

select * from src where match(json1) against('red' in boolean mode);

select * from src where match(json1) against('中文學習教材' in boolean mode);

create fulltext index ftidx2 on src (json1, json2) with parser json_value;
select * from src where match(json1, json2) against('+red +winter' in boolean mode);

select * from src where match(json1, json2) against('中文學習教材' in boolean mode);

update src set json1='{"c":"update json"}' where id=0;

drop table src;

-- bytejson parser
create table src (id bigint primary key, json1 text, json2 varchar, fulltext(json1) with parser json_value);
insert into src values (0, '{"a":1, "b":"red"}', '{"d": "happy birthday", "f":"winter"}'),
(1, '{"a":2, "b":"中文學習教材"}', '["apple", "orange", "banana", "指引"]'),
(2, '{"a":3, "b":"red blue"}', '{"d":"兒童中文"}');

select * from src where match(json1) against('red' in boolean mode);

select * from src where match(json1) against('中文學習教材' in boolean mode);

create fulltext index ftidx2 on src (json1, json2) with parser json_value;
select * from src where match(json1, json2) against('+red +winter' in boolean mode);

select * from src where match(json1, json2) against('中文學習教材' in boolean mode);

update src set json1='{"c":"update_json"}' where id=0;

select * from src where match(json1, json2) against('"update_json"' in boolean mode);

drop table src;

0 comments on commit 30e534e

Please sign in to comment.