postgresql-hll icon indicating copy to clipboard operation
postgresql-hll copied to clipboard

"could not identify an equality operator for type hll" in GROUP BY

Open onlined opened this issue 5 years ago • 4 comments

When I use a column with hll type as a field in GROUP BY clause, I get the error:

ERROR:  could not identify an equality operator for type hll

Here's a small repro:

CREATE TABLE tmp (int num, set hll);
INSERT INTO tmp VALUES (1, hll_empty());
INSERT INTO tmp VALUES (2, hll_empty());
INSERT INTO tmp VALUES (3, hll_empty());
INSERT INTO tmp VALUES (4, hll_empty());
SELECT SUM(num), set FROM tmp GROUP BY set;

While I expect it to result in a row consisting of 10 and empty hll value, I get the error above.

postgresql-hll Version: master (77aa0fe) PostgreSQL Version: 11.5 OS Version: Debian 10

onlined avatar Sep 12 '19 11:09 onlined

@onlined is there an equality operator for type hll, this error message would be expected?

metdos avatar Sep 12 '19 14:09 metdos

Yes, there is. When I run \do, I get the following output:

                                List of operators
 Schema | Name | Left arg type | Right arg type |   Result type    | Description
--------+------+---------------+----------------+------------------+-------------
 public | #    |               | hll            | double precision |
 public | <>   | hll           | hll            | boolean          |
 public | <>   | hll_hashval   | hll_hashval    | boolean          |
 public | =    | hll           | hll            | boolean          |
 public | =    | hll_hashval   | hll_hashval    | boolean          |
 public | ||   | hll           | hll            | hll              |
 public | ||   | hll           | hll_hashval    | hll              |
 public | ||   | hll_hashval   | hll            | hll              |
(8 rows)

onlined avatar Sep 13 '19 07:09 onlined

We're having the same problem when trying to UNION two tables with hll columns. e.g.

CREATE TABLE test1 ( id integer, hashed hll);
CREATE TABLE test2 ( id integer, hashed hll);
SELECT hashed FROM test1 UNION SELECT hashed FROM test2; 

postgresql-hll Version: v2.15.1 PostgreSQL Version: 12 OS Version: macOS Catalina 10.15.7

davidalejandroaguilar avatar Jan 14 '21 00:01 davidalejandroaguilar

SELECT hll_union_agg(hashed) FROM test1 UNION SELECT hll_union_agg(hashed) FROM test2; 

hashed in both queries is a list of records (even though only one may exist). Therefore, it is necessary to apply an aggregate operation first (hll_union_agg()).

This works for me.

Sieboldianus avatar Jun 28 '21 07:06 Sieboldianus