This repository documents the analysis of query execution time in Apache Spark, including the impact of caching and partitioning on performance. The project was executed using Google Colab and Jupyter Notebook with Apache Spark.
- Jupyter Notebook and Google Colab: Used for executing Spark queries locally.
- Apache Spark: Used for big data processing and query execution.
- Parquet Format: Used for efficient data storage and retrieval.
This project analyzes the impact of different Spark optimizations on query execution time:
- Without Caching and Partitioning: The initial query took 0.384 seconds.
- After Caching: Execution time drastically reduced to 0.27 seconds since Spark stored the data in memory.

- After Partitioning by
date_builtand Using a Temporary View: Execution time was 0.359 seconds, showing that partitioning is beneficial only when queries utilize partition pruning.
- Caching significantly reduces query time by avoiding disk I/O.
- Partitioning improves performance only when queries filter on partition columns.
- Parquet format enhances query efficiency by enabling columnar storage and predicate pushdown.
- Jupyter Notebook and Google Colab: this project also identify query time differ based on platform. In my case jupyter notebook query running time was lower.
To set up and run Spark on Jupyter Notebook, follow these steps:
- Install Java, Spark, and Hadoop
sudo apt update
sudo apt install openjdk-8-jdk -y
wget https://archive.apache.org/dist/spark/spark-3.0.1/spark-3.0.1-bin-hadoop2.7.tgz
mkdir spark
tar -xvzf spark-3.0.1-bin-hadoop2.7.tgz -C spark/- Set Environment Variables
export SPARK_HOME=~/spark/spark-3.0.1-bin-hadoop2.7
export PATH=$SPARK_HOME/bin:$PATH
export PYSPARK_PYTHON=python3- Install Findspark and PySpark
pip install findspark pyspark- Configure Jupyter Notebook to Recognize Spark
import findspark
findspark.init()
import pyspark
from pyspark.sql import SparkSession
spark = SparkSession.builder.appName("SparkQueryPerformance").getOrCreate()- Verify Spark Installation
sparkAtnaf