函数聚合函数聚合函数uniqThetauniqTheta uniqTheta 引入于:v21.6 使用 Theta Sketch Framework 计算不同参数值数量的近似值。 实现细节此函数对聚合中的所有参数计算哈希值,然后在计算中使用这些哈希值。 它使用 KMV 算法来近似计算不同参数值的数量。使用了 4096(2^12)个 64 位 sketch。 状态大小约为 41 KB。相对误差为 3.125%(95% 置信水平),详情参见相对误差表。 语法 uniqTheta(x[, ...]) 参数 x — 该函数接受可变数量的参数。Tuple(T) 或 Array(T) 或 Date 或 DateTime 或 String 或 (U)Int* 或 Float* 或 Decimal 返回值 返回一个 UInt64 类型的数值,表示不同参数值的近似个数。 示例 基本用法 CREATE TABLE example_theta ( id UInt32, category String ) ENGINE = Memory; INSERT INTO example_theta VALUES (1, 'A'), (2, 'B'), (3, 'A'), (4, 'C'), (5, 'B'), (6, 'A'); SELECT uniqTheta(category) as theta_unique_categories FROM example_theta; ┌─theta_unique_categories─┐ │ 3 │ └─────────────────────────┘ 另请参阅 uniq uniqCombined uniqCombined64 uniqHLL12 uniqExact