跳到主要内容

uniqTheta 函数

uniqTheta 函数用于对两个 uniqThetaSketch 对象执行集合操作计算,例如 ∪ / ∩ / ×(并集/交集/非),返回一个包含结果的新 uniqThetaSketch 对象。

uniqThetaSketch 对象由聚合函数 uniqTheta 与 -State 构建。

UniqThetaSketch 是一种近似值集的存储数据结构。有关 RoaringBitmap 的更多信息,请参阅:Theta Sketch Framework.

uniqThetaUnion

两个 uniqThetaSketch 对象执行并集计算(集合操作 ∪),结果是一个新的 uniqThetaSketch。

uniqThetaUnion(uniqThetaSketch,uniqThetaSketch)

参数

  • uniqThetaSketch – uniqThetaSketch 对象。

示例

select finalizeAggregation(uniqThetaUnion(a, b)) as a_union_b, finalizeAggregation(a) as a_cardinality, finalizeAggregation(b) as b_cardinality
from
(select arrayReduce('uniqThetaState',[1,2]) as a, arrayReduce('uniqThetaState',[2,3,4]) as b );
┌─a_union_b─┬─a_cardinality─┬─b_cardinality─┐
│ 4 │ 2 │ 3 │
└───────────┴───────────────┴───────────────┘

uniqThetaIntersect

两个 uniqThetaSketch 对象执行交集计算(集合操作 ∩),结果是一个新的 uniqThetaSketch。

uniqThetaIntersect(uniqThetaSketch,uniqThetaSketch)

参数

  • uniqThetaSketch – uniqThetaSketch 对象。

示例

select finalizeAggregation(uniqThetaIntersect(a, b)) as a_intersect_b, finalizeAggregation(a) as a_cardinality, finalizeAggregation(b) as b_cardinality
from
(select arrayReduce('uniqThetaState',[1,2]) as a, arrayReduce('uniqThetaState',[2,3,4]) as b );
┌─a_intersect_b─┬─a_cardinality─┬─b_cardinality─┐
│ 1 │ 2 │ 3 │
└───────────────┴───────────────┴───────────────┘

uniqThetaNot

两个 uniqThetaSketch 对象执行 a_not_b 计算(集合操作 ×),结果是一个新的 uniqThetaSketch。

uniqThetaNot(uniqThetaSketch,uniqThetaSketch)

参数

  • uniqThetaSketch – uniqThetaSketch 对象。

示例

select finalizeAggregation(uniqThetaNot(a, b)) as a_not_b, finalizeAggregation(a) as a_cardinality, finalizeAggregation(b) as b_cardinality
from
(select arrayReduce('uniqThetaState',[2,3,4]) as a, arrayReduce('uniqThetaState',[1,2]) as b );
┌─a_not_b─┬─a_cardinality─┬─b_cardinality─┐
│ 2 │ 3 │ 2 │
└─────────┴───────────────┴───────────────┘

另请参阅