Hands-on Tour of Apache Spark in 5 Minutes

Hortonworks Sandbox

A Hands-On Example

Let’s open a shell to our Sandbox through SSH:

or putty


Then let’s get some data with the command below in your shell prompt:

Copy the data over to HDFS on Sandbox:

ลอง ls ดูดิ

login เป็น hdfs แล้วเปลี่ยนสิทธิ์ให้ /user/guest

จากนั้นค่อย put ลงไปใหม่ ก็จะได้ละ

Let’s start the PySpark shell and work through a simple example of counting the lines in a file. The shell allows us to interact with our data using Spark and Python:


As discussed above, the first step is to instantiate the Resilient Distributed Dataset (RDD) using the Spark Context sc with the file Hortonworks on HDFS.

Now that we have instantiated the RDD, it’s time to apply some transformation operations on the RDD. In this case, I am going to apply a simple transformation operation using a Python lambda expression to filter out all the empty lines.

Note that the previous Python statement returned without any output. This lack of output signifies that the transformation operation did not touch the data in any way but has only modified the processing graph.

Let’s make this transformation real, with an Action operation like ‘count()’, which will execute all the transformation actions before and apply this aggregate function.

The final result of this little Spark Job is the number you see at the end.