跳到主要内容
跳到主要内容

uniqTheta 函数

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

uniqThetaSketch 对象由带有 -State 后缀的聚合函数 uniqTheta 构造。

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)

参数

  • uniqThetaSketchuniqThetaSketch 对象。

示例

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 │
└─────────┴───────────────┴───────────────┘

另请参阅