You need to enable JavaScript to run this app.
Torch Log Service

Torch Log Service

Copy page
Download PDF
SQL function
HyperLogLog functions
Copy page
Download PDF
HyperLogLog functions

This topic introduces the syntax of HyperLogLog functions supported by TLS, along with usage examples in common scenarios.

function list

tip

  • Currently, TLS console does not support displaying HyperLogLog type strings. You can use type conversion functions to convert the HyperLogLog type to the binary type. For the description of the type conversion function, please refer to the CAST function ,TRY_CAST function
  • To use strings in SQL analysis statements of TLS, enclose the strings in single quotation marks ( ' ' ). Strings that are not enclosed or enclosed in double quotation marks ( " " ) indicate field names or column names. For example, '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 KEY field.

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

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.

Function syntax

  • Syntax format

    APPROX_SET(KEY)
    
  • Parameter description

    ParameterDescription
    KEYA field or an expression. The value can be any data type.
  • Return value description
    The return value is of HyperLogLog type.

Function example

  • 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
    Image

EMPTY_APPROX_SET function

EMPTY_APPROX_SET function is used to construct a null value of the HyperLogLog data type.

Function syntax

  • Syntax format

    EMPTY_APPROX_SET()
    
  • Return value description
    The return value is of HyperLogLog type.

Function example

  • 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
    Image

MERGE Function

MERGE function is used to merge multiple HyperLogLogLogs into a single HyperLogLog.

Function syntax

  • Syntax format

    MERGE(KEY)
    
  • Parameter description

    ParameterDescription
    KEYA field or an expression. The value is of HyperLogLog type.
  • Return value description
    The return value is of HyperLogLog type.

Function example

  • 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
    Image

Last updated: 2025.02.07 10:42:17