Ubuntu under Sprak (IDE) WordCount Example

Source: Internet
Author: User

First, enter the IDE interface

CD ~/downloads/idea/bin

idea.sh

Ii. Building a Scala project

Step 1 : Import spark-hadoop corresponding package, select "File" –> "Project Structure" –> "Libraries", select "+" to import Spark-hadoop corresponding package:

Click "OK" to confirm:

Click "OK":

When idea is done, we'll find that Spark's jar package is imported into our project:

Step two, write Scala code implementation wordcount

Import Sparkcontext

Import Sparkcontext._
Object Wordcount {
def main (args:array[string]) {
Val sc = new Sparkcontext ("local", "Simple App", "HOME\\YUANQIN\\DOWNLOADS\\SPARK-0.9.0-INCUBATING-BIN-HADOOP1", NULL)
List ("Lib/spark-assembly_2.10-0.9.0-incubating-hadoop1.0.4.jar")
Val logFile = Sc.textfile ("Hdfs://master:9000/user/root/input/file.txt")//should be some file on your system
Val Count=logfile.flatmap (line = Line.split ("")). Map (Word = = (word,1)). Reducebykey (_+_)
println (count)
Count.saveastextfile ("home\\yuanqin\\output\\2014")

}
}

Step three, right-click Run as ....

Ubuntu under Sprak (IDE) WordCount Example

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.