Submit a Hadoop job to run on spark

Source: Internet
Author: User

1. Introduction of Spark Package: spark-assembly-1.4.0-hadoop2.6.0, in the Lib directory of Spark

File-->project structure

2. Create a Scala project with idea and create a new WordCount object

The 3.WordCount code is as follows:

Import Org.apache.spark.SparkConfimport Org.apache.spark.SparkContextimport org.apache.spark.sparkcontext._ ObjectWordCount {def main (args:array[string]) {if(Args.length <1) {System.err.println ("Usage: <file>") System.exit (1)} Val conf=Newsparkconf () Val SC=Newsparkcontext (Conf) Val line= Sc.textfile (Args (0)) Line.flatmap (_.split (" "). Map ((_,1). Reducebykey (_+_). Collect ().foreach(println) Sc.stop ()}}

4. Package jar: Idea-->project structure-->artifacts--> click +

5. Fill in the exported path, mine is placed in the/home/jiahong/sparktest directory

6. Start the spark cluster and go to http://localhost:8080/to view the primary node address of Spark, mine is: spark://jiahong-optiplex-7010:7077

7. Last jar package to spark in terminal

[Email protected] 7010: ~/spark-1.4. 0-bin-hadoop2. 6$ bin/spark-submit--master Spark://jiahong-optiplex-7010:7077--name Spark_scala--class WordCount--executor-memory 1G--total-executor-cores 2 ~/sparktest/spark_scala.jar/home/jiahong/jia.txt

Enter Hadoop, then use the Spark-submit command to submit the jar package, if you do not understand the above command, you can use Spark-submit--help to view the Help

Spark://jiahong-optiplex-7010:7077  address of the primary node
Address of the Har package for export
--class WordCount The object name for the word count
--executor-memory 1G--total-executor-cores 2 Specifies how much memory is executed and, in what number of CPU cores executed
~/sparktest/spark_scala.jar The location of the exported jar package
/home/jiahong/jia.txt for the calculation of the input to wordcount the word frequency file location

Submit a Hadoop job to run on spark

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.