对文件进行词频统计,是一个大数据领域的hello word级别的应用,来看下实现有多简单:

1 Linux单机处理

egrep -o "\b[[:alpha:]]+\b" test_word.log|sort|uniq -c|sort -rn|head -10

2 Scala单机处理(Array)

line.split(" ").map((_, 1)).groupBy(_._1).map(_._2.reduce((v1, v2) => (v1._1, v1._2 + v2._2))).toArray.sortWith(_._2 > _._2).foreach(println)

3 Spark分布式处理(Scala)

val sparkConf = new SparkConf()
val sc = new SparkContext(sparkConf)
sc.textFile("test_word.log").flatMap(_.split("\\s+")).map((_, 1)).reduceByKey(_ + _).sortBy(_._2, false).take(10).foreach(println)

4 Flink分布式处理(Scala)

    val env = ExecutionEnvironment.getExecutionEnvironment
env.readTextFile("test_word.log").flatMap(_.toLowerCase.split("\\s+").map((_, 1)).groupBy(0).sum(1).sortPartition(1, Order.DESCENDING).first(10).print

5 MongoDB

>db.table_name.mapReduce(function(){ emit(this.column,1);}, function(key, values){return Array.sum(values);}, {out:"post_total"})

6 Hadoop示例

hadoop jar /path/hadoop-2.6.1/share/hadoop/mapreduce/hadoop-mapreduce-examples-2.6.1.jar wordcount /tmp/wordcount/input /tmp/wordcount/output

附:测试文件test_word.log内容如下:

hello world
hello www

输出如下:

2 hello
1 world
1 www

【原创】大数据基础之词频统计Word Count的更多相关文章

  1. 软工之词频统计器及基于sketch在大数据下的词频统计设计

    目录 摘要 算法关键 红黑树 稳定排序 代码框架 .h文件: .cpp文件 频率统计器的实现 接口设计与实现 接口设计 核心功能词频统计器流程 效果 单元测试 性能分析 性能分析图 问题发现 解决方案 ...

  2. 【原创】大数据基础之Zookeeper(2)源代码解析

    核心枚举 public enum ServerState { LOOKING, FOLLOWING, LEADING, OBSERVING; } zookeeper服务器状态:刚启动LOOKING,f ...

  3. 【原创】大数据基础之Spark(5)Shuffle实现原理及代码解析

    一 简介 Shuffle,简而言之,就是对数据进行重新分区,其中会涉及大量的网络io和磁盘io,为什么需要shuffle,以词频统计reduceByKey过程为例, serverA:partition ...

  4. 【原创】大数据基础之Spark(4)RDD原理及代码解析

    一 简介 spark核心是RDD,官方文档地址:https://spark.apache.org/docs/latest/rdd-programming-guide.html#resilient-di ...

  5. 【原创】大数据基础之Flink(1)简介、安装、使用

    Flink 1.7 官方:https://flink.apache.org/ 一 简介 Apache Flink is an open source platform for distributed ...

  6. 【原创】大数据基础之ElasticSearch(2)常用API整理

    Fortunately, Elasticsearch provides a very comprehensive and powerful REST API that you can use to i ...

  7. 【原创】大数据基础之Impala(1)简介、安装、使用

    impala2.12 官方:http://impala.apache.org/ 一 简介 Apache Impala is the open source, native analytic datab ...

  8. 【原创】大数据基础之Benchmark(2)TPC-DS

    tpc 官方:http://www.tpc.org/ 一 简介 The TPC is a non-profit corporation founded to define transaction pr ...

  9. 【原创】大数据基础之Mongodb(2)常用查询命令

    1 下载 https://www.mongodb.com/download-center/community 比如: https://fastdl.mongodb.org/linux/mongodb- ...

随机推荐

  1. vuex的使用步骤

    第一步: 安装vuex:npm install vuex --save 第二步:在src下创建文件夹store及文件index.js import Vue from 'vue'; import Vue ...

  2. 程序员买房指南——LZ的三次买房和一次卖房经历

    引言 买房,一直是程序员群体绕不开的一个话题,尤其是到了一定年纪和人生阶段以后,买房这件事会变得越来越迫切. 为什么LZ一上来就说,买房是程序员绕不开的一个话题? 其实原因很简单,由于程序员这个职业的 ...

  3. python __init__() 和__new__()简析

    先看下面一个例子: 如上图,例1中,构造了函数Foo,并重写了__new__()和__init__()方法,在实例化Foo()的时候,却只调用了__new__() 例2中,在实例化Too()对象时,同 ...

  4. 最速下降方法和Newton方法

    目录 最速下降方法 Euclid范数和二次范数 采用\(\ell_1\)-范数的最速下降方向 Newton 方法 Newton 步径 二阶近似的最优解 线性化最优性条件的解 Newton 步径的仿射不 ...

  5. hadoop用户写入文件权限不够的问题

    问题: 普通用户echo写入文件,提示权限不够. 解决方式: sudo tee test.txt <<< "要插入内容"

  6. AI佳作解读系列(一)——深度学习模型训练痛点及解决方法

    1 模型训练基本步骤 进入了AI领域,学习了手写字识别等几个demo后,就会发现深度学习模型训练是十分关键和有挑战性的.选定了网络结构后,深度学习训练过程基本大同小异,一般分为如下几个步骤 定义算法公 ...

  7. 一招明白URL和URI的区别

    URL和URI的区别(示例): URL[统一资源定位器]: http://localhost:8080/api/account/queryAccountInfo URI[统一资源定位符]: /api/ ...

  8. RCNN算法的tensorflow实现

    RCNN算法的tensorflow实现 转载自:https://blog.csdn.net/MyJournal/article/details/77841348?locationNum=9&f ...

  9. Spring Boot程序获取tomcat启动端口

    package com.geostar.geostack.git_branch_manager.config; import org.springframework.beans.factory.ann ...

  10. java json转换(二)

    package com.kps.common.utils; import com.alibaba.fastjson.JSON; import com.alibaba.fastjson.JSONArra ...