WordCount Interactive analysis in the Spark shell based on the HDFs file system

Source: Internet
Author: User
Tags hadoop ecosystem hadoop fs

Spark is a distributed memory computing framework that can be deployed in yarn or Mesos managed distributed Systems (Fully distributed) or in a pseudo distributed way on a single machine. It can also be deployed on a single machine in a standalone manner. There are interactive and submit ways to run spark. All of the actions in this article are interactive operations that are deployed in standalone mode by Spark. Refer to Hadoop Ecosystem for specific deployment options.

HDFS is a distributed file management system that is installed by default as Hadoop is installed. The deployment method has local mode and cluster mode, which is used in this article when local mode. Refer to Hadoop Ecosystem for specific deployment options.

Goal:

The ability to perform wordcount operations in Spark-shell via the HDFs file system.

Premise:

There is a file that can be viewed by the following command.

Hadoop Fs-ls/

If it does not exist, add one (the license file needs to exist in the local directory). For more Hadoop commands, refer to Hadoop commands.

Hadoop fs-put License/license.txt

See if Hadoop is already running through the Web browser.

http://localhost:50070

Steps:

Step 1: Enter the Spark-shell interactive command line.

Spark-shell

Step 2: Read the License.txt file and check whether the read was successful. If it does not exist, the following error is indicated.

val s = sc.textfile ("Hdfs://localhost:9000/license.txt")

S.count

Step 3: Set the number of files to output and perform statistical logic

Val numoutputfiles = 128

Val counts = S.flatmap (line = Line.split ("")). Map (Word = = (Word, 1)). Reducebykey (_ + _, Numoutputfiles)

Step 4: Save the calculation results in HDFs

Counts.saveastextfile ("Hdfs://localhost:9000/license_hdfs.txt")

Step 5: View the results in the shell

Hadoop fs-cat/license_hdfs.txt/*

Conclusion:

With HDFs, we can easily perform interactive analysis (word count statistics) in Spark-shell.

Resources:

Http://hadoop.apache.org/docs/r1.0.4/cn/commands_manual.html

Http://spark.apache.org/docs/latest/programming-guide.html

Http://coe4bd.github.io/HadoopHowTo/sparkScala/sparkScala.html

Http://coe4bd.github.io/HadoopHowTo/sparkJava/sparkJava.html

WordCount Interactive analysis in the Spark shell based on the HDFs file system

Related Article

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.