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. ...
随机推荐
- RequireJS跨域加载html模版后被转成JS问题分析及解决
问题描述 RequireJS跨域加载HTML模版失败,例如: 在a.com域名下请求CDN域名下的模版,text.js插件会把html文件转成html.js文件去加载,由于并没有生成html.js文件 ...
- 在grails中远程调用action
在进行类似批处理的程序时,如果在一个action中需要保存很多记录数,这会导致grails中的数据库session超过负荷,从而导致OOM. 因为这个情况的发生是由于在一次请求中,对数据进行的修改都保 ...
- [转]android sqlite db-journal文件产生原因及说明 .
http://blog.csdn.net/kaiwii/article/details/8609093 今天在android中将sqlite的数据库文件生成在SD卡上的过程中,发现生成的.db文件的旁 ...
- pip安装其他包报错
pip安装时报错 Unknown or unsupported command 'install 一.是否配置了路径 配置了看下面的方法. 二.有多个pip系统不知道调用哪个. 1.where pi ...
- python---初始sqlite3
***sqllite不需要单独安装,python2.5以上自带的! ***官方中文文档:https://docs.python.org/2/library/sqlite3.html ***SQLite ...
- DateFormat抽象类实现日期与字符串的转换
[需求]日期是可以计算的,而日期字符串无法计算. 由于DateFormat是抽象类,我们一般都是用的它的子类SimpleDateFormat. [SimpleDateFormat构造方法] 1)Sim ...
- 010 pandas的DataFrame
一:创建 1.通过二维数组进行创建 2.取值 取列,取位置的值 3.切片取值 这个和上面的有些不同,这里先取行,再取列 4.设定列索引 这里使用的行索引与上面不同. 5.通过字典的方式创建 6.索引 ...
- mumu模拟器设置代理/打开网络连接(windows)
adb_server.exe devicesadb_server.exe connect 127.0.0.1:7555adb_server.exe shell am start -a android. ...
- Effective Java 第三版——59. 熟悉并使用Java类库
Tips 书中的源代码地址:https://github.com/jbloch/effective-java-3e-source-code 注意,书中的有些代码里方法是基于Java 9 API中的,所 ...
- spring_AOP
例子代码 理解AOP AOP为Aspect Oriented Programming的缩写,意为:面向切面编程.大概意思就是在原有源代码的基础上,增加功能,而又不修改原有的代码. 术语 切面(Aspe ...