Help Center/
MapReduce Service/
Developer Guide (Normal_Earlier Than 3.x)/
Spark Development Guide/
Developing a Spark Application/
Spark Core Application/
Scala Sample Code
Updated on 2022-06-01 GMT+08:00
Scala Sample Code
Function Description
Collect statistics on female netizens who dwell on online shopping for more than 2 hours on the weekend.
Sample Code
The following code snippets are used as an example. For complete codes, see the com.huawei.bigdata.spark.examples.FemaleInfoCollection class.
// Configure the Spark application name. val conf = new SparkConf().setAppName("CollectFemaleInfo") // Submit a Spark job. val sc = new SparkContext(conf) // Reads data. The input parameter args(0) specifies the data path. val text = sc.textFile(args(0)) // Filter data information of the time that female netizens spend online. val data = text.filter(_.contains("female")) // Summarize the total time that each female netizen spends online. val femaleData:RDD[(String,Int)] = data.map{line => val t= line.split(',') (t(0),t(2).toInt) }.reduceByKey(_ + _) // Filter the information of female netizens who spend more than 2 hours online and output the result. val result = femaleData.filter(line => line._2 > 120) result.foreach(println)
Parent topic: Spark Core Application
Feedback
Was this page helpful?
Provide feedbackThank you very much for your feedback. We will continue working to improve the documentation.See the reply and handling status in My Cloud VOC.
The system is busy. Please try again later.
For any further questions, feel free to contact us through the chatbot.
Chatbot