Apache Spark Big Data (50 Qs)•Part 1: Basic & Foundational Concepts (Junior / Entry-Level)
How do you write a basic PySpark DataFrame application?
junior LevelCode Exampleapache-sparkBasic
In Simple Words:
A standard PySpark application initializes a SparkSession, ingests structured data from distributed storage (such as S3, GCS, or HDFS), chains lazy transformations (filtering, grouping, and aggregations), and writes the computed output back to disk via an action:
python
from pyspark.sql import SparkSession
from pyspark.sql.functions import col, avg
# Initialize SparkSession:
spark = SparkSession.builder \
.appName("ECommerceSalesAnalytics") \
.getOrCreate()
# Read Parquet files:
df = spark.read.parquet("s3://data-lake/orders/")
# Transformation: filter, group, and calculate average order:
result_df = df.filter(col("status") == "COMPLETED") \
.groupBy("customer_id") \
.agg(avg("total_amount").alias("avg_spent")) \
.filter(col("avg_spent") > 500)
# Action: write back to S3:
result_df.write.mode("overwrite").parquet("s3://data-lake/gold/top_customers/")