Skip to content

HyperLogLog bin operations

HyperLogLog (HLL) bin expressions run the same read and modify operations as the HLL data type (estimated cardinality, union, intersection, similarity, describe, may-contain), but embedded in the expression tree for filters, read/write operation expressions, and policies.

Read expressions (hll_get_count, hll_get_union, …) return integers, floats, lists, or HLL values; wrap them in comparison or logic when you need a boolean filter. Modify expressions (hll_add, hll_update, …) evaluate to an HLL value for the pipeline; they do not replace normal HLL write operations unless you use them in an operation policy that applies the result.

For typed bin operands, start from Record storage hll_bin. Nested results (for example hll_describe returning a two-element list) often pair with list bin read helpers such as ListExp.getByIndex.

Composing expressions

The hll_add reference includes an Example that wraps HLLExp.add in HLLExp.getCount—a modify-then-read pattern on the HLL value. Many other operations show similar composition: their examples nest another expression as the HLL operand (hll_bin_expr in the arguments table), including union and other read chains.

Modify

hll_add

hll_add(policy, values, index_bit_count, bin)
Description

Invokes the add operation.

Arguments
NameType
policy library_specific
values list_expr
index_bit_count integer_expr
bin hll_bin_expr
Returns
hll_bin
Introduced
5.2.0.4
Example

Add string ids from list bin new_user_ids into visitors, creating the HLL with index_bit_count 10 if missing; then require a non-zero estimated count.

import com.aerospike.client.operation.HLLPolicy;
import com.aerospike.client.exp.Exp;
import com.aerospike.client.exp.HLLExp;
Expression exp = Exp.build(
Exp.gt(
HLLExp.getCount(
HLLExp.add(
HLLPolicy.Default,
Exp.listBin("new_user_ids"),
Exp.val(10),
Exp.hllBin("visitors"))),
Exp.val(0)));

hll_add_mh

hll_add_mh(policy, values, index_bit_count, minhash_bit_count, bin)
Description

Invokes the add_mh operation.

Arguments
NameType
policy library_specific
values list_expr
index_bit_count integer_expr
minhash_bit_count integer_expr
bin hll_bin_expr
Returns
hll_bin
Introduced
5.2.0.4
Example

Same as hll_add but supplies both index and minhash bit counts when the HLL must be created.

import com.aerospike.client.operation.HLLPolicy;
import com.aerospike.client.exp.Exp;
import com.aerospike.client.exp.HLLExp;
Expression exp = Exp.build(
Exp.gt(
HLLExp.getCount(
HLLExp.add(
HLLPolicy.Default,
Exp.listBin("new_user_ids"),
Exp.val(10),
Exp.val(20),
Exp.hllBin("visitors"))),
Exp.val(0)));

hll_update

hll_update(policy, values, bin)
Description

Invokes the update operation.

Arguments
NameType
policy library_specific
values list_expr
bin hll_bin_expr
Returns
hll_bin
Introduced
5.2.0.4
Example

Add values from list bin new_user_ids to an existing HLL visitors (no index/minhash creation path).

import com.aerospike.client.operation.HLLPolicy;
import com.aerospike.client.exp.Exp;
import com.aerospike.client.exp.HLLExp;
Expression exp = Exp.build(
Exp.gt(
HLLExp.getCount(
HLLExp.add(
HLLPolicy.Default,
Exp.listBin("new_user_ids"),
Exp.val(-1),
Exp.val(-1),
Exp.hllBin("visitors"))),
Exp.val(0)));

Read

hll_describe

hll_describe(bin)
Description

Invokes the describe operation.

Arguments
NameType
bin hll_bin_expr
Returns
list_bin
Introduced
5.2.0.4
Example

The HLL’s index bit count (describe result index 0) is fewer than 16; uses a list read on the describe list.

import com.aerospike.client.cdt.ListReturnType;
import com.aerospike.client.exp.Exp;
import com.aerospike.client.exp.HLLExp;
import com.aerospike.client.exp.ListExp;
Expression exp = Exp.build(
Exp.lt(
ListExp.getByIndex(
ListReturnType.VALUE,
Exp.Type.INT,
Exp.val(0),
HLLExp.describe(Exp.hllBin("visitors"))),
Exp.val(16)));

hll_get_count

hll_get_count(bin)
Description

Invokes the get_count operation.

Arguments
NameType
bin hll_bin_expr
Returns
integer_bin
Introduced
5.2.0.4
Example

Filter to records whose HLL visitors sketch estimates more than 100 unique ids.

import com.aerospike.client.exp.Exp;
import com.aerospike.client.exp.HLLExp;
Expression exp = Exp.build(
Exp.gt(HLLExp.getCount(Exp.hllBin("visitors")), Exp.val(100)));

hll_get_intersect_count

hll_get_intersect_count(hll_list, bin)
Description

Invokes the get_intersect_count operation.

Arguments
NameType
hll_list list_expr
bin hll_bin_expr
Returns
integer_bin
Introduced
5.2.0.4
Example

Estimated intersection size between cohort_a and visitors is at least 50.

import com.aerospike.client.exp.Exp;
import com.aerospike.client.exp.HLLExp;
Expression exp = Exp.build(
Exp.ge(
HLLExp.getIntersectCount(Exp.hllBin("cohort_a"), Exp.hllBin("visitors")),
Exp.val(50)));

hll_get_similarity

hll_get_similarity(hll_list, bin)
Description

Invokes the get_similarity operation.

Arguments
NameType
hll_list list_expr
bin hll_bin_expr
Returns
float_bin
Introduced
5.2.0.4
Example

Jaccard-style similarity between cohort_a and visitors is at least 0.5.

import com.aerospike.client.exp.Exp;
import com.aerospike.client.exp.HLLExp;
Expression exp = Exp.build(
Exp.ge(
HLLExp.getSimilarity(Exp.hllBin("cohort_a"), Exp.hllBin("visitors")),
Exp.val(0.5)));

hll_get_union

hll_get_union(hll_list, bin)
Description

Invokes the get_union operation.

Arguments
NameType
hll_list list_expr
bin hll_bin_expr
Returns
hll_bin
Introduced
5.2.0.4
Example

Union of HLL cohort_a with visitors, then require a non-empty estimate (via hll_get_count on the union result).

import com.aerospike.client.exp.Exp;
import com.aerospike.client.exp.HLLExp;
Expression exp = Exp.build(
Exp.gt(
HLLExp.getCount(
HLLExp.getUnion(Exp.hllBin("cohort_a"), Exp.hllBin("visitors"))),
Exp.val(0)));

hll_get_union_count

hll_get_union_count(hlls, bin)
Description

Invokes the get_union_count operation.

Arguments
NameType
hlls list_expr
bin hll_bin_expr
Returns
integer_bin
Introduced
5.2.0.4
Example

Estimated cardinality of the union of cohort_a and visitors exceeds 500.

import com.aerospike.client.exp.Exp;
import com.aerospike.client.exp.HLLExp;
Expression exp = Exp.build(
Exp.gt(
HLLExp.getUnionCount(Exp.hllBin("cohort_a"), Exp.hllBin("visitors")),
Exp.val(500)));

hll_may_contain

hll_may_contain(values, bin)
Description

Operation on bin that returns 1 if bin may contain all elements in the values list, otherwise returns 0.

Arguments
NameType
values list_expr
bin hll_bin_expr
Returns
integer_bin
Introduced
5.2.0.4
Example

The HLL may contain every candidate key listed in list bin candidate_keys (returns 1 when the check is positive).

import com.aerospike.client.exp.Exp;
import com.aerospike.client.exp.HLLExp;
Expression exp = Exp.build(
Exp.eq(
HLLExp.mayContain(Exp.listBin("candidate_keys"), Exp.hllBin("visitors")),
Exp.val(1)));
Feedback

Was this page helpful?

What type of feedback are you giving?

What would you like us to know?

+Capture screenshot

Can we reach out to you?