学习 Flink(十七):HyperLogLog 去重计数

栏目: 编程工具 · 发布时间: 5年前

内容简介:在需要对数据进行去重计数的场景里,实现方式是将数据明细存储在集合的数据结构中。然而,随着数据随时间的不断累积,明细数据占用了大量的存储空间。使用 HyperLoglog 去重计数,在牺牲非常小准确性的情况下,可以极大的减少数据存储。编辑 pom.xml 文件,添加依赖:定义状态:

在需要对数据进行去重计数的场景里,实现方式是将数据明细存储在集合的数据结构中。然而,随着数据随时间的不断累积,明细数据占用了大量的存储空间。使用 HyperLoglog 去重计数,在牺牲非常小准确性的情况下,可以极大的减少数据存储。

依赖

编辑 pom.xml 文件,添加依赖:

<dependency>  
    <groupId>net.agkn</groupId>
    <artifactId>hll</artifactId>
    <version>1.6.0</version>
</dependency>

使用

定义状态:

private ValueState<Byte[]> hllState;

初识化状态:

@Override
public void open(Configuration parameters) throws Exception {  
    super.open(parameters);
    ValueStateDescriptor<Byte[]> hllStateDescriptor = new ValueStateDescriptor<>(
        "hll",
        Types.OBJECT_ARRAY(Types.BYTE)
    );

    this.hllState = getRuntimeContext().getState(hllStateDescriptor);
}

处理方法中,由状态获取 HLL:

HLL hll = null;  
if (this.hllState.value() == null) {  
    hll = new HLL(14, 5);
} else {
    hll = HLL.fromBytes(ArrayUtils.toPrimitive(this.hllState.value()));
}

处理方法中,由 HLL 更新状态:

this.hllState.update(ArrayUtils.toObject(hll.toBytes()));

以上就是本文的全部内容,希望本文的内容对大家的学习或者工作能带来一定的帮助,也希望大家多多支持 码农网

查看所有标签

猜你喜欢:

本站部分资源来源于网络,本站转载出于传递更多信息之目的,版权归原作者或者来源机构所有,如转载稿涉及版权问题,请联系我们

Data Structures and Algorithms in Java

Data Structures and Algorithms in Java

Robert Lafore / Sams / 2002-11-06 / USD 64.99

Data Structures and Algorithms in Java, Second Edition is designed to be easy to read and understand although the topic itself is complicated. Algorithms are the procedures that software programs use......一起来看看 《Data Structures and Algorithms in Java》 这本书的介绍吧!

MD5 加密
MD5 加密

MD5 加密工具

HEX CMYK 转换工具
HEX CMYK 转换工具

HEX CMYK 互转工具

HEX HSV 转换工具
HEX HSV 转换工具

HEX HSV 互换工具