Module: aerospike/hll

This module defines operations on the HyperLogLog data type. Create HLL operations used by the Client#operate command.

For more information, please refer to the ⇑HyperLogLog documentation in the Aerospike Feature Guide.

Since:
  • v3.16.0
Source:
See:

Examples

Adds items to HyperLogLog bin and gets approximate count

const Aerospike = require('aerospike')
const hll = Aerospike.hll
const key = new Aerospike.Key('test', 'demo', 'hllDemo')

Aerospike.connect().then(async client => {
  const result = await client.operate(key, [
    hll.init('demo', 10),
    hll.add('demo', ['blue', 'green', 'red']),
    hll.add('demo', ['green', 'orange', 'yellow']),
    hll.add('demo', ['red', 'blue']),
    hll.getCount('demo')
  ])
  console.info('Count:', result.bins) // => Count: 5
  client.close()
})

Performs a union of multiple sets

const Aerospike = require('aerospike')
const hll = Aerospike.hll
const ops = Aerospike.operations

const key1 = new Aerospike.Key('test', 'demo', 'hllDemo1')
const key2 = new Aerospike.Key('test', 'demo', 'hllDemo2')
const key3 = new Aerospike.Key('test', 'demo', 'hllDemo3')

Aerospike.connect().then(async client => {
  const { bins: { colors: colors1 } } = await client.operate(key1, [
    hll.add('colors', ['blue', 'green', 'orange', 'yellow'], 12),
    ops.read('colors')
  ])

  const { bins: { colors: colors2 } } = await client.operate(key2, [
    hll.add('colors', ['violet', 'purple', 'pink', 'orange'], 8),
    ops.read('colors')
  ])

  const { bins: { colors: count } } = await client.operate(key3, [
    hll.add('colors', ['red', 'yellow', 'brown', 'green'], 10),
    hll.setUnion('colors', [colors1, colors2])
         .withPolicy({ writeFlags: hll.writeFlags.ALLOW_FOLD }),
    hll.getCount('colors')
  ])

  console.info('Count:', count) // => Count: 9
  client.close()
})

Classes

HLLOperation

Members


<static> writeFlags :Object

HLL write flags.

Type:
  • Object
Properties:
Name Type Description
DEFAULT number

Allow create or update. Default.

CREATE_ONLY number

If the bin already exists, the operation will be denied. If the bin does not exist, a new bin will be created.

UPDATE_ONLY number

If the bin already exists, the bin will be overwritten. If the bin does not exist, the operation will be denied.

NO_FAIL number

Do not raise error if operation is denied.

ALLOW_FOLD number

Allow the resulting set to be the minimum of provided index bits. For getIntersectCount and getSimilarity, allow the usage of less precise HLL algorithms when min hash bits of all participating sets do not match.

Source:
See:

Methods


<static> add(bin, list [, indexBits] [, minhashBits])

Adds elements to the HLL set. If the bin does not exist, create the HLL with the indexBits and minhashBits parameters.

Returns an integer indicating number of entries that caused HLL to update a register.

The add operation supports the following HLL Policy write flags:

  • CREATE_ONLY
  • NO_FAIL

Not specifying the bit count, implies UPDATE_ONLY.

Parameters:
Name Type Argument Description
bin string

The name of the bin. The bin must contain an HLL value.

list array

Entries to be added to the HLL set.

indexBits number <optional>

Number of index bits. If specified, must be between 4 and 16 inclusive.

minhashBits number <optional>

Number of minhash bits. If specified, must be between 4 and 51 inclusive.

Source:
Returns:

Operation that can be passed to the Client#operate command.

Type
Object

<static> describe(bin)

Returns the index and min hash bit counts used to create the HLL bin as a list of integers.

Parameters:
Name Type Description
bin string

The name of the bin. The bin must contain an HLL value.

Source:
Returns:

Operation that can be passed to the Client#operate command.

Type
Object

<static> fold(bin, indexBits)

Folds the index bit count to the specified value. This can only be applied when the min hash count on the HLL bin is 0.

Parameters:
Name Type Description
bin string

The name of the bin. The bin must contain an HLL value.

indexBits number

Number of index bits. Must be between 4 and 16 inclusive.

Source:
Returns:

Operation that can be passed to the Client#operate command.

Type
Object

<static> getCount(bin)

Returns the estimated number of elements in the HLL bin.

Parameters:
Name Type Description
bin string

The name of the bin. The bin must contain an HLL value.

Source:
Returns:

Operation that can be passed to the Client#operate command.

Type
Object

<static> getIntersectCount(bin, list)

Returns the estimated number of elements that would be contained by the intersection of these HLL objects.

Parameters:
Name Type Description
bin string

The name of the bin. The bin must contain an HLL value.

list array

List of HLL objects (of type Buffer).

Source:
Returns:

Operation that can be passed to the Client#operate command.

Type
Object

<static> getSimilarity(bin, list)

Returns the estimated similarity of these HLL objects. Return type is double.

Parameters:
Name Type Description
bin string

The name of the bin. The bin must contain an HLL value.

list array

List of HLL objects (of type Buffer).

Source:
Returns:

Operation that can be passed to the Client#operate command.

Type
Object

<static> getUnion(bin, list)

Returns an HLL object, which is the union of all specified HLL objects in the list with the HLL bin.

Parameters:
Name Type Description
bin string

The name of the bin. The bin must contain an HLL value.

list array

List of HLL objects (of type Buffer).

Source:
Returns:

Operation that can be passed to the Client#operate command.

Type
Object

<static> getUnionCount(bin, list)

Returns the estimated number of elements that would be contained by the union of these HLL objects.

Parameters:
Name Type Description
bin string

The name of the bin. The bin must contain an HLL value.

list array

List of HLL objects (of type Buffer).

Source:
Returns:

Operation that can be passed to the Client#operate command.

Type
Object

<static> init(bin, indexBits [, minhashBits])

Creates a new HLL or re-initializes an existing HLL. Re-initialization clears existing contents.

The init operation supports the following HLL Policy write flags:

  • CREATE_ONLY
  • UPDATE_ONLY
  • NO_FAIL
Parameters:
Name Type Argument Description
bin string

The name of the bin. The bin must contain an HLL value.

indexBits number

Number of index bits. Must be between 4 and 16 inclusive.

minhashBits number <optional>

Number of minhash bits. If specified, must be between 4 and 51 inclusive.

Source:
Returns:

Operation that can be passed to the Client#operate command.

Type
Object

<static> refreshCount(bin)

Updates the cached count (if stale), and returns the estimated number of elements in the HLL bin.

Parameters:
Name Type Description
bin string

The name of the bin. The bin must contain an HLL value.

Source:
Returns:

Operation that can be passed to the Client#operate command.

Type
Object

<static> setUnion(bin, list)

Sets a union of the specified HLLs with the HLL bin value (if it exists) back into the HLL bin.

The setUnion operation supports the following HLL Policy write flags:

  • CREATE_ONLY
  • UPDATE_ONLY
  • ALLOW_FOLD
  • NO_FAIL

If ALLOW_FOLD is not set, all provided HLLs and the target bin (if it exists) must have matching index bits and minhash bits. If ALLOW_FOLD is set, server will union down to the minimum index bits of all provided HLLs and the target bin (if it exists). Additionally, if minhash bits differs on any HLL, the resulting union will have 0 minhash bits.

Parameters:
Name Type Description
bin string

The name of the bin. The bin must contain an HLL value.

list array

List of HLL objects (of type Buffer).

Source:
Returns:

Operation that can be passed to the Client#operate command.

Type
Object