Step 1: Preparation
- Install Java JDK (1.8 or 11)
- Install Python 3.9.x
Step 2: Download Apache Spark
- Navigate to https://spark.apache.org/downloads.html.
- Choose the Spark release and package type as shown below:
You can download this version: spark-3.5.4-bin-hadoop3.tgz
After downloading, open a new terminal and run the following command to verify the checksum:
certutil -hashfile spark-3.5.4-bin-hadoop3.tgz SHA512
Step 3: Configure environment variables
- Create the empty folders
C:\Hadoop\binandC:\Spark. - Download winutils.exe and copy it to
C:\Hadoop\bin. - Copy the extracted
spark-3.5.4-bin-hadoop3folder toC:\Spark. - Create the following environment variables:
SPARK_HOME=C:\Spark\spark-3.5.4-bin-hadoop3 HADOOP_HOME=C:\Hadoop - Add
%SPARK_HOME%\binand%HADOOP_HOME%\binto thePathvariable.
Step 4: Launch Spark and test
Close the old terminal, open a new one and type:
spark-shell
Open a web browser and go to http://localhost:4040/.
Test
Create a text file named testhadoop.txt with the following content:
12345678910
HelloWorld
Then run in spark-shell:
scala> val x = sc.textFile("testhadoop.txt")
x: org.apache.spark.rdd.RDD[String] = testhadoop.txt MapPartitionsRDD[1] at textFile at <console>:24
scala> x.take(11).foreach(println)
12345678910
HelloWorld
scala> val y = x.map(_.reverse)
y: org.apache.spark.rdd.RDD[String] = MapPartitionsRDD[2] at map at <console>:25
scala> y.take(11).foreach(println)
01987654321
dlroWolleH
That's all for getting started with Apache Spark.
Reference: https://phoenixnap.com/kb/category/devops-and-development
0 comments:
Post a Comment