PFMERGE
The PFMERGE
command in DiceDB is used to merge multiple HyperLogLog data structures into a single HyperLogLog. HyperLogLog is a probabilistic data structure used for estimating the cardinality of a set, i.e., the number of unique elements in a dataset. This command is particularly useful when you have multiple HyperLogLogs and you want to combine them to get an estimate of the total unique elements across all of them.
Syntax
Parameters
Parameter | Description | Type | Required |
---|---|---|---|
destkey | The key where the merged HyperLogLog will be stored. If this key already exists, it will be overwritten. | String | Yes |
sourcekey | One or more keys of the HyperLogLogs that you want to merge. These keys must already exist and contain HyperLogLog data. | List[String] | Yes |
Return Values
Condition | Return Value |
---|---|
Command is successful | OK |
Syntax or specified constraints are invalid | (error) |
Behaviour
- If the
destkey
already exists, thePFMERGE
command will overwrite the existing value with the new merged HyperLogLog. - The command retrieves the HyperLogLog data structures from the specified
sourcekey
keys. - These
sourcekey
keys are merged into a single HyperLogLog and stored in thedestkey
. - If the
sourcekey
keys are not valid HyperLogLogs, an error is returned.
Errors
The PFMERGE
command can raise errors in the following scenarios:
-
Wrong Type Error
:(error)
:WRONGTYPE Operation against a key holding the wrong kind of value
- If any of the
sourcekey
keys or thedestkey
key contains a value that is not a HyperLogLog, DiceDB will return an error.
-
Non-Existent Key Error
:- If any of the
sourcekey
keys do not exist, DiceDB will treat them as empty HyperLogLogs and proceed with the merge operation without raising an error.
- If any of the
Example Usage
Basic Usage
Suppose you have three HyperLogLogs stored at keys hll1
, hll2
, and hll3
, and you want to merge them into a new HyperLogLog stored at key hll_merged
.
Overwriting Existing Key
If the destkey
already exists, it will be overwritten by the merged HyperLogLog.
Handling Non-Existent Source Keys
If a sourcekey
does not exist, DiceDB will treat it as an empty HyperLogLog.
Invalid Usage
if a sourcekey
exists and is not of type HyperLogLog, the command will result in an error