-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathUploader_Video_Count.scala
34 lines (26 loc) · 995 Bytes
/
Uploader_Video_Count.scala
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
package tube.analysis
import scala.collection.mutable.ListBuffer
import org.apache.log4j.{Level, Logger}
import org.apache.spark.{SparkConf, SparkContext}
/**
*
* This program finds the number of video uploaded by a user
*
*
* Created by maniram on 18/3/18.
*/
object Uploader_Video_Count {
Logger.getLogger("org").setLevel(Level.ERROR)
def main(args: Array[String]) {
val conf = new SparkConf().setMaster("local[2]").setAppName("Number of Uploaded Video by User")
val sc = new SparkContext(conf)
val raw_data = sc.textFile("/home/maniram/data/youtubedata.txt")
// map the user
val user_list = raw_data.filter(line => line.split("\\t").length >1).map(line => (line.split("\\t")(1),1) )
//reduce rdd by the user video uploaded
val video_count_ofuser = user_list.reduceByKey(_+_).sortBy(_._2,ascending = false)
video_count_ofuser.saveAsTextFile("/home/maniram/data/TubeAnalysis/User_Video_Count")
video_count_ofuser.foreach(println)
sc.stop()
}
}