doris:HLL

HLL是用作模糊去重,在数据量大的情况性能优于 Count Distinct。HLL的导入需要结合hll_hash等函数来使用。更多文档参考HLL

使用示例

第 1 步:准备数据

创建如下的 csv 文件:test_hll.csv

复制代码
1001|koga
1002|nijg
1003|lojn
1004|lofn
1005|jfin
1006|kon
1007|nhga
1008|nfubg
1009|huang
1010|buag

第 2 步:在库中创建表

复制代码
CREATE TABLE testdb.test_hll(
    typ_id           BIGINT          NULL   COMMENT "ID",
    typ_name         VARCHAR(10)     NULL   COMMENT "NAME",
    pv               hll hll_union   NOT NULL   COMMENT "hll"
)
AGGREGATE KEY(typ_id,typ_name)
DISTRIBUTED BY HASH(typ_id) BUCKETS 10;

第 3 步:导入数据

复制代码
curl --location-trusted -u <doris_user>:<doris_password> \
    -H "column_separator:|" \
    -H "columns:typ_id,typ_name,pv=hll_hash(typ_id)" \
    -T test_hll.csv \
    -XPUT http://<fe_ip>:<fe_http_port>/api/testdb/test_hll/_stream_load

第 4 步:检查导入数据

使用 hll_cardinality 进行查询:

复制代码
mysql> select typ_id,typ_name,hll_cardinality(pv) from testdb.test_hll;
+--------+----------+---------------------+
| typ_id | typ_name | hll_cardinality(pv) |
+--------+----------+---------------------+
|   1010 | buag     |                   1 |
|   1002 | nijg     |                   1 |
|   1001 | koga     |                   1 |
|   1008 | nfubg    |                   1 |
|   1005 | jfin     |                   1 |
|   1009 | huang    |                   1 |
|   1004 | lofn     |                   1 |
|   1007 | nhga     |                   1 |
|   1003 | lojn     |                   1 |
|   1006 | kon      |                   1 |
+--------+----------+---------------------+
10 rows in set (0.06 sec)
相关推荐
孟意昶11 天前
Doris专题31-SQL手册-基础元素
大数据·数据库·数据仓库·分布式·sql·知识图谱·doris
孟意昶14 天前
Doris专题28-聚合多维分析
大数据·数据库·数据仓库·sql·doris
Henb92916 天前
# StarRocks/Doris 深度实践
doris
千月落18 天前
部署Doris存算一体集群
doris
何中应21 天前
Doris部署&连接
大数据·数据库·时序数据库·doris
喵了几个咪1 个月前
Apache Doris 4.x 在量化交易中的完整应用实践
ai·doris·量化交易
piepis1 个月前
Doris 快速写入原理
doris
AllData公司负责人1 个月前
高效同步!离线开发平台(DolphinScheduler) 实现Apache IotDB物联网数据同步到 Doris
apache·doris·iotdb
jasnet_u2 个月前
Doris的集群搭建(3FE+3BE)
doris·mpp
家有娇妻张兔兔2 个月前
Apache Doris 副本故障排查与修复实战指南
apache·doris·时序库