Torch Log Service
This topic introduces the syntax of HyperLogLog functions supported by TLS, along with usage examples in common scenarios.
tip
'time' indicates a string, while time or "time" indicates a field or column name.Function | Function Syntax | Description |
|---|---|---|
APPROX_SET | APPROX_SET(KEY) | Estimates the number of distinct values in the |
EMPTY_APPROX_SET | EMPTY_APPROX_SET() | Constructs a null value of the HyperLogLog data type. |
MERGE | MERGE(KEY) | Merges multiple HyperLogLogs into one HyperLogLog. |
APPROX_SET function is used to estimate the number of distinct values in the KEY field. The maximum standard error value is 0.01625 by default.
Syntax format
APPROX_SET(KEY)
Parameter description
| Parameter | Description |
|---|---|
| KEY | A field or an expression. The value can be any data type. |
Return value description
The return value is of HyperLogLog type.
Scenario
Estimate the number of requests by through the request ID, and the return result is in HyperLogLog encoding.
Query and analysis statement
* | SELECT CAST(APPROX_SET(ReqID) AS varbinary)
Query and analysis results
EMPTY_APPROX_SET function is used to construct a null value of the HyperLogLog data type.
Syntax format
EMPTY_APPROX_SET()
Return value description
The return value is of HyperLogLog type.
Scenario
Constructs a null value of type HyperLogLog.
Query and analysis statement
* | SELECT CAST(EMPTY_APPROX_SET() AS varbinary) LIMIT 1
Query and analysis results
MERGE function is used to merge multiple HyperLogLogLogs into a single HyperLogLog.
Syntax format
MERGE(KEY)
Parameter description
| Parameter | Description |
|---|---|
| KEY | A field or an expression. The value is of HyperLogLog type. |
Return value description
The return value is of HyperLogLog type.
Scenario
Use the APPROX_SET function to estimate the number of requests per hour (HyperLogLog type), and then use the MERGE function to combine all the requests into a single HyperLogLog.
Query and analysis statement
* | SELECT CAST(MERGE(UV) AS varbinary) FROM ( SELECT DATE_TRUNC('hour', __time__) AS time, APPROX_SET(ReqID) AS UV GROUP BY time ORDER BY time )
Query and analysis results