Flink源码解读(四) Flink1.9之新特性--数据结构二进制化&minibatch aggregation

数据结构二进制化源码解读org/apache/flink/table/dataformat/BinaryRow.java由Flink的最小内存管理单元 MemorySegment 支撑实现,能够大量减少序列化与反序列化的开销正如上图所示,一个binary row含有两个部分: 定长和变长部分Fixed-length part:一个字节长的headernull bit sets ...
摘要由CSDN通过智能技术生成

数据结构二进制化

在这里插入图片描述

源码解读

org/apache/flink/table/dataformat/BinaryRow.java

  • 由Flink的最小内存管理单元 MemorySegment 支撑实现,能够大量减少序列化与反序列化的开销
  • 正如上图所示,一个binary row含有两个部分: 定长和变长部分
  • Fixed-length part:
    • 一个字节长的header
    • null bit sets 用于null 的追踪??与8个字节长的字对齐
    • field values 保存基本类型和能以8个字节长存储的变长的值
    • 否则field values将会存储变长值的长度与offset
    • 完全落在MemorySegment,这会加速field的读写速度。
    • 单行的field的数值不能超过一个MemorySegment的容量
  • variable-length part:
    • 可能会由多个memorySegment来存储

在这里插入图片描述/home/graviti/下载/flink-release-1.9.0/flink-table/flink-table-runtime-blink/src/main/java/org/apache/flink/table/runtime/operators/aggregate

下面对比一下GroupAggFunction 与 MiniBatchGroupAggFunction的区别

GroupAggFunction

/**
	 * 对stream上经过的每一个元素进行处理
	 * @param input
	 * @param ctx A {@link Context} that allows querying the timestamp of the element and getting
	 *            a {@link TimerService} for registering timers and querying the time. The
	 *            context is only valid during the invocation of this method, do not store it.
	 * @param out The collector for returning result values.
	 *
	 * @throws Exception
	 */
	@Override
	public void processElement(BaseRow input, Context ctx, Collector<BaseRow> out) throws Exception {
		long currentTime = ctx.timerService().currentProcessingTime();
		// register state-cleanup timer
		registerProcessingCleanupTimer(ctx, currentTime);

		
		BaseRow currentKey = ctx.getCurrentKey();

		boolean firstRow;
		//以当前的accumulator 是否为空来判断是否是第一行
		BaseRow accumulators = accState.value();
		if (null == accumulators) {
			firstRow = true;
			accumulators = function.createAccumulators();
		} else {
			firstRow = false;
		}

		// set accumulators to handler first
		function.setAccumulators(accum
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值