manticoresoftware / manticoresearch

Easy to use open source fast database for search | Good alternative to Elasticsearch now | Drop-in replacement for E in the ELK soon
https://manticoresearch.com
GNU General Public License v3.0
9.07k stars 509 forks source link

Incorrect CALL PQ results when expression parser is used #2745

Open glookka opened 1 week ago

glookka commented 1 week ago

Bug Description:

The following CALL PQ uses an expression parser (as the SQL parser doesn't know about '=='). This results in string comparison expression comparing JSON_TRUE that can't be converted into a string (and StringEval returns 0) and an empty const string (StringEval returns 0 again). String comparison assumes that they are equal empty strings and returns 1 as a result which is wrong.

drop table if exists pq;
create table pq (`json` json) type='pq';
INSERT INTO pq (query, filters) VALUES ('', 'json.target.`wpcom:blog_id`==\'\'');
call pq ('pq', '{"text":"filter test", "json":{"target":{"wpcom:blog_id":true}}}', 1 as docs_json);

The following CALL PQ uses a SQL parser; it spawns a Expr_JsonFieldIn_c which knows the types of data it is comparing. As JSON_TRUE is not a string, this always returns 0 which is expected.

drop table if exists pq;
create table pq (`json` json) type='pq';
INSERT INTO pq (query, filters) VALUES ('', 'json.target.`wpcom:blog_id`=\'\'');
call pq ('pq', '{"text":"filter test", "json":{"target":{"wpcom:blog_id":true}}}', 1 as docs_json);

Manticore Search Version:

6.3.1

Operating System Version:

Any

Have you tried the latest development version?

Yes

Internal Checklist:

To be completed by the assignee. Check off tasks that have been completed or are not applicable.

- [ ] Implementation completed - [ ] Tests developed - [ ] Documentation updated - [ ] Documentation reviewed - [ ] [Changelog](https://docs.google.com/spreadsheets/d/1mz_3dRWKs86FjRF7EIZUziUDK_2Hvhd97G0pLpxo05s/edit?pli=1&gid=1102439133) updated