WordCount

Description

WordCount
Nilesh Patel
Note by Nilesh Patel, updated more than 1 year ago
Nilesh Patel
Created by Nilesh Patel about 7 years ago
6
0
1 2 3 4 5 (0)

Resource summary

Page 1

Word Count:   Example 1 (RDD) val txtfile=sc.textFile("C:/Users/Redirection/pateln7/Downloads/SPARK/wordcount.txt") val txtflatmap= txtfile.flatMap(x=>x.split(" ")) txtflatmap.first val txtmap=txtflatmap.map(x=>(x,1)) txtmap.first val output=txtmap.reduceByKey(_+_) output.foreach(println)   Single line : val output = txtfile.flatMap(x=>x.split(" ")).map(x=>(x,1)).reduceByKey(_+_) output.foreach(println)     Example 2  (RDD) val txtfile=sc.textFile("C:/Users/Redirection/pateln7/Downloads/SPARK/wordcount.txt") val txtflatmap= txtfile.flatMap(x=>x.split(" ")) txtflatmap.first val txtmap=txtflatmap.map(x=>(x,1)) txtmap.first val output = txtmap.reduceByKey((x,txtmap)=>(x+txtmap)).foreach(println)   Example 3 (for Array[(string ,Int) ] type data  val str = "Hell saying hello is good, keep say hello"  val x =str.split(" ").map(x=> (x, 1))  val q = sc.parallelize(x)  q.reduceByKey(_+_).foreach(println)

Show full summary Hide full summary

0 comments

There are no comments, be the first and leave one below:

Similar

Joins
Nilesh Patel
Setup spark scala in windows
Nilesh Patel
Othello content knowledge quiz
rubyduggan
HRCI Glossary of Terms A-N
Sandra Reed
Polymers, alkanes and alkenes
amira-2000
The Circulatory System
Shane Buckley
Biopsychology
Emily Cushlow
ASSD & PSBD QUESTION 2018 200
Dhiraj Tamang
3MA114 Management_test 1/2
Jakub Beyr