HLL Function
Last Updated:2021-04-13
This article mainly introduces the built-in functions related to HLL(HyperLogLog) type.
-
Scalar function
1.hll_cardinality
2.hll_hash
3.hll_empty -
Aggregate function
HLL_CARDINALITY
Description
bigint hll_cardinality(hll a)
- Function: calculate the cardinality of a single HLL type value.
- Returned value: bigint type.
Example
mysql> select hll_cardinality(v1) from tbl;
+-----------------------+
| hll_cardinality(`v1`) |
+-----------------------+
| 3 |
+-----------------------+
Keywords
hll_cardinality
HLL_HASH
Description
hll hll_hash(type a)
- Function: convert a numeric value to hll type. It is generally used in import, mapping values in source data to HLL column types in Palo table.
- Returned value: hll type.
Example
mysql> select hll_cardinality(hll_hash("a"));
+--------------------------------+
| hll_cardinality(hll_hash('a')) |
+--------------------------------+
| 1 |
+--------------------------------+
As HLL type is binary type, it cannot be displayed on MySQL client end. Therefore,
hll_cardinality
is used to return the carbinality of HLL type for display.
Keywords
hll_hash
HLL_EMPTY
Description
hll hll_empty()
- Function: return an empty value of HLL type. Generally it is used in import, inserted with an empty HLL value.
- Returned value: hll type.
Example
mysql> select hll_cardinality(hll_empty());
+------------------------------+
| hll_cardinality(hll_empty()) |
+------------------------------+
| 0 |
+------------------------------+
Keywords
hll_empty
HLL_UNION,HLL_RAW_AGG
Description
hll hll_union(hll a)
hll hll_raw_agg(hll a)
- Function: an aggregate function, which returns the union set of a group of HLL values.
hll_raw_agg
is the alias ofhll_union
. - Returned value: hll type.
Example
mysql> select k1, hll_cardinality(hll_union(v1)) from tbl group by k1;
+------+----------------------------------+
| k1 | hll_cardinality(hll_union(`v1`)) |
+------+----------------------------------+
| 2 | 4 |
| 1 | 3 |
+------+----------------------------------+
Keywords
hll_union, hll_raw_agg
HLL_UNION_AGG
Description
bigint hll_union_agg(hll a)
- Function: an aggregate function, which returns the cardinality of the union set of HLL values, with effect equivalent to
hll_cardinality(hll_union(v1))
. It is recommended to usehll_union_agg
directly, which is more efficient. - Returned value: bigint type.
Example
mysql> select k1, hll_union_agg(v1) from tbl group by k1;
+------+---------------------+
| k1 | hll_union_agg(`v1`) |
+------+---------------------+
| 2 | 4 |
| 1 | 3 |
+------+---------------------+
Keywords
hll_union_agg