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.
- Description:
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.
- Source:
- Since:
- v3.16.0
- See:
Examples
const Aerospike = require('aerospike')
const hll = Aerospike.hll
const key = new Aerospike.Key('test', 'demo', 'hllDemo')
// INSERT HOSTNAME AND PORT NUMBER OF AEROSPIKE SERVER NODE HERE!
var config = {
hosts: '192.168.33.10:3000',
// Timeouts disabled, latency dependent on server location. Configure as needed.
policies: {
operate : new Aerospike.OperatePolicy({socketTimeout : 0, totalTimeout : 0})
}
}
Aerospike.connect(config).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.log('Count:', result.bins.demo) // => Count: 5
client.close()
})
const Aerospike = require('aerospike')
const hll = Aerospike.hll
const ops = Aerospike.operations
// INSERT HOSTNAME AND PORT NUMBER OF AEROSPIKE SERVER NODE HERE!
var config = {
hosts: '192.168.33.10:3000',
// Timeouts disabled, latency dependent on server location. Configure as needed.
policies: {
operate : new Aerospike.OperatePolicy({socketTimeout : 0, totalTimeout : 0})
}
}
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(config).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.log('Count:', count) // => Count: 9
client.close()
})
Classes
Members
(static) writeFlags :Object
HLL write flags.
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 |
Type:
- Object
Methods
(static) add(bin, list, indexBitsopt, minhashBitsopt) → {Object}
- Description:
Adds elements to the HLL set. If the bin does not exist, create the HLL with the
indexBits
andminhashBits
parameters.Returns an integer indicating number of entries that caused HLL to update a register.
The
add
operation supports the followingHLL Policy write flags
:CREATE_ONLY
NO_FAIL
Not specifying the bit count, implies
UPDATE_ONLY
.
- Source:
Parameters:
Name | Type | Attributes | 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. |
Returns:
Operation that can be passed to the Client#operate
command.
- Type
- Object
(static) describe(bin) → {Object}
- Description:
Returns the index and min hash bit counts used to create the HLL bin as a list of integers.
- Source:
Parameters:
Name | Type | Description |
---|---|---|
bin |
string | The name of the bin. The bin must contain an HLL value. |
Returns:
Operation that can be passed to the Client#operate
command.
- Type
- Object
(static) fold(bin, indexBits) → {Object}
- Description:
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.
- Source:
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. |
Returns:
Operation that can be passed to the Client#operate
command.
- Type
- Object
(static) getCount(bin) → {Object}
Parameters:
Name | Type | Description |
---|---|---|
bin |
string | The name of the bin. The bin must contain an HLL value. |
Returns:
Operation that can be passed to the Client#operate
command.
- Type
- Object
(static) getIntersectCount(bin, list) → {Object}
- Description:
Returns the estimated number of elements that would be contained by the intersection of these HLL objects.
- Source:
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). |
Returns:
Operation that can be passed to the Client#operate
command.
- Type
- Object
(static) getSimilarity(bin, list) → {Object}
- Description:
Returns the estimated similarity of these HLL objects. Return type is double.
- Source:
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). |
Returns:
Operation that can be passed to the Client#operate
command.
- Type
- Object
(static) getUnion(bin, list) → {Object}
- Description:
Returns an HLL object, which is the union of all specified HLL objects in the list with the HLL bin.
- Source:
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). |
Returns:
Operation that can be passed to the Client#operate
command.
- Type
- Object
(static) getUnionCount(bin, list) → {Object}
- Description:
Returns the estimated number of elements that would be contained by the union of these HLL objects.
- Source:
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). |
Returns:
Operation that can be passed to the Client#operate
command.
- Type
- Object
(static) init(bin, indexBits, minhashBitsopt) → {Object}
- Description:
Creates a new HLL or re-initializes an existing HLL. Re-initialization clears existing contents.
The
init
operation supports the followingHLL Policy write flags
:CREATE_ONLY
UPDATE_ONLY
NO_FAIL
- Source:
Parameters:
Name | Type | Attributes | 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. |
Returns:
Operation that can be passed to the Client#operate
command.
- Type
- Object
(static) refreshCount(bin) → {Object}
- Description:
Updates the cached count (if stale), and returns the estimated number of elements in the HLL bin.
- Source:
Parameters:
Name | Type | Description |
---|---|---|
bin |
string | The name of the bin. The bin must contain an HLL value. |
Returns:
Operation that can be passed to the Client#operate
command.
- Type
- Object
(static) setUnion(bin, list) → {Object}
- Description:
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 followingHLL 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. IfALLOW_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.
- Source:
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). |
Returns:
Operation that can be passed to the Client#operate
command.
- Type
- Object