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

GROUP BY and FACET Inconsistent behavior with JSON array #2727

Open sanikolaev opened 2 weeks ago

sanikolaev commented 2 weeks ago

Bug Description:

The GROUP BY and FACET statements should aggregate results consistently. Currently, there’s a discrepancy: GROUP BY aggregates by individual array elements, while FACET performs a similar operation but does not display the elements it groups by.

MRE:

mysql> drop table if exists t; create table t (j json); insert into t(j) values('["S","M"]'),('["M","L"]'),('{"a": 1}'),('{"a": 2}'),('[1,2]'),('[{"a":123}, {"b": 123}]'); select groupby(), count(*) from t group by j facet j;
--------------
drop table if exists t
--------------

Query OK, 0 rows affected (0.01 sec)

--------------
create table t (j json)
--------------

Query OK, 0 rows affected (0.00 sec)

--------------
insert into t(j) values('["S","M"]'),('["M","L"]'),('{"a": 1}'),('{"a": 2}'),('[1,2]'),('[{"a":123}, {"b": 123}]')
--------------

Query OK, 6 rows affected (0.00 sec)

--------------
select groupby(), count(*) from t group by j facet j
--------------

+-----------------------+----------+
| groupby()             | count(*) |
+-----------------------+----------+
| M                     |        2 |
| S                     |        1 |
| L                     |        1 |
| {"a":1}               |        1 |
| {"a":2}               |        1 |
| 2                     |        1 |
| 1                     |        1 |
| [{"a":123},{"b":123}] |        1 |
+-----------------------+----------+
8 rows in set (0.01 sec)
--- 8 out of 8 results in 0ms ---

+-----------------------+----------+
| j                     | count(*) |
+-----------------------+----------+
| ["S","M"]             |        2 |
| ["S","M"]             |        1 |
| ["M","L"]             |        1 |
| {"a":1}               |        1 |
| {"a":2}               |        1 |
| [1,2]                 |        1 |
| [1,2]                 |        1 |
| [{"a":123},{"b":123}] |        1 |
+-----------------------+----------+
8 rows in set (0.01 sec)
--- 8 out of 8 results in 0ms ---

Manticore Search Version:

Manticore 6.3.7 6aa68659d@24102222 dev (columnar 2.3.1 30ad2d6@24100914) (secondary 2.3.1 30ad2d6@24100914) (knn 2.3.1 30ad2d6@24100914)

Operating System Version:

macos

Have you tried the latest development version?

No

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