云数据库 GAUSSDB-HLL函数和操作符:聚合函数

时间:2024-11-02 18:48:20

聚合函数

  • hll_add_agg(hll_hashval)

    描述:把哈希后的数据按照分组放到hll中。

    返回值类型:hll

    示例:

     1
     2
     3
     4
     5
     6
     7
     8
     9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    --准备数据
    openGauss=# create table t_id(id int);
    openGauss=# insert into t_id values(generate_series(1,500));
    openGauss=# create table t_data(a int, c text);
    openGauss=# insert into t_data select mod(id,2), id from t_id;
    
    --创建表并指定列为hll
    openGauss=# create table t_a_c_hll(a int, c hll);
    
    --根据a列group by对数据分组,把各组数据加到hll中
    openGauss=# insert into t_a_c_hll select a, hll_add_agg(hll_hash_text(c)) from t_data group by a;
    
    --得到每组数据中hll的Distinct值
    openGauss=# select a, #c as cardinality from t_a_c_hll order by a;
     a |   cardinality    
    ---+------------------
     0 | 247.862354346299
     1 | 250.908710610377
    (2 rows)
    
support.huaweicloud.com/distributed-devg-v2-gaussdb/gaussdb_v5r2c10_0351.html