spark countByKey用法详解
来源:互联网 发布:mac 10.7.5 dmg 编辑:程序博客网 时间:2024/06/15 22:23
统计每个key对应的value个数,需要注意的是rdd类型是pairRdd,即键值对的形式的rdd,详细代码如下:
private static void myCountByKey(){
SparkConf conf=new SparkConf()
.setMaster("local")
.setAppName("myCountByKey");
JavaSparkContext sc=new JavaSparkContext(conf);
List<Tuple2<String,String>> studentList=Arrays.asList(new Tuple2<String,String>("c1","cai"),new Tuple2<String,String>("c2","niao")
,new Tuple2<String,String>("c1","feng"),new Tuple2<String,String>("c2","jin"),new Tuple2<String,String>("c2","niao"));
JavaPairRDD<String, String> studentRdd= sc.parallelizePairs(studentList);
Map<String, Object> studentCounts=studentRdd.countByKey();
for(Map.Entry<String, Object> map:studentCounts.entrySet()){
System.out.println("key:"+map.getKey()+",values:"+map.getValue());
}
}
运行结果:
key:c2,values:3
key:c1,values:2
- spark countByKey用法详解
- spark rddToPairRDDFunctions countByKey
- spark--Actions算子--countByKey
- Spark算子[07]:reduce,reduceByKey,count,countByKey
- 【Spark Java API】Action(2)—fold、countByKey
- Spark算子:RDD行动Action操作(4)–countByKey、foreach
- 3.4 Spark RDD Action操作4-countByKey、foreach、foreachPartition、sortBy
- Spark算子:RDD行动Action操作(4)–countByKey、foreach、foreachPartition、sortBy
- Spark算子:RDD行动Action操作(4)–countByKey、foreach、foreachPartition、sortBy
- Spark算子:RDD行动Action操作(4)–countByKey、foreach、foreachPartition、sortBy
- Spark算子:RDD行动Action操作(4)–countByKey、foreach、foreachPartition、sortBy
- spark RDD算子(十)之PairRDD的Action操作countByKey, collectAsMap
- 拼写错误:value countBykey is not a member of org.apache.spark.rdd.RDD[(String, Int)]
- Spark详解
- spark详解
- spark详解
- spark详解
- spark streaming updateStateByKey 用法
- 【有感】《菊与刀》——换个角度看日本
- CSS中关于定位的问题, 相对,绝对定位
- 电子海图7Csahara.000解析结果
- 软考之路(三)——数据结构之查找表与哈希表
- LayoutInflater
- spark countByKey用法详解
- Promise
- 第十二周项目一-实现复数类中的运算符重载(3)
- HTML中的<head/>不能省略
- centos7的一些改变
- 自定义View遇到的小坑
- 【github】github 使用教程初级版【wins】
- MySQL函数-- FIND_IN_SET的使用
- 淘宝开源网络框架TBNET分析