Accumulator<Long> implements of JavaSparkContext in Spark1.x
As we all know , up to Spark 1.6.2, JavaSparkContext only provides two kinds of accumulators: Integer and Double.
However, unfortunately I've met with problems of Integer overflow and the program returned me a negative number.

So I have to use original sparkcontext to implement the Long accumulator.
public static class LongAccumulatorParam implements AccumulatorParam<Long>,Serializable {
@Override
public Long addAccumulator(final Long r, final Long t) {
return r + t;
}
@Override
public Long addInPlace(final Long r1, final Long r2) {
return r1 + r2;
}
@Override
public Long zero(final Long initialValue) {
return 0L;
}
}
final Accumulator<Long> acc = jsc.sc().accumulator(new Long(0), new LongAccumulatorParam());
Actually it is pretty simple. I haven't looked into Spark 2 yet, hope the developers have fixed this issue.
Accumulator<Long> implements of JavaSparkContext in Spark1.x的更多相关文章
- java使用spark/spark-sql处理schema数据(spark1.6)
1.spark是什么? Spark是基于内存计算的大数据并行计算框架. 1.1 Spark基于内存计算 相比于MapReduce基于IO计算,提高了在大数据环境下数据处理的实时性. 1.2 高容错性和 ...
- 【Spark Java API】broadcast、accumulator
转载自:http://www.jianshu.com/p/082ef79c63c1 broadcast 官方文档描述: Broadcast a read-only variable to the cl ...
- spark-2.2.0-bin-hadoop2.6和spark-1.6.1-bin-hadoop2.6发行包自带案例全面详解(java、python、r和scala)之Basic包下的JavaPageRank.java(图文详解)
不多说,直接上干货! spark-1.6.1-bin-hadoop2.6里Basic包下的JavaPageRank.java /* * Licensed to the Apache Software ...
- spark 变量使用 broadcast、accumulator
broadcast 官方文档描述: Broadcast a read-only variable to the cluster, returning a [[org.apache.spark.broa ...
- Spark1.6.2 java实现读取json数据文件插入MySql数据库
public class Main implements Serializable { /** * */ private static final long serialVersionUID = -8 ...
- Spark1.6.2 java实现读取txt文件插入MySql数据库代码
package com.gosun.spark1; import java.util.ArrayList;import java.util.List;import java.util.Properti ...
- flink - accumulator
读accumlator JobManager 在job finish的时候会汇总accumulator的值, newJobStatus match { case JobStatus.FINISHE ...
- spark1.4的本地模式编程练习(1)
spark编程练习 申明:以下代码仅作学习参考使用,勿使用在商业用途. Wordcount UserMining TweetMining HashtagMining InvertedIndex Tes ...
- Spark1.0.x入门指南
1 节点说明 IP Role 192.168.1.111 ActiveNameNode 192.168.1.112 StandbyNameNode,Master,Worker 192.168.1. ...
随机推荐
- php函数xml转化数组
/** * xml转数组 * @param $xml * @return array */ function xml_to_array( $xml ) { $reg = "/<(\\w ...
- 【SPFA与Dijkstra的对比】CDOJ 1961 咸鱼睡觉觉【差分约束-负权最短路径SPFA】
差分约束系统,求最小值,跑最长路. 转自:https://www.cnblogs.com/ehanla/p/9134012.html 题解:设sum[x]为前x个咕咕中至少需要赶走的咕咕数,则sum[ ...
- H5利用pattern属性和oninvalid属性验证表单
HTML代码 <!DOCTYPE html> <html> <head> <meta charset="utf-8"> <ti ...
- eclipse启动web应用 报错
错误:The origin server did not find a current representation for the target resource or is not willing ...
- Mysql my.cnf配置文件记录
一.参数 1.max_binlog_size = 1G #binlog大小 2. #slave不需要同步数据库 binlog-ignore-db=information_schema bin ...
- BZOJ3240 [Noi2013]矩阵游戏 矩阵 快速幂 卡常
原文链接http://www.cnblogs.com/zhouzhendong/p/8084891.html 题目传送门 - BZOJ3240 题意概括 F[1][1]=1F[i,j]=a*F[i][ ...
- Python编程基础[函数和面向对象](三)
Python 函数 函数是组织好的,可重复使用的,用来实现单一,或相关联功能的代码段. 函数能提高应用的模块性,和代码的重复利用率.你已经知道Python提供了许多内建函数,比如print().但你也 ...
- 爬虫2 urllib用法
from urllib import request,parse # 1. 解析数据 # 解析一条 # response = request.urlopen(url='http://httpbin.o ...
- Java 之 JQuery
1.JQuery a.定义:jQuery 是一个 JavaScript 库 b.作用:极大地简化了 JavaScript 编程 c.引入: <script src="jquery.js ...
- python爬虫积累(一)--------selenium+python+PhantomJS的使用(转)
阅读目录 一.Selenium介绍 二.爬虫为什么要用selenium? 三.PhantomJS介绍 四.PhantomJS安装 五.操作实战 六.在此推荐虫师博客的学习资料 selenium + p ...