wordcount程序

文件wordcount.txt

hello wujiadong
hello spark
hello hadoop
hello python

程序示例

package wujiadong_sparkCore

import org.apache.spark.{SparkConf, SparkContext}

/**
* Created by Administrator on 2017/2/25.
*/
object LocalSpark {
def main(args: Array[String]): Unit = {
//第一步:创建SparkConf对象,设置spark应用的配置信息
//使用setMaster()可以设置spark应用程序要连接spark集群的master节点的url
//设置为local则代表在本地运行
val conf = new SparkConf().setAppName("localspark").setMaster("local")//在idea里运行的话才需要设置setMaster
//创建SparkContext对象,SparkContex是spark所有功能的一个入口,主要作用包括初始化spark应用程序所需的一些核心组件,包括调度器
//(DAGSchedule、TaskScheduler)还会去spark master节点上进行注册等等
val sc = new SparkContext(conf)
//本地文件
val file = "C://Users//Administrator.USER-20160219OS//Desktop//wordcount.txt"
//针对输入源(hdfs文件,本地文件等),创建一个初始的RDD,RDD中有元素这种概念,每一个元素就相当于文件的一行
val lines = sc.textFile(file)
//对初始RDD进行transformation操作
//先将每一行拆分成一个一个的单词
val wordRDD = lines.flatMap(line => line.split(" "))
//将每个单词映射成(单词,1)这样的格式,后面才能根据单词作为key,来进行每个单词的出现次数的累加
val wordpair = wordRDD.map(word => (word,1))
//以单词作为key,统计每个单词出现的次数(对每个单词的key进行reduce操作)
val result = wordpair.reduceByKey(_+_)
//最后进行action操作,比如可以使用foreach进行触发
result.foreach(wordNumberPair => println(wordNumberPair._1 + " , " + wordNumberPair._2)) } }

运行结果

"C:\Program Files\Java\jdk1.8.0_101\bin\java" -Dspark.master=local -Didea.launcher.port=7532 "-Didea.launcher.bin.path=C:\Program Files (x86)\JetBrains\IntelliJ IDEA Community Edition 2016.3.3\bin" -Dfile.encoding=UTF-8 -classpath "C:\Program Files\Java\jdk1.8.0_101\jre\lib\charsets.jar;C:\Program Files\Java\jdk1.8.0_101\jre\lib\deploy.jar;C:\Program Files\Java\jdk1.8.0_101\jre\lib\ext\access-bridge-64.jar;C:\Program Files\Java\jdk1.8.0_101\jre\lib\ext\cldrdata.jar;C:\Program Files\Java\jdk1.8.0_101\jre\lib\ext\dnsns.jar;C:\Program Files\Java\jdk1.8.0_101\jre\lib\ext\jaccess.jar;C:\Program Files\Java\jdk1.8.0_101\jre\lib\ext\jfxrt.jar;C:\Program Files\Java\jdk1.8.0_101\jre\lib\ext\localedata.jar;C:\Program Files\Java\jdk1.8.0_101\jre\lib\ext\nashorn.jar;C:\Program Files\Java\jdk1.8.0_101\jre\lib\ext\sunec.jar;C:\Program Files\Java\jdk1.8.0_101\jre\lib\ext\sunjce_provider.jar;C:\Program Files\Java\jdk1.8.0_101\jre\lib\ext\sunmscapi.jar;C:\Program Files\Java\jdk1.8.0_101\jre\lib\ext\sunpkcs11.jar;C:\Program Files\Java\jdk1.8.0_101\jre\lib\ext\zipfs.jar;C:\Program Files\Java\jdk1.8.0_101\jre\lib\javaws.jar;C:\Program Files\Java\jdk1.8.0_101\jre\lib\jce.jar;C:\Program Files\Java\jdk1.8.0_101\jre\lib\jfr.jar;C:\Program Files\Java\jdk1.8.0_101\jre\lib\jfxswt.jar;C:\Program Files\Java\jdk1.8.0_101\jre\lib\jsse.jar;C:\Program Files\Java\jdk1.8.0_101\jre\lib\management-agent.jar;C:\Program Files\Java\jdk1.8.0_101\jre\lib\plugin.jar;C:\Program Files\Java\jdk1.8.0_101\jre\lib\resources.jar;C:\Program Files\Java\jdk1.8.0_101\jre\lib\rt.jar;D:\wujiadong.spark\out\production\wujiadong.spark;C:\Program Files (x86)\scala\lib\scala-library.jar;C:\Program Files (x86)\scala\lib\scala-reflect.jar;F:\spark-assembly-1.5.1-hadoop2.6.0.jar;C:\Program Files (x86)\JetBrains\IntelliJ IDEA Community Edition 2016.3.3\lib\idea_rt.jar" com.intellij.rt.execution.application.AppMain wujiadong_sparkCore.LocalSpark
Using Spark's default log4j profile: org/apache/spark/log4j-defaults.properties
17/03/04 20:41:21 INFO SparkContext: Running Spark version 1.5.1
17/03/04 20:41:24 WARN NativeCodeLoader: Unable to load native-hadoop library for your platform... using builtin-java classes where applicable
17/03/04 20:41:24 INFO SecurityManager: Changing view acls to: Administrator
17/03/04 20:41:24 INFO SecurityManager: Changing modify acls to: Administrator
17/03/04 20:41:24 INFO SecurityManager: SecurityManager: authentication disabled; ui acls disabled; users with view permissions: Set(Administrator); users with modify permissions: Set(Administrator)
17/03/04 20:41:27 INFO Slf4jLogger: Slf4jLogger started
17/03/04 20:41:27 INFO Remoting: Starting remoting
17/03/04 20:41:28 INFO Remoting: Remoting started; listening on addresses :[akka.tcp://sparkDriver@10.11.25.3:64151]
17/03/04 20:41:29 INFO Utils: Successfully started service 'sparkDriver' on port 64151.
17/03/04 20:41:29 INFO SparkEnv: Registering MapOutputTracker
17/03/04 20:41:30 INFO SparkEnv: Registering BlockManagerMaster
17/03/04 20:41:31 INFO DiskBlockManager: Created local directory at C:\Users\Administrator.USER-20160219OS\AppData\Local\Temp\blockmgr-8339dad4-0230-405c-8ff3-f28fe073b327
17/03/04 20:41:35 INFO MemoryStore: MemoryStore started with capacity 972.5 MB
17/03/04 20:41:38 INFO HttpFileServer: HTTP File server directory is C:\Users\Administrator.USER-20160219OS\AppData\Local\Temp\spark-7aef918f-fd75-4153-833e-f29def7f1805\httpd-e95baaaa-f8c5-43e3-be14-8b45a90fce45
17/03/04 20:41:38 INFO HttpServer: Starting HTTP Server
17/03/04 20:41:40 INFO Utils: Successfully started service 'HTTP file server' on port 64166.
17/03/04 20:41:40 INFO SparkEnv: Registering OutputCommitCoordinator
17/03/04 20:41:42 INFO Utils: Successfully started service 'SparkUI' on port 4040.
17/03/04 20:41:42 INFO SparkUI: Started SparkUI at http://10.11.25.3:4040
17/03/04 20:41:43 WARN MetricsSystem: Using default name DAGScheduler for source because spark.app.id is not set.
17/03/04 20:41:43 INFO Executor: Starting executor ID driver on host localhost
17/03/04 20:41:47 INFO Utils: Successfully started service 'org.apache.spark.network.netty.NettyBlockTransferService' on port 64205.
17/03/04 20:41:47 INFO NettyBlockTransferService: Server created on 64205
17/03/04 20:41:47 INFO BlockManagerMaster: Trying to register BlockManager
17/03/04 20:41:47 INFO BlockManagerMasterEndpoint: Registering block manager localhost:64205 with 972.5 MB RAM, BlockManagerId(driver, localhost, 64205)
17/03/04 20:41:47 INFO BlockManagerMaster: Registered BlockManager
17/03/04 20:41:52 INFO MemoryStore: ensureFreeSpace(130448) called with curMem=0, maxMem=1019782103
17/03/04 20:41:52 INFO MemoryStore: Block broadcast_0 stored as values in memory (estimated size 127.4 KB, free 972.4 MB)
17/03/04 20:41:53 INFO MemoryStore: ensureFreeSpace(14276) called with curMem=130448, maxMem=1019782103
17/03/04 20:41:53 INFO MemoryStore: Block broadcast_0_piece0 stored as bytes in memory (estimated size 13.9 KB, free 972.4 MB)
17/03/04 20:41:53 INFO BlockManagerInfo: Added broadcast_0_piece0 in memory on localhost:64205 (size: 13.9 KB, free: 972.5 MB)
17/03/04 20:41:53 INFO SparkContext: Created broadcast 0 from textFile at LocalSpark.scala:20
17/03/04 20:41:56 INFO FileInputFormat: Total input paths to process : 1
17/03/04 20:41:56 INFO SparkContext: Starting job: foreach at LocalSpark.scala:29
17/03/04 20:41:58 INFO DAGScheduler: Registering RDD 3 (map at LocalSpark.scala:25)
17/03/04 20:41:58 INFO DAGScheduler: Got job 0 (foreach at LocalSpark.scala:29) with 1 output partitions
17/03/04 20:41:58 INFO DAGScheduler: Final stage: ResultStage 1(foreach at LocalSpark.scala:29)
17/03/04 20:41:58 INFO DAGScheduler: Parents of final stage: List(ShuffleMapStage 0)
17/03/04 20:41:58 INFO DAGScheduler: Missing parents: List(ShuffleMapStage 0)
17/03/04 20:41:58 INFO DAGScheduler: Submitting ShuffleMapStage 0 (MapPartitionsRDD[3] at map at LocalSpark.scala:25), which has no missing parents
17/03/04 20:41:59 INFO MemoryStore: ensureFreeSpace(4120) called with curMem=144724, maxMem=1019782103
17/03/04 20:41:59 INFO MemoryStore: Block broadcast_1 stored as values in memory (estimated size 4.0 KB, free 972.4 MB)
17/03/04 20:41:59 INFO MemoryStore: ensureFreeSpace(2337) called with curMem=148844, maxMem=1019782103
17/03/04 20:41:59 INFO MemoryStore: Block broadcast_1_piece0 stored as bytes in memory (estimated size 2.3 KB, free 972.4 MB)
17/03/04 20:41:59 INFO BlockManagerInfo: Added broadcast_1_piece0 in memory on localhost:64205 (size: 2.3 KB, free: 972.5 MB)
17/03/04 20:41:59 INFO SparkContext: Created broadcast 1 from broadcast at DAGScheduler.scala:861
17/03/04 20:41:59 INFO DAGScheduler: Submitting 1 missing tasks from ShuffleMapStage 0 (MapPartitionsRDD[3] at map at LocalSpark.scala:25)
17/03/04 20:41:59 INFO TaskSchedulerImpl: Adding task set 0.0 with 1 tasks
17/03/04 20:42:00 INFO TaskSetManager: Starting task 0.0 in stage 0.0 (TID 0, localhost, PROCESS_LOCAL, 2164 bytes)
17/03/04 20:42:00 INFO Executor: Running task 0.0 in stage 0.0 (TID 0)
17/03/04 20:42:00 INFO HadoopRDD: Input split: file:/C:/Users/Administrator.USER-20160219OS/Desktop/wordcount.txt:0+54
17/03/04 20:42:00 INFO deprecation: mapred.tip.id is deprecated. Instead, use mapreduce.task.id
17/03/04 20:42:00 INFO deprecation: mapred.task.id is deprecated. Instead, use mapreduce.task.attempt.id
17/03/04 20:42:00 INFO deprecation: mapred.task.is.map is deprecated. Instead, use mapreduce.task.ismap
17/03/04 20:42:00 INFO deprecation: mapred.task.partition is deprecated. Instead, use mapreduce.task.partition
17/03/04 20:42:00 INFO deprecation: mapred.job.id is deprecated. Instead, use mapreduce.job.id
17/03/04 20:42:01 INFO Executor: Finished task 0.0 in stage 0.0 (TID 0). 2253 bytes result sent to driver
17/03/04 20:42:01 INFO TaskSetManager: Finished task 0.0 in stage 0.0 (TID 0) in 1448 ms on localhost (1/1)
17/03/04 20:42:01 INFO TaskSchedulerImpl: Removed TaskSet 0.0, whose tasks have all completed, from pool
17/03/04 20:42:01 INFO DAGScheduler: ShuffleMapStage 0 (map at LocalSpark.scala:25) finished in 1.633 s
17/03/04 20:42:01 INFO DAGScheduler: looking for newly runnable stages
17/03/04 20:42:01 INFO DAGScheduler: running: Set()
17/03/04 20:42:01 INFO DAGScheduler: waiting: Set(ResultStage 1)
17/03/04 20:42:01 INFO DAGScheduler: failed: Set()
17/03/04 20:42:01 INFO DAGScheduler: Missing parents for ResultStage 1: List()
17/03/04 20:42:01 INFO DAGScheduler: Submitting ResultStage 1 (ShuffledRDD[4] at reduceByKey at LocalSpark.scala:27), which is now runnable
17/03/04 20:42:01 INFO MemoryStore: ensureFreeSpace(2224) called with curMem=151181, maxMem=1019782103
17/03/04 20:42:01 INFO MemoryStore: Block broadcast_2 stored as values in memory (estimated size 2.2 KB, free 972.4 MB)
17/03/04 20:42:01 INFO MemoryStore: ensureFreeSpace(1380) called with curMem=153405, maxMem=1019782103
17/03/04 20:42:01 INFO MemoryStore: Block broadcast_2_piece0 stored as bytes in memory (estimated size 1380.0 B, free 972.4 MB)
17/03/04 20:42:01 INFO BlockManagerInfo: Added broadcast_2_piece0 in memory on localhost:64205 (size: 1380.0 B, free: 972.5 MB)
17/03/04 20:42:01 INFO SparkContext: Created broadcast 2 from broadcast at DAGScheduler.scala:861
17/03/04 20:42:01 INFO DAGScheduler: Submitting 1 missing tasks from ResultStage 1 (ShuffledRDD[4] at reduceByKey at LocalSpark.scala:27)
17/03/04 20:42:01 INFO TaskSchedulerImpl: Adding task set 1.0 with 1 tasks
17/03/04 20:42:01 INFO TaskSetManager: Starting task 0.0 in stage 1.0 (TID 1, localhost, PROCESS_LOCAL, 1901 bytes)
17/03/04 20:42:01 INFO Executor: Running task 0.0 in stage 1.0 (TID 1)
17/03/04 20:42:02 INFO ShuffleBlockFetcherIterator: Getting 1 non-empty blocks out of 1 blocks
17/03/04 20:42:02 INFO ShuffleBlockFetcherIterator: Started 0 remote fetches in 55 ms
spark , 1
wujiadong , 1
hadoop , 1
python , 1
hello , 4
17/03/04 20:42:02 INFO Executor: Finished task 0.0 in stage 1.0 (TID 1). 1165 bytes result sent to driver
17/03/04 20:42:02 INFO TaskSetManager: Finished task 0.0 in stage 1.0 (TID 1) in 367 ms on localhost (1/1)
17/03/04 20:42:02 INFO TaskSchedulerImpl: Removed TaskSet 1.0, whose tasks have all completed, from pool
17/03/04 20:42:02 INFO DAGScheduler: ResultStage 1 (foreach at LocalSpark.scala:29) finished in 0.370 s
17/03/04 20:42:02 INFO DAGScheduler: Job 0 finished: foreach at LocalSpark.scala:29, took 5.915115 s
17/03/04 20:42:02 INFO SparkContext: Invoking stop() from shutdown hook
17/03/04 20:42:02 INFO SparkUI: Stopped Spark web UI at http://10.11.25.3:4040
17/03/04 20:42:02 INFO DAGScheduler: Stopping DAGScheduler
17/03/04 20:42:02 INFO MapOutputTrackerMasterEndpoint: MapOutputTrackerMasterEndpoint stopped!
17/03/04 20:42:03 INFO MemoryStore: MemoryStore cleared
17/03/04 20:42:03 INFO BlockManager: BlockManager stopped
17/03/04 20:42:03 INFO BlockManagerMaster: BlockManagerMaster stopped
17/03/04 20:42:03 INFO OutputCommitCoordinator$OutputCommitCoordinatorEndpoint: OutputCommitCoordinator stopped!
17/03/04 20:42:03 INFO SparkContext: Successfully stopped SparkContext
17/03/04 20:42:03 INFO ShutdownHookManager: Shutdown hook called
17/03/04 20:42:03 INFO ShutdownHookManager: Deleting directory C:\Users\Administrator.USER-20160219OS\AppData\Local\Temp\spark-7aef918f-fd75-4153-833e-f29def7f1805 Process finished with exit code 0

spark学习11(Wordcount程序-本地测试)的更多相关文章

  1. Spark学习之wordcount程序

    实例代码: import org.apache.spark.SparkConf; import org.apache.spark.api.java.JavaPairRDD; import org.ap ...

  2. 在Spark上运行WordCount程序

    1.编写程序代码如下: Wordcount.scala package Wordcount import org.apache.spark.SparkConf import org.apache.sp ...

  3. 50、Spark Streaming实时wordcount程序开发

    一.java版本 package cn.spark.study.streaming; import java.util.Arrays; import org.apache.spark.SparkCon ...

  4. WordCount程序及测试

    Github地址:https://github.com/CG0317/WordCount PSP表: PSP2.1 PSP阶段 预估耗时 (分钟) 实际耗时 (分钟) Planning 计划  30 ...

  5. WordCount程序与测试

    Github地址: https://github.com/hcy6668/wordCount PSP表格: PSP PSP阶段 预估耗时(分钟) 实际耗时(分钟) Planning 计划 60 40 ...

  6. Spark中的wordCount程序实现

    import org.apache.spark.SparkConf; import org.apache.spark.api.java.JavaPairRDD; import org.apache.s ...

  7. Spark学习之第一个程序 WordCount

    WordCount程序 求下列文件中使用空格分割之后,单词出现的个数 input.txt java scala python hello world java pyfysf upuptop wintp ...

  8. 【Spark深入学习-11】Spark基本概念和运行模式

    ----本节内容------- 1.大数据基础 1.1大数据平台基本框架 1.2学习大数据的基础 1.3学习Spark的Hadoop基础 2.Hadoop生态基本介绍 2.1Hadoop生态组件介绍 ...

  9. 编写Spark的WordCount程序并提交到集群运行[含scala和java两个版本]

    编写Spark的WordCount程序并提交到集群运行[含scala和java两个版本] 1. 开发环境 Jdk 1.7.0_72 Maven 3.2.1 Scala 2.10.6 Spark 1.6 ...

随机推荐

  1. windows安装oracle11g

    windows上安装oracle11g   1.下载Oracle 11g R2 for Windows的版本 下载地址:https://www.oracle.com/technetwork/datab ...

  2. 【BZOJ4108】[Wf2015]Catering 有上下界费用流

    [BZOJ4108][Wf2015]Catering Description 有一家装备出租公司收到了按照时间顺序排列的n个请求. 这家公司有k个搬运工.每个搬运工可以搬着一套装备按时间顺序去满足一些 ...

  3. iOS 程序切换后台

    1. -(void)animationFinished:(NSString*)animationid finished:(NSNumber*)finished context:(void*)conte ...

  4. ES6入门概览二--数组

    一 数组 1. Array.from() 将两类对象转为真的数组 : 类似数组的对象(伪数组,如arguments.document.getElementsByTagNames等)和可遍历对象(包括E ...

  5. Parrot Linux国内源

    China USTC (University of Science and Technology of China and USTCLUG) - Hefei University 1 Gbps for ...

  6. python基础之类的进阶

    一.__setitem__,__getitem,__delitem__ #把对象操作属性模拟成字典的格式 class Foo: def __init__(self,name): self.name=n ...

  7. 请写出用于校验HTML文本框中输入的内容全部为数字的javascript代码

    <%@ page contentType="text/html;charset=UTF-8" language="java" %> <html ...

  8. Numpy常用操作方法

    NumPy NumPy是高性能科学计算和数据分析的基础包.部分功能如下: ndarray, 具有矢量算术运算和复杂广播能力的快速且节省空间的多维数组. 用于对整组数据进行快速运算的标准数学函数(无需编 ...

  9. python线程池应用场景-爬虫

    import requests from bs4 import BeautifulSoup from concurrent.futures import ThreadPoolExecutor, Pro ...

  10. 谷歌公布全新设计语言:跟苹果Swift天差地别

    今日凌晨.谷歌(微博)在I/O大会上公布了全新设计语言Material Design.在20多天前的WWDC上.苹果也公布了全新编程语言Swift.两家科技巨头公司,在一年一度的开发人员大会上,都公布 ...