spark_updateStateByKey
java核心代码
JavaPairDStream<String, Integer> wordCounts = pair.updateStateByKey(new Function2<List<Integer>, Optional<Integer>, Optional<Integer>>() {
@Override
public Optional<Integer> call(List<Integer> values,
Optional<Integer> state) throws Exception {
Integer newValue = 0;
if(state.isPresent())
{
newValue = state.get();
}
for(Integer value : values)
{
newValue += value;
}
return Optional.of(newValue);
}
});
scala:
val wordCounts = pairs.updateStateByKey((values:Seq[Int],state:Option[Int]) => {
var newValue = state.getOrElse(0);
for(value <- values)
{
newValue += value;
}
Option(newValue)
})
spark_updateStateByKey的更多相关文章
随机推荐
- static关键字的理解
#include<stdio.h> int counter(int i){ static int count=0;//编译时只运行一次 count=count+i; return coun ...
- 关于Spatial referencing by geographical identifiers 标准
地理信息空间参考大体可以分为两类,ISO给出了分类:Spatial referencing by geographical identifiers(根据地理标识符的空间定位,ISO 19112)与Sp ...
- [pjsip]Pjlib中的链表结构
Pjlib的链表结构跟常见的链表结构有所区别,如下图所示: 图1:一般链表结构 图2:pjlib中的链表结构 可以看到一般的双向链表是链表节点包含数据域,而pjlib中是数据域包含链表节点.一般的链表 ...
- php 封装分页查询类
<?php /** file: page.class.php 完美分页类 Page */ class Page { private $total; //数据表中总记录数 private $lis ...
- objectARX判断当前坐标系
判断当前坐标系是WCS还是UCS 使用系统变量 WORLDUCS 请参见 用户坐标系 (UCS) 概述 (只读) 类型: 整数 保存位置: 未保存 初始值: 1 指示 UCS 是否与 WCS 相同 ...
- Intellij IDEA Help
https://www.jetbrains.com/idea/help/intellij-idea.html https://www.jetbrains.com/idea/help/creating- ...
- Camel routes in Spring config file
The normal spring bean definition configuration file, the xsi:schemaLocation only has two: beans and ...
- HDU 5025
http://acm.hdu.edu.cn/showproblem.php?pid=5025 蛇最多只有五条,状态压缩一下,vis增加两维,表示取得钥匙的状态和蛇的状态,然后一个优先队列的bfs即可解 ...
- 【转】阿里2015校招面试回忆(成功拿到offer)
原文转自:http://blog.jobbole.com/78722/ 1. 引言 继上次<百度2015校园招聘面试题回忆(成功拿到offer)>文章过后,大家都希望除了题目之外,最好能给 ...
- CentOS 6.6 nginx PHP 配置
/************************************************************************* * CentOS 6.6 nginx PHP 配置 ...